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';
197 $module =
'expedition';
198 $subdirectory =
'/sending';
213 $subdirectory =
'/'.$object->project->ref;
225 if ($mode ==
'output' || $mode ==
'outputrel' || $mode ==
'version') {
226 if (isset(
$conf->$module) && property_exists(
$conf->$module,
'multidir_output')) {
228 if ($mode !=
'outputrel') {
232 if (!isset(
$conf->$module->multidir_output[$entity])) {
233 return 'error-diroutput-not-defined-for-this-entity-and-object='.$module;
235 $s =
$conf->$module->multidir_output[$entity] . $subdirectory;
237 if ($forobject &&
$object->id > 0) {
241 } elseif (isset(
$conf->$module) && property_exists(
$conf->$module,
'dir_output')) {
243 if ($mode !=
'outputrel') {
244 $s =
$conf->$module->dir_output . $subdirectory;
246 if ($forobject &&
$object->id > 0) {
251 return 'error-diroutput-not-defined-for-this-entity-and-object='.$module;
253 } elseif ($mode ==
'temp') {
254 if (isset(
$conf->$module) && property_exists(
$conf->$module,
'multidir_temp')) {
257 if (!isset(
$conf->$module->multidir_temp[$entity])) {
258 return 'error-dirtemp-not-defined-for-this-entity-and-object='.$module;
261 } elseif (isset(
$conf->$module) && property_exists(
$conf->$module,
'dir_temp')) {
264 return 'error-dirtemp-not-defined-for-this-entity-and-object='.$module;
267 return 'error-bad-value-for-mode';
311 return (
string) (isset(
$conf->global->$key) ?
$conf->global->$key : $default);
321 global $dolibarr_login_badcharunauthorized;
323 if (isset($dolibarr_login_badcharunauthorized)) {
324 if ($dolibarr_login_badcharunauthorized ===
'MAIN_LOGIN_BADCHARUNAUTHORIZED') {
328 return (
string) $dolibarr_login_badcharunauthorized;
346 return (
int) (isset(
$conf->global->$key) ?
$conf->global->$key : $default);
361 return (
float) (isset(
$conf->global->$key) ?
$conf->global->$key : $default);
375 return (
bool) (
$conf->global->$key ?? $default);
386 return (
string)
$conf->currency;
397 return (
string)
$conf->dol_optimize_smallscreen;
408 return (
int)
$conf->entity;
419 return $conf->db->type;
430 return str_replace(
'_',
'', basename(dirname($s)).basename($s,
'.php'));
444 if (empty($tmpuser)) {
449 return (
string) (isset($tmpuser->conf->$key) ? $tmpuser->conf->$key : $default);
462 if (empty($tmpuser)) {
467 return (
int) (isset($tmpuser->conf->$key) ? $tmpuser->conf->$key : $default);
483 'adherent' =>
'member',
484 'member_type' =>
'adherent_type',
486 'contrat' =>
'contract',
487 'entrepot' =>
'stock',
488 'projet' =>
'project',
489 'categorie' =>
'category',
490 'commande' =>
'order',
491 'expedition' =>
'shipping',
492 'facture' =>
'invoice',
493 'fichinter' =>
'intervention',
494 'ficheinter' =>
'intervention',
495 'propale' =>
'propal',
496 'societe' =>
'thirdparty',
497 'socpeople' =>
'contact',
498 'fournisseur' =>
'supplier',
500 'actioncomm' =>
'agenda',
501 'product_price' =>
'productprice',
502 'product_fournisseur_price' =>
'productsupplierprice',
522 $arrayconv[
'supplier_order'] =
'fournisseur';
523 $arrayconv[
'supplier_invoice'] =
'fournisseur';
526 $module_alt = $module;
527 if (!empty($arrayconv[$module])) {
528 $module_alt = $arrayconv[$module];
530 $module_bis = $module;
531 if (!empty($arrayconvbis[$module])) {
532 $module_bis = $arrayconvbis[$module];
535 return !empty(
$conf->modules[$module]) || !empty(
$conf->modules[$module_alt]) || !empty(
$conf->modules[$module_bis]);
553 $moduletomoduletouse = array(
554 'invoice' =>
'facture',
556 $moduleParmsMapping = array(
557 'product' =>
'produit',
560 if (!empty($moduletomoduletouse[$module])) {
561 $module = $moduletomoduletouse[$module];
564 $warningDelayPath = $parmlevel1;
565 if (!empty($moduleParmsMapping[$warningDelayPath])) {
566 $warningDelayPath = $moduleParmsMapping[$warningDelayPath];
570 if (!empty(
$conf->$module) && !empty(
$conf->$module->$warningDelayPath) && !empty(
$conf->$module->$warningDelayPath->$parmlevel2) && !empty(
$conf->$module->$warningDelayPath->$parmlevel2->warning_delay)) {
571 return (
int)
$conf->$module->$warningDelayPath->$parmlevel2->warning_delay;
574 if (!empty(
$conf->$module) && !empty(
$conf->$module->$warningDelayPath) && !empty(
$conf->$module->$warningDelayPath->warning_delay)) {
575 return (
int)
$conf->$module->$warningDelayPath->warning_delay;
590 if ($timestamp ===
'') {
591 dol_syslog(
'Using empty string for a timestamp is deprecated, prefer use of null when calling page ' . $_SERVER[
"PHP_SELF"] .
getCallerInfoString(), LOG_DEBUG);
594 if (is_null($timestamp) || !is_numeric($timestamp)) {
614 require_once DOL_DOCUMENT_ROOT .
"/core/db/" . $type .
'.class.php';
616 $class =
'DoliDB' . ucfirst($type);
617 $db =
new $class($type, $host, $user, $pass, $name, $port);
638function getEntity($element, $shared = 1, $currentobject =
null)
642 if (!is_object($hookmanager)) {
643 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
650 $element =
'project';
653 $element =
'contract';
655 case 'order_supplier':
656 $element =
'supplier_order';
658 case 'invoice_supplier':
659 $element =
'supplier_invoice';
663 if (is_object($mc)) {
664 $out = $mc->getEntity($element, $shared, $currentobject);
667 $addzero = array(
'user',
'usergroup',
'cronjob',
'c_email_templates',
'email_template',
'default_values',
'overwrite_trans');
669 $addzero[] =
'c_holiday_types';
671 if (in_array($element, $addzero)) {
674 $out .= ((int)
$conf->entity);
679 'element' => $element,
682 'currentobject' => $currentobject,
686 $reshook = $hookmanager->executeHooks(
'hookGetEntity', $parameters, $currentobject, $action);
688 if (is_numeric($reshook)) {
689 if ($reshook == 0 && !empty($hookmanager->resPrint)) {
690 $out .=
',' . $hookmanager->resPrint;
691 } elseif ($reshook == 1) {
692 $out = $hookmanager->resPrint;
709 if (is_object($mc) && method_exists($mc,
'setEntity')) {
710 return $mc->setEntity($currentobject);
712 return ((is_object($currentobject) && $currentobject->id > 0 && ((
int) $currentobject->entity) > 0) ? (
int) $currentobject->entity :
$conf->entity);
724 return preg_match(
'/(_pass|password|_pw|_key|securekey|serverkey|secret\d?|p12key|exportkey|_PW_[a-z]+|token)$/i', $keyname);
737 for ($r =
""; $n >= 0; $n = intval($n / 26) - 1) {
738 $r = chr($n % 26 + 0x41) . $r;
762 include_once DOL_DOCUMENT_ROOT .
'/includes/mobiledetect/mobiledetectlib/Mobile_Detect.php';
769 $user_agent = substr($user_agent, 0, 512);
772 $detectmobile =
new Mobile_Detect(
null, $user_agent);
773 $tablet = $detectmobile->isTablet();
775 if ($detectmobile->isMobile()) {
779 if ($detectmobile->is(
'AndroidOS')) {
780 $os = $phone =
'android';
781 } elseif ($detectmobile->is(
'BlackBerryOS')) {
782 $os = $phone =
'blackberry';
783 } elseif ($detectmobile->is(
'iOS')) {
786 } elseif ($detectmobile->is(
'PalmOS')) {
787 $os = $phone =
'palm';
788 } elseif ($detectmobile->is(
'SymbianOS')) {
790 } elseif ($detectmobile->is(
'webOS')) {
792 } elseif ($detectmobile->is(
'MaemoOS')) {
794 } elseif ($detectmobile->is(
'WindowsMobileOS') || $detectmobile->is(
'WindowsPhoneOS')) {
800 if (preg_match(
'/linux/i', $user_agent)) {
802 } elseif (preg_match(
'/macintosh/i', $user_agent)) {
804 } elseif (preg_match(
'/windows/i', $user_agent)) {
810 if (preg_match(
'/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
812 $version = empty($reg[2]) ?
'' : $reg[2];
813 } elseif (preg_match(
'/edge(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
815 $version = empty($reg[2]) ?
'' : $reg[2];
816 } elseif (preg_match(
'/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg)) {
818 $version = empty($reg[2]) ?
'' : $reg[2];
819 } elseif (preg_match(
'/chrome/i', $user_agent, $reg)) {
822 } elseif (preg_match(
'/iceweasel/i', $user_agent)) {
824 } elseif (preg_match(
'/epiphany/i', $user_agent)) {
826 } elseif (preg_match(
'/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
828 $version = empty($reg[2]) ?
'' : $reg[2];
829 } elseif (preg_match(
'/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
832 $version = empty($reg[2]) ?
'' : $reg[2];
833 } elseif (preg_match(
'/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
835 $version = end($reg);
836 } elseif (preg_match(
'/(Windows NT\s([0-9]+\.[0-9])).*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
839 $version = end($reg);
840 } elseif (preg_match(
'/l[iy]n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) {
842 $name =
'textbrowser';
843 $version = empty($reg[3]) ?
'' : $reg[3];
844 } elseif (preg_match(
'/w3m\/([\d\.]+)/i', $user_agent, $reg)) {
846 $name =
'textbrowser';
847 $version = empty($reg[1]) ?
'' : $reg[1];
859 'browsername' => $name,
860 'browserversion' => $version,
862 'browserua' => $user_agent,
877 $disconnectdone =
false;
879 if (is_object(
$db) && !empty(
$db->connected)) {
880 $depth =
$db->transaction_opened;
881 $disconnectdone =
$db->close();
883 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));
899 $relativepathstring = $_SERVER[
"PHP_SELF"];
901 if (constant(
'DOL_URL_ROOT')) {
902 $relativepathstring = preg_replace(
'/^' . preg_quote(constant(
'DOL_URL_ROOT'),
'/') .
'/',
'', $relativepathstring);
904 $relativepathstring = ltrim($relativepathstring,
'/');
905 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
909 if (!empty($_GET[
'restore_lastsearch_values'])) {
910 if (!empty($_SESSION[
'lastsearch_values_' . $relativepathstring])) {
911 $tmp = json_decode($_SESSION[
'lastsearch_values_' . $relativepathstring],
true);
912 if (is_array($tmp)) {
913 foreach ($tmp as $key => $val) {
914 if ($key == $paramname) {
922 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_' . $relativepathstring])) {
924 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_' . $relativepathstring])) {
926 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_' . $relativepathstring])) {
928 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_' . $relativepathstring])) {
932 $isset = (isset($_POST[$paramname]) || isset($_GET[$paramname]));
949 if (empty($method)) {
950 $val = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
951 } elseif ($method == 1) {
952 $val = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
953 } elseif ($method == 2) {
954 $val = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
955 } elseif ($method == 3) {
956 $val = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
958 $val =
'BadFirstParameterForGETPOST';
961 return is_array($val);
975function GETPOSTINT($paramname, $method = 0, $nodefault = 0)
977 return (
int)
GETPOST($paramname,
'int', $method,
null,
null, 0, $nodefault);
993function GETPOSTFLOAT($paramname, $rounding =
'', $option = 2)
1014function GETPOSTDATE($prefix, $hourTime =
'', $gm =
'auto', $saverestore =
'')
1017 if ($hourTime ===
'getpost' || $hourTime ===
'getpostend') {
1021 } elseif (preg_match(
'/^(\d\d):(\d\d):(\d\d)$/', $hourTime, $m)) {
1022 $hour = intval($m[1]);
1023 $minute = intval($m[2]);
1024 $second = intval($m[3]);
1025 } elseif ($hourTime ===
'end') {
1030 $hour = $minute = $second = 0;
1038 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_day'])
1039 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_month'])
1040 && isset($_SESSION[
'DOLDATE_' . $saverestore .
'_year'])
1042 $day = $_SESSION[
'DOLDATE_' . $saverestore .
'_day'];
1043 $month = $_SESSION[
'DOLDATE_' . $saverestore .
'_month'];
1044 $year = $_SESSION[
'DOLDATE_' . $saverestore .
'_year'];
1052 $hour = (int) min($hour, 23);
1053 $minute = (int) min($minute, 59);
1054 $second = (int) min($second, 59);
1057 $_SESSION[
'DOLDATE_' . $saverestore .
'_day'] = $day;
1058 $_SESSION[
'DOLDATE_' . $saverestore .
'_month'] = $month;
1059 $_SESSION[
'DOLDATE_' . $saverestore .
'_year'] = $year;
1063 return dol_mktime($hour, $minute, $second, $month, $day, $year, $gm);
1107function GETPOST($paramname, $check =
'alphanohtml', $method = 0, $filter =
null, $options =
null, $noreplace = 0, $nodefault = 0)
1111 if (empty($paramname)) {
1112 return 'BadFirstParameterForGETPOST';
1114 if (empty($check)) {
1115 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);
1119 if (in_array($paramname, array(
'sortfield',
'sortorder'))) {
1120 $check =
'aZ09comma';
1123 if (empty($method)) {
1124 $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
1125 } elseif ($method == 1) {
1126 $out = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
1127 } elseif ($method == 2) {
1128 $out = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
1129 } elseif ($method == 3) {
1130 $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
1132 return 'BadThirdParameterForGETPOST';
1135 $relativepathstring =
'';
1137 if (empty($method) || $method == 3 || $method == 4) {
1138 $relativepathstring = (empty($_SERVER[
"PHP_SELF"]) ?
'' : $_SERVER[
"PHP_SELF"]);
1140 if (constant(
'DOL_URL_ROOT')) {
1141 $relativepathstring = preg_replace(
'/^' . preg_quote(constant(
'DOL_URL_ROOT'),
'/') .
'/',
'', $relativepathstring);
1143 $relativepathstring = ltrim($relativepathstring,
'/');
1144 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
1148 if (!empty($_GET[
'restore_lastsearch_values'])) {
1149 if (!empty($_SESSION[
'lastsearch_values_' . $relativepathstring])) {
1150 $tmp = json_decode($_SESSION[
'lastsearch_values_' . $relativepathstring],
true);
1151 if (is_array($tmp)) {
1152 foreach ($tmp as $key => $val) {
1153 if ($key == $paramname) {
1161 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_' . $relativepathstring])) {
1162 $out = $_SESSION[
'lastsearch_contextpage_' . $relativepathstring];
1163 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_' . $relativepathstring])) {
1164 $out = $_SESSION[
'lastsearch_limit_' . $relativepathstring];
1165 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_' . $relativepathstring])) {
1166 $out = $_SESSION[
'lastsearch_page_' . $relativepathstring];
1167 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_' . $relativepathstring])) {
1168 $out = $_SESSION[
'lastsearch_mode_' . $relativepathstring];
1170 } elseif (!isset($_GET[
'sortfield'])) {
1173 if (!empty($_GET[
'action']) && $_GET[
'action'] ==
'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
1176 '@phan-var-force CommonObject $object';
1177 if (is_object(
$object) && isset(
$object->fields[$paramname][
'default'])) {
1179 $out =
$object->fields[$paramname][
'default'];
1183 if (!empty($_GET[
'action']) && (preg_match(
'/^create/', $_GET[
'action']) || preg_match(
'/^presend/', $_GET[
'action'])) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
1185 if (!empty($user->default_values)) {
1186 if (isset($user->default_values[$relativepathstring][
'createform'])) {
1187 foreach ($user->default_values[$relativepathstring][
'createform'] as $defkey => $defval) {
1189 if ($defkey !=
'_noquery_') {
1190 $tmpqueryarraytohave = explode(
'&', $defkey);
1193 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1194 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1206 if (isset($user->default_values[$relativepathstring][
'createform'][$defkey][$paramname])) {
1207 $out = $user->default_values[$relativepathstring][
'createform'][$defkey][$paramname];
1214 } elseif (!empty($paramname) && !isset($_GET[$paramname]) && !isset($_POST[$paramname]) && empty($nodefault)) {
1216 if (!empty($user->default_values)) {
1219 if ($paramname ==
'sortfield' || $paramname ==
'sortorder') {
1221 if (isset($user->default_values[$relativepathstring][
'sortorder'])) {
1223 foreach ($user->default_values[$relativepathstring][
'sortorder'] as $defkey => $defval) {
1225 if ($defkey !=
'_noquery_') {
1226 $tmpqueryarraytohave = explode(
'&', $defkey);
1229 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1230 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1242 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1243 foreach ($user->default_values[$relativepathstring][
'sortorder'][$defkey] as $key => $val) {
1247 if ($paramname ==
'sortfield') {
1250 if ($paramname ==
'sortorder') {
1258 } elseif (isset($user->default_values[$relativepathstring][
'filters'])) {
1259 foreach ($user->default_values[$relativepathstring][
'filters'] as $defkey => $defval) {
1260 if (!empty($_GET[
'disabledefaultvalues'])) {
1264 if ($defkey !=
'_noquery_') {
1265 $tmpqueryarraytohave = explode(
'&', $defkey);
1268 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
1269 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
1280 if ($qualified && isset($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname])) {
1282 if (isset($_POST[
'search_all']) || isset($_GET[
'search_all'])) {
1285 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1286 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
1289 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
1290 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
1305 '@phan-var-force string $paramname';
1306 if (!is_array($out) && empty($_POST[$paramname]) && empty($noreplace)) {
1307 if (preg_match(
'/__([A-Z0-9]+(?:_[A-Z0-9]+){0,3})__/i', $out)) {
1308 $substitutionarray = getCommonSubstitutionArray($langs, 0,
null, $user, array(
'mycompany',
'date',
'system',
'user'));
1316 if (preg_match(
'/^array/', $check)) {
1317 $tmpcheck =
'alphanohtml';
1318 if ($out ===
null || $out ===
'') {
1320 } elseif (!is_array($out)) {
1321 $out = explode(
',', $out);
1323 $tmparray = explode(
':', $check);
1324 if (!empty($tmparray[1])) {
1325 $tmpcheck = $tmparray[1];
1328 foreach ($out as $outkey => $outval) {
1329 $out[$outkey] =
sanitizeVal($outval, $tmpcheck, $filter, $options);
1334 if (strpos($paramname,
'search_') === 0) {
1335 $out = preg_replace(
'/([<>])([-+]?\d)/',
'\1 \2', $out);
1339 $out =
sanitizeVal($out, $check, $filter, $options);
1347 if (preg_match(
'/^backto/i', $paramname) || preg_match(
'/^urlfrom/i', $paramname)) {
1348 $out = str_replace(
'\\',
'/', $out);
1349 $out = str_replace(array(
':',
';',
'@',
"\t",
' '),
'', $out);
1351 $oldstringtoclean = $out;
1352 $out = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $out);
1353 $out = preg_replace(array(
'/^[^\?]*%/'),
'', $out);
1354 $out = preg_replace(array(
'/^[a-z]*\/\s*\/+/i'),
'', $out);
1355 }
while ($oldstringtoclean != $out);
1360 if (empty($method) || $method == 3 || $method == 4) {
1361 if (preg_match(
'/^search_/', $paramname) || in_array($paramname, array(
'sortorder',
'sortfield'))) {
1368 if ($out !=
'' && isset($user)) {
1369 $user->lastsearch_values_tmp[$relativepathstring][$paramname] = $out;
1374 if ($paramname ==
'hashp' && $out ==
'shared') {
1390function sanitizeVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
1394 if ($out ===
null) {
1402 if (!is_numeric($out)) {
1407 if (is_array($out)) {
1408 $out = implode(
',', $out);
1410 if (preg_match(
'/[^0-9,-]+/i', $out)) {
1415 dol_syslog(
"Use of parameter value 'san_alpha' in GETPOST is deprecated. Use 'alphanohtml', 'aZ09comma', ...", LOG_WARNING);
1416 $out = filter_var($out, FILTER_SANITIZE_STRING);
1419 $out = filter_var($out, FILTER_SANITIZE_EMAIL);
1423 $out = preg_replace(
'/[^:\/\[\]a-z0-9@\$\'\*\~\.\-_,;\?\!=%&+#]+/i',
'', $out);
1427 if (!is_array($out)) {
1429 if (preg_match(
'/[^a-z]+/i', $out)) {
1435 if (!is_array($out)) {
1437 if (preg_match(
'/[^a-z0-9_\-\.]+/i', $out)) {
1443 if (!is_array($out)) {
1445 if (preg_match(
'/[^a-z0-9_\-\.@]+/i', $out)) {
1451 if (!is_array($out)) {
1453 if (preg_match(
'/[^a-z0-9_\-\.,]+/i', $out)) {
1460 if (!is_array($out)) {
1463 $oldstringtoclean = $out;
1467 $out = preg_replace(
'/\\\([0-9xu])/',
'/\1', $out);
1474 $out = str_ireplace(array(
'../',
'..\\',
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'/',
'\',
'\',
'\'),
'', $out);
1475 }
while ($oldstringtoclean != $out);
1479 case 'alphawithlgt':
1480 if (!is_array($out)) {
1483 $oldstringtoclean = $out;
1487 $out = preg_replace(
'/\\\([0-9xu])/',
'/\1', $out);
1494 $out = str_ireplace(array(
'../',
'..\\',
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'/',
'\',
'\',
'\'),
'', $out);
1495 }
while ($oldstringtoclean != $out);
1501 case 'restricthtmlnolink':
1502 case 'restricthtml':
1503 case 'restricthtmlallowclass':
1504 case 'restricthtmlallowiframe':
1505 case 'restricthtmlallowlinkscript':
1506 case 'restricthtmlallowunvalid':
1511 if (empty($filter)) {
1512 return 'BadParameterForGETPOST - Param 3 of sanitizeVal()';
1514 if (is_null($options)) {
1517 $out = filter_var($out, $filter, $options);
1521 dol_syslog(
"Error, you call sanitizeVal() with a bad value for the check type. Data will be sanitized with alphanohtml.", LOG_ERR);
1522 $out =
GETPOST($out,
'alphanohtml');
1537function dolSetCookie(
string $cookiename,
string $cookievalue,
int $expire = -1)
1539 include_once DOL_DOCUMENT_ROOT.
'/blockedlog/lib/securitycore.lib.php';
1541 global $dolibarr_main_force_https;
1543 if ($expire == -1) {
1544 $expire = (time() + (86400 * 354));
1547 if (PHP_VERSION_ID < 70300) {
1548 setcookie($cookiename, empty($cookievalue) ?
'' : $cookievalue, empty($cookievalue) ? 0 : $expire,
'/',
'', !(empty($dolibarr_main_force_https) &&
isHTTPS() === false), true);
1551 $cookieparams = array(
1552 'expires' => empty($cookievalue) ? 0 : $expire,
1555 'secure' => !(empty($dolibarr_main_force_https) &&
isHTTPS() === false),
1559 setcookie($cookiename, empty($cookievalue) ?
'' : $cookievalue, $cookieparams);
1561 if (empty($cookievalue)) {
1562 unset($_COOKIE[$cookiename]);
1566if (!function_exists(
'dol_getprefix')) {
1577 function dol_getprefix($mode =
'')
1580 if ($mode ==
'email') {
1586 } elseif (isset($_SERVER[
"SERVER_NAME"])) {
1587 return $_SERVER[
"SERVER_NAME"];
1592 if (!empty(
$conf->file->instance_unique_id)) {
1593 return sha1(
'dolibarr' .
$conf->file->instance_unique_id);
1597 return sha1(DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1601 global $dolibarr_main_instance_unique_id, $dolibarr_main_cookie_cryptkey;
1602 $tmp_instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ?
'' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id;
1605 if (!empty($tmp_instance_unique_id)) {
1606 return sha1(
'dolibarr' . $tmp_instance_unique_id);
1610 if (isset($_SERVER[
"SERVER_NAME"]) && isset($_SERVER[
"DOCUMENT_ROOT"])) {
1611 return sha1($_SERVER[
"SERVER_NAME"] . $_SERVER[
"DOCUMENT_ROOT"] . DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1613 return sha1(DOL_DOCUMENT_ROOT . DOL_URL_ROOT);
1632 if (strpos($relpath,
'..') !==
false) {
1634 dol_syslog(
'functions::dol_include_once Tried to load a file with a path including a forbidden sequence ".." : ' . $relpath, LOG_WARNING);
1637 if (!preg_match(
'/\.php$/', $relpath)) {
1639 dol_syslog(
'functions::dol_include_once Tried to load a file that is not a PHP file : ' . $relpath, LOG_WARNING);
1645 if (!file_exists($fullpath)) {
1646 dol_syslog(
'functions::dol_include_once Tried to load unexisting file: ' . $relpath, LOG_WARNING);
1649 if (!empty($classname) && !class_exists($classname)) {
1650 return include $fullpath;
1652 return include_once $fullpath;
1670function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0)
1674 $path = preg_replace(
'/^\//',
'', $path);
1677 $res = DOL_DOCUMENT_ROOT .
'/' . $path;
1678 if (is_array(
$conf->file->dol_document_root)) {
1679 foreach (
$conf->file->dol_document_root as $key => $dirroot) {
1680 if ($key ==
'main') {
1684 if (@file_exists($dirroot .
'/' . $path)) {
1685 if ($key !=
'main' && preg_match(
'/^core\//', $path)) {
1688 $res = $dirroot .
'/' . $path;
1693 if ($returnemptyifnotfound) {
1695 if ($returnemptyifnotfound == 1 || !file_exists($res)) {
1707 $res = DOL_URL_ROOT .
'/' . $path;
1710 $res = DOL_MAIN_URL_ROOT .
'/' . $path;
1713 $res = DOL_URL_ROOT .
'/' . $path;
1716 foreach (
$conf->file->dol_document_root as $key => $dirroot) {
1717 if ($key ==
'main') {
1722 $urlwithouturlroot = preg_replace(
'/' . preg_quote(DOL_URL_ROOT,
'/') .
'$/i',
'', trim(
$conf->file->dol_main_url_root));
1723 $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
1726 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : $urlwithroot) .
'/' . $path;
1731 preg_match(
'/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i', $path, $regs);
1732 if (!empty($regs[1])) {
1735 if (@file_exists($dirroot .
'/' . $regs[1])) {
1737 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : DOL_URL_ROOT) .
$conf->file->dol_url_root[$key] .
'/' . $path;
1738 } elseif ($type == 2) {
1739 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : DOL_MAIN_URL_ROOT) .
$conf->file->dol_url_root[$key] .
'/' . $path;
1740 } elseif ($type == 3) {
1744 $urlwithouturlroot = preg_replace(
'/' . preg_quote(DOL_URL_ROOT,
'/') .
'$/i',
'', trim(
$conf->file->dol_main_url_root));
1745 $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
1748 $res = (preg_match(
'/^http/i',
$conf->file->dol_url_root[$key]) ?
'' : $urlwithroot) .
$conf->file->dol_url_root[$key] .
'/' . $path;
1768function dolBuildUrl($url, $params = [], $addtoken =
false, $anchor =
'')
1770 global
$db, $hookmanager;
1772 if (!is_object($hookmanager)) {
1773 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1776 if ((!isset($params[
'mainmenu']) || empty($params[
'mainmenu'])) &&
GETPOSTISSET(
'mainmenu')) {
1777 $params = array_merge($params, [
'mainmenu' => (
GETPOST(
'mainmenu',
'restricthtml'))]);
1779 if ((!isset($params[
'leftmenu'])) &&
GETPOSTISSET(
'leftmenu')) {
1780 $params = array_merge($params, [
'leftmenu' => (
GETPOST(
'leftmenu',
'restricthtml'))]);
1784 'params' => &$params,
1785 'addtoken' => &$addtoken,
1787 $hookmanager->executeHooks(
'buildurl', $parameters);
1789 $params = array_merge($params, [
'token' =>
newToken()]);
1792 $url .=
'?' . http_build_query($params);
1795 $url .=
'#' . preg_replace(
'/[^a-z]/i',
'', $anchor);
1814 if (empty($properties)) {
1815 return get_object_vars($obj);
1818 $existingProperties = [];
1819 $realProperties = get_object_vars($obj);
1822 foreach ($properties as $property) {
1823 if (array_key_exists($property, $realProperties)) {
1825 $existingProperties[$property] = $obj->{$property};
1826 } elseif (property_exists($obj, $property)) {
1828 $existingProperties[$property] = $obj->{$property};
1832 return $existingProperties;
1853function dol_clone($srcobject, $native = 2)
1857 dol_syslog(
"Warning, call to dol_clone() with the deprecated parameter native=0, use 2 instead", LOG_WARNING);
1860 if (isset($srcobject->db) && isset($srcobject->db->db) && is_object($srcobject->db->db) && get_class($srcobject->db->db) ==
'PgSql\Connection') {
1861 $tmpsavdb = $srcobject->db;
1862 unset($srcobject->db);
1865 $myclone = unserialize(serialize($srcobject));
1867 if (!empty($tmpsavdb)) {
1868 $srcobject->db = $tmpsavdb;
1870 } elseif ($native == 2) {
1873 $tmparray = get_object_vars($srcobject);
1875 if (is_array($tmparray)) {
1876 foreach ($tmparray as $propertykey => $propertyval) {
1877 if (is_scalar($propertyval) || is_array($propertyval)) {
1878 $myclone->$propertykey = $propertyval;
1883 $myclone = clone $srcobject;
1900 if (is_object($srcobject)) {
1901 $srcobject = get_object_vars($srcobject);
1904 if (is_array($srcobject)) {
1906 foreach ($srcobject as $key => $value) {
1907 if (in_array($key, array(
'db',
'fields',
'error',
'errorhidden',
'errors',
'oldcopy',
'linkedObjects',
'linked_objects'))) {
1928function dol_size($size, $type =
'')
1931 if (empty(
$conf->dol_optimize_smallscreen)) {
1934 if ($type ==
'width' && $size > 250) {
1955function dol_sanitizeFileName($str, $newstr =
'_', $unaccent = 1, $includequotes = 0, $allowdash = 0)
1963 $filesystem_forbidden_chars = array(
'<',
'>',
'/',
'\\',
'?',
'*',
'|',
'"',
':',
'°',
'$',
';',
'`');
1964 if ($includequotes) {
1965 $filesystem_forbidden_chars[] =
"'";
1968 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
1969 if (empty($allowdash)) {
1970 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $tmp);
1971 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1973 $tmp = str_replace(
'..',
'', $tmp);
1974 $tmp = str_replace(
'~', $newstr, $tmp);
1975 $tmp = preg_replace(
'/\s{2,}/',
' ', $tmp);
2002 $filesystem_forbidden_chars = array(
'<',
'>',
'?',
'*',
'|',
'"',
'°',
'$',
';',
'`');
2009 $tmp = preg_replace(
'/\-\-+/', $newstr, $tmp);
2010 if (empty($allowdash)) {
2011 $tmp = preg_replace(
'/\s+\-([^\s])/',
' '.$newstr.
'$1', $tmp);
2012 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
2014 $tmp = str_replace(
'..', $newstr, $tmp);
2015 $tmp = str_replace(
'~', $newstr, $tmp);
2016 $tmp = preg_replace(
'/\s{2,}/',
' ', $tmp);
2032 $stringtoclean = preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $stringtoclean);
2034 $stringtoclean = preg_replace(
'/<!--[^>]*-->/',
'', $stringtoclean);
2036 $stringtoclean = str_replace(
'\\',
'/', $stringtoclean);
2040 $stringtoclean = str_replace(array(
':',
';',
'@'),
'', $stringtoclean);
2044 $oldstringtoclean = $stringtoclean;
2047 $stringtoclean = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $stringtoclean);
2048 }
while ($oldstringtoclean != $stringtoclean);
2052 $stringtoclean = preg_replace(array(
'/^[a-z]*\/\/+/i'),
'', $stringtoclean);
2055 return $stringtoclean;
2067 $oldstringtoclean = $stringtoclean;
2068 $stringtoclean = str_ireplace(array(
'"',
':',
'[',
']',
"\n",
"\r",
'\\',
'\/'),
'', $stringtoclean);
2069 }
while ($oldstringtoclean != $stringtoclean);
2071 return $stringtoclean;
2084 return preg_replace(
'/[^\w]+/',
'', $str);
2098 if (is_null($str)) {
2103 if (extension_loaded(
'intl') &&
getDolGlobalString(
'MAIN_UNACCENT_USE_TRANSLITERATOR')) {
2104 $transliterator = Transliterator::createFromRules(
':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', Transliterator::FORWARD);
2105 return $transliterator->transliterate($str);
2108 $string = rawurlencode($str);
2109 $replacements = array(
2110 '%C3%80' =>
'A',
'%C3%81' =>
'A',
'%C3%82' =>
'A',
'%C3%83' =>
'A',
'%C3%84' =>
'A',
'%C3%85' =>
'A',
2112 '%C3%88' =>
'E',
'%C3%89' =>
'E',
'%C3%8A' =>
'E',
'%C3%8B' =>
'E',
2113 '%C3%8C' =>
'I',
'%C3%8D' =>
'I',
'%C3%8E' =>
'I',
'%C3%8F' =>
'I',
2115 '%C3%92' =>
'O',
'%C3%93' =>
'O',
'%C3%94' =>
'O',
'%C3%95' =>
'O',
'%C3%96' =>
'O',
'%C5%90' =>
'O',
2117 '%C3%99' =>
'U',
'%C3%9A' =>
'U',
'%C3%9B' =>
'U',
'%C3%9C' =>
'U',
'%C5%B0' =>
'U',
2118 '%C3%9D' =>
'Y',
'%C5%B8' =>
'y',
2119 '%C3%A0' =>
'a',
'%C3%A1' =>
'a',
'%C3%A2' =>
'a',
'%C3%A3' =>
'a',
'%C3%A4' =>
'a',
'%C3%A5' =>
'a',
2121 '%C3%A8' =>
'e',
'%C3%A9' =>
'e',
'%C3%AA' =>
'e',
'%C3%AB' =>
'e',
2122 '%C3%AC' =>
'i',
'%C3%AD' =>
'i',
'%C3%AE' =>
'i',
'%C3%AF' =>
'i',
2124 '%C3%B2' =>
'o',
'%C3%B3' =>
'o',
'%C3%B4' =>
'o',
'%C3%B5' =>
'o',
'%C3%B6' =>
'o',
'%C5%91' =>
'o',
2126 '%C3%B9' =>
'u',
'%C3%BA' =>
'u',
'%C3%BB' =>
'u',
'%C3%BC' =>
'u',
'%C5%B1' =>
'u',
2127 '%C3%BD' =>
'y',
'%C3%BF' =>
'y',
2148 $string = strtr($string, $replacements);
2149 return rawurldecode($string);
2154 "\xC0\xC1\xC2\xC3\xC4\xC5\xC7
2155 \xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1
2156 \xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD
2157 \xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB
2158 \xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8
2159 \xF9\xFA\xFB\xFC\xFD\xFF",
2167 $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"));
2185function dol_string_nospecial($str, $newstr =
'_', $badcharstoreplace =
'', $badcharstoremove =
'', $keepspaces = 0)
2187 $forbidden_chars_to_replace = array(
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
",",
";",
"=",
'°',
'$',
';');
2188 if (empty($keepspaces)) {
2189 $forbidden_chars_to_replace[] =
" ";
2191 $forbidden_chars_to_remove = array();
2194 if (is_array($badcharstoreplace)) {
2195 $forbidden_chars_to_replace = $badcharstoreplace;
2197 if (is_array($badcharstoremove)) {
2198 $forbidden_chars_to_remove = $badcharstoremove;
2202 return str_replace($forbidden_chars_to_replace, $newstr, str_replace($forbidden_chars_to_remove,
"", $str));
2221 if ($removetabcrlf) {
2222 return preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $str);
2224 return preg_replace(
'/[\x00-\x08\x11-\x12\x14-\x1F\x7F]/u',
'', $str);
2239 if (function_exists(
'iconv')) {
2240 $slug = iconv(
'UTF-8',
'ASCII//TRANSLIT//IGNORE', $slug);
2244 $slug = strtolower($slug);
2247 $slug = preg_replace(
'/[^a-z0-9]+/',
'-', $slug);
2250 $slug = trim($slug,
'-');
2263function dol_escape_js($stringtoescape, $mode = 0, $noescapebackslashn = 0)
2265 if (is_null($stringtoescape)) {
2270 $substitjs = array(
"'" =>
"\\'",
"\r" =>
'\\r');
2272 if (empty($noescapebackslashn)) {
2273 $substitjs[
"\n"] =
'\\n';
2274 $substitjs[
'\\'] =
'\\\\';
2277 $substitjs[
"'"] =
"\\'";
2278 $substitjs[
'"'] =
"\\'";
2279 } elseif ($mode == 1) {
2280 $substitjs[
"'"] =
"\\'";
2281 } elseif ($mode == 2) {
2282 $substitjs[
'"'] =
'\\"';
2283 } elseif ($mode == 3) {
2284 $substitjs[
"'"] =
"\\'";
2285 $substitjs[
'"'] =
"\\\"";
2287 return strtr((
string) $stringtoescape, $substitjs);
2301 return rawurlencode($stringtoescape);
2312 return str_replace(
'"',
'\"', $stringtoescape);
2324 if (is_null($stringtoescape)) {
2328 if ($stringforquotes == 2) {
2329 return str_replace(
'"',
"'", $stringtoescape);
2330 } elseif ($stringforquotes == 1) {
2336 $stringtoescape = str_replace(
'\\',
'', $stringtoescape);
2337 return str_replace(
"'",
"\'", str_replace(
'"',
"'", $stringtoescape));
2340 return 'Bad parameter for stringforquotes in dol_escape_php';
2351 return preg_replace(
'/[^a-z0-9_]/i',
'', $stringtoescape);
2362 return $stringtoescape;
2403function dolPrintHTML($s, $allowiframe = 0, $moreallowedtags = array())
2412 $allowedtags =
'common';
2413 if (!empty($moreallowedtags)) {
2414 $allowedtags .=
','.implode(
',', $moreallowedtags);
2416 return dol_escape_htmltag(
dol_htmlwithnojs(
dol_string_onlythesehtmltags($stringWithEntitesForSpecialChar, 1, 1, 1, $allowiframe, $allowedtags)), 1, 1, $allowedtags, 0, 1);
2431 $allowedtags = array(
'br',
'b',
'font',
'hr',
'span');
2432 if (!empty($allowothertags) && is_array($allowothertags)) {
2433 $allowedtags = array_merge($allowedtags, $allowothertags);
2437 if ($escapeonlyhtmltags) {
2438 return dol_escape_htmltag(
dol_string_onlythesehtmltags($s, 1, 0, 0, 0, $allowedtags), 1, -1,
'', 1, 1);
2440 return dol_escape_htmltag(
dol_string_onlythesehtmltags(
dol_htmlentitiesbr($s), 1, 0, 0, 0, $allowedtags), 1, -1,
'', 0, 1);
2456 $escapeonlyhtmltags = 1;
2457 return dol_escape_htmltag(
dol_string_onlythesehtmltags($s, 1, 1, 1, 0, array()), 0, 0,
'', $escapeonlyhtmltags, 1);
2482 return htmlspecialchars($s, ENT_HTML5,
'UTF-8');
2502function dol_escape_htmltag($stringtoescape, $keepb = 0, $keepn = 0, $noescapetags =
'', $escapeonlyhtmltags = 0, $cleanalsojavascript = 0)
2505 if (preg_match(
'/^common([a-z,]*)/', $noescapetags, $reg)) {
2506 $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';
2508 $noescapetags .=
',header,footer,nav,section,menu,menuitem';
2509 if (!empty($reg[1])) {
2510 $noescapetags .= $reg[1];
2513 if ($cleanalsojavascript) {
2518 if ($escapeonlyhtmltags) {
2519 $tmp = htmlspecialchars_decode((
string) $stringtoescape, ENT_COMPAT);
2526 $tmp = (
string) $stringtoescape;
2529 $tmp = str_ireplace(
'<',
'__DONOTDECODELT', $tmp);
2530 $tmp = str_ireplace(
'>',
'__DONOTDECODEGT', $tmp);
2531 $tmp = str_ireplace(
'&',
'__DONOTDECODEAMP', $tmp);
2532 $tmp = str_ireplace(
'"',
'__DONOTDECODEQUOT', $tmp);
2533 $tmp = str_ireplace(
'&apos',
'__DONOTDECODEAPOS', $tmp);
2534 $tmp = str_ireplace(
''',
'__DONOTDECODE39', $tmp);
2536 $tmp = html_entity_decode((
string) $tmp, ENT_COMPAT,
'UTF-8');
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(
'__DONOTDECODEAPOS',
'&apos', $tmp);
2544 $tmp = str_ireplace(
'__DONOTDECODE39',
''', $tmp);
2546 $tmp = str_ireplace(
''',
'__SIMPLEQUOTE__', $tmp);
2549 $tmp = strtr($tmp, array(
"<b>" =>
'',
'</b>' =>
'',
'<strong>' =>
'',
'</strong>' =>
''));
2552 $tmp = strtr($tmp, array(
"\r" =>
'\\r',
"\n" =>
'\\n'));
2553 } elseif ($keepn == -1) {
2554 $tmp = strtr($tmp, array(
"\r" =>
'',
"\n" =>
''));
2557 if ($escapeonlyhtmltags) {
2558 $tmp = htmlspecialchars($tmp, ENT_COMPAT,
'UTF-8');
2562 $tmparrayoftags = array();
2563 if ($noescapetags) {
2564 $tmparrayoftags = explode(
',', $noescapetags);
2567 if (count($tmparrayoftags)) {
2572 $tmp = str_ireplace(array(
'__DOUBLEQUOTE',
'__BEGINTAGTOREPLACE',
'__ENDTAGTOREPLACE',
'__BEGINENDTAGTOREPLACE'),
'', $tmp);
2574 foreach ($tmparrayoftags as $tagtoreplace) {
2576 $tmp = preg_replace(
'/<' . preg_quote($tagtoreplace,
'/') .
'>/',
'__BEGINTAGTOREPLACE' . $tagtoreplace .
'__', $tmp);
2577 $tmp = str_ireplace(
'</' . $tagtoreplace .
'>',
'__ENDTAGTOREPLACE' . $tagtoreplace .
'__', $tmp);
2578 $tmp = preg_replace(
'/<' . preg_quote($tagtoreplace,
'/') .
' \/>/',
'__BEGINENDTAGTOREPLACE' . $tagtoreplace .
'__', $tmp);
2584 $tmp = preg_replace_callback(
2585 '/<'.preg_quote($tagtoreplace,
'/').
'(\s+)([^>]+)>/',
2590 static function ($reg) use ($tagtoreplace) {
2592 $tmpattributes = str_ireplace(array(
'[',
']'),
'_', $reg[2]);
2593 $tmpattributes = str_ireplace(
'"',
'__DOUBLEQUOTE__', $tmpattributes);
2594 $tmpattributes = preg_replace(
'/[^a-z0-9_%,\/\?\;\s=&\.\-@:\.#\+]/i',
'', $tmpattributes);
2596 return '__BEGINTAGTOREPLACE'.$tagtoreplace.
'['.$tmpattributes.
']__';
2602 $tmp = str_ireplace(
'&',
'__ANDNOSEMICOLON__', $tmp);
2603 $tmp = str_ireplace(
'"',
'__DOUBLEQUOTENOSEMICOLON__', $tmp);
2604 $tmp = str_ireplace(
'<',
'__LESSTHAN__', $tmp);
2605 $tmp = str_ireplace(
'>',
'__GREATERTHAN__', $tmp);
2609 $result = htmlentities($tmp, ENT_COMPAT,
'UTF-8');
2613 if (count($tmparrayoftags)) {
2615 foreach ($tmparrayoftags as $tagtoreplace) {
2616 $result = str_ireplace(
'__BEGINTAGTOREPLACE' . $tagtoreplace .
'__',
'<' . $tagtoreplace .
'>', $result);
2617 $result = preg_replace(
'/__BEGINTAGTOREPLACE' . $tagtoreplace .
'\[([^\]]*)\]__/',
'<' . $tagtoreplace .
' \1>', $result);
2618 $result = str_ireplace(
'__ENDTAGTOREPLACE' . $tagtoreplace .
'__',
'</' . $tagtoreplace .
'>', $result);
2619 $result = str_ireplace(
'__BEGINENDTAGTOREPLACE' . $tagtoreplace .
'__',
'<' . $tagtoreplace .
' />', $result);
2620 $result = preg_replace(
'/__BEGINENDTAGTOREPLACE' . $tagtoreplace .
'\[([^\]]*)\]__/',
'<' . $tagtoreplace .
' \1 />', $result);
2623 $result = str_ireplace(
'__DOUBLEQUOTE__',
'"', $result);
2625 $result = str_ireplace(
'__ANDNOSEMICOLON__',
'&', $result);
2626 $result = str_ireplace(
'__DOUBLEQUOTENOSEMICOLON__',
'"', $result);
2627 $result = str_ireplace(
'__LESSTHAN__',
'<', $result);
2628 $result = str_ireplace(
'__GREATERTHAN__',
'>', $result);
2631 $result = str_ireplace(
'__SIMPLEQUOTE__',
''', $result);
2648 if (function_exists(
'mb_strtolower')) {
2649 return mb_strtolower($string, $encoding);
2651 return strtolower($string);
2665 if (function_exists(
'mb_strtoupper')) {
2666 return mb_strtoupper($string, $encoding);
2668 return strtoupper($string);
2682 if (function_exists(
'mb_substr')) {
2683 return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding) . mb_substr($string, 1,
null, $encoding);
2685 return ucfirst($string);
2699 if (function_exists(
'mb_convert_case')) {
2700 return mb_convert_case($string, MB_CASE_TITLE, $encoding);
2702 return ucwords($string);
2714 $backtrace = debug_backtrace();
2716 if (count($backtrace) >= 1) {
2718 if (count($backtrace) == 1) {
2721 $trace = $backtrace[$pos];
2722 if (isset($trace[
'file'], $trace[
'line'])) {
2723 $msg =
" From {$trace['file']}:{$trace['line']}.";
2751function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename =
'', $restricttologhandler =
'', $logcontext =
null)
2753 global
$conf, $user, $debugbar;
2761 if (defined(
'USEEXTERNALSERVER') && !defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
2762 global $website, $websitekey;
2763 if (is_object($website) && !empty($website->ref)) {
2764 $suffixinfilename .=
'_website_' . $website->ref;
2765 } elseif (!empty($websitekey)) {
2766 $suffixinfilename .=
'_website_' . $websitekey;
2771 if (defined(
'USESUFFIXINLOG')) {
2772 $suffixinfilename .= constant(
'USESUFFIXINLOG');
2776 foreach (
$conf->loghandlers as $loghandlerinstance) {
2777 $loghandlerinstance->setIdent($ident);
2781 if (!empty($message)) {
2784 $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');
2786 if (!array_key_exists($level, $logLevels)) {
2787 dol_syslog(
'Error Bad Log Level ' . $level, LOG_ERR);
2795 $message = preg_replace(
'/password=\'[^\']*\'/',
'password=\'hidden\'', $message);
2799 if ((!empty($_REQUEST[
'logtohtml']) &&
getDolGlobalString(
'MAIN_ENABLE_LOG_TO_HTML'))
2800 || (is_object($user) && $user->hasRight(
'debugbar',
'read') && is_object($debugbar))
2802 $ospid = sprintf(
"%7s",
dol_trunc((
string) getmypid(), 7,
'right',
'UTF-8', 1));
2803 $osuser =
" " . sprintf(
"%6s",
dol_trunc(function_exists(
'posix_getuid') ? posix_getuid() :
'', 6,
'right',
'UTF-8', 1));
2805 $conf->logbuffer[] =
dol_print_date(time(),
"%Y-%m-%d %H:%M:%S") .
" " . sprintf(
"%-7s", $logLevels[$level]) .
" " . $ospid .
" " . $osuser .
" " . $message;
2811 print
"\n\n<!-- Log start\n";
2813 print
"Log end -->\n";
2817 'message' => $message,
2818 'script' => (isset($_SERVER[
'PHP_SELF']) ? basename($_SERVER[
'PHP_SELF'],
'.php') :
''),
2820 'user' => ((is_object($user) && $user->id) ? $user->login :
''),
2822 'osuser' => function_exists(
'posix_getuid') ? (
string) posix_getuid() :
'',
2823 'ospid' => (
string) getmypid()
2828 if (!empty($remoteip)) {
2829 $data[
'ip'] = $remoteip;
2833 if (!empty($_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
2834 $tmpips = explode(
',', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
2838 foreach ($tmpips as $tmpip) {
2839 $tmpip = trim($tmpip);
2840 if (strtolower($tmpip) == strtolower($remoteip)) {
2843 if (empty($data[
'ip'])) {
2844 $data[
'ip'] = $tmpip;
2847 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $tmpip;
2850 if (!$foundremoteip) {
2852 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $remoteip;
2854 $data[
'ip'] .= (($j > 0) ?
']' :
'');
2855 } elseif (!empty($_SERVER[
'HTTP_CLIENT_IP'])) {
2856 $tmpips = explode(
',', $_SERVER[
'HTTP_CLIENT_IP']);
2860 foreach ($tmpips as $tmpip) {
2861 $tmpip = trim($tmpip);
2862 if (strtolower($tmpip) == strtolower($remoteip)) {
2865 if (empty($data[
'ip'])) {
2866 $data[
'ip'] = $tmpip;
2869 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $tmpip;
2872 if (!$foundremoteip) {
2874 $data[
'ip'] .= (($j == 1) ?
' [via ' :
',') . $remoteip;
2876 $data[
'ip'] .= (($j > 0) ?
']' :
'');
2878 } elseif (!empty($_SERVER[
'SERVER_ADDR'])) {
2880 $data[
'ip'] = (
string) $_SERVER[
'SERVER_ADDR'];
2881 } elseif (!empty($_SERVER[
'COMPUTERNAME'])) {
2883 $data[
'ip'] = (
string) $_SERVER[
'COMPUTERNAME'];
2885 $data[
'ip'] =
'???';
2888 if (!empty($_SERVER[
'USERNAME'])) {
2890 $data[
'osuser'] = (
string) $_SERVER[
'USERNAME'];
2891 } elseif (!empty($_SERVER[
'LOGNAME'])) {
2893 $data[
'osuser'] = (
string) $_SERVER[
'LOGNAME'];
2897 foreach (
$conf->loghandlers as $loghandlerinstance) {
2898 if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
2901 $loghandlerinstance->export($data, $suffixinfilename);
2907 foreach (
$conf->loghandlers as $loghandlerinstance) {
2908 $loghandlerinstance->setIdent($ident);
2930 $templatenameforexport = $website->name_template;
2931 if (empty($templatenameforexport)) {
2932 $templatenameforexport =
'website_' . $website->ref;
2936 $out .=
'<input type="button" class="cursorpointer button bordertransp" id="open-dialog-' . $name .
'" value="' .
dol_escape_htmltag($buttonstring) .
'"/>';
2939 $out .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">';
2940 $out .=
'jQuery(document).ready(function () {';
2941 $out .=
' jQuery("#open-dialog-' . $name .
'").click(function () {';
2942 $out .=
' var dialogHtml = \'';
2944 $dialogcontent =
' <div id="custom-dialog-' . $name .
'">';
2945 $dialogcontent .=
' <div style="margin-top: 20px;">';
2946 $dialogcontent .=
' <label for="export-site-' . $name .
'"><strong>' . $langs->trans(
"ExportSiteLabel") .
'...</label><br>';
2947 $dialogcontent .=
' <button class="button smallpaddingimp" id="export-site-' . $name .
'">' .
dol_escape_htmltag($langs->trans(
"DownloadZip")) .
'</button>';
2948 $dialogcontent .=
' </div>';
2949 $dialogcontent .=
' <br>';
2950 $dialogcontent .=
' <div style="margin-top: 20px;">';
2951 $dialogcontent .=
' <strong>' . $langs->trans(
"ExportSiteGitLabel") .
' ' . $form->textwithpicto(
'', $langs->trans(
"SourceFiles"), 1,
'help',
'', 0, 3,
'') .
'</strong><br>';
2952 $dialogcontent .=
' <form action="' .
dol_escape_htmltag($overwriteGitUrl) .
'" method="POST">';
2953 $dialogcontent .=
' <input type="hidden" name="action" value="overwritesite">';
2954 $dialogcontent .=
' <input type="hidden" name="token" value="' .
newToken() .
'">';
2955 $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>';
2956 $dialogcontent .=
' <button type="submit" class="button smallpaddingimp" id="overwrite-git-' . $name .
'">' .
dol_escape_htmltag($langs->trans(
"ExportIntoGIT")) .
'</button>';
2957 $dialogcontent .=
' </form>';
2958 $dialogcontent .=
' </div>';
2959 $dialogcontent .=
' </div>';
2966 // Add the content of the dialog to the body of the page
2967 $out .= ' var $dialog = jQuery(
"#custom-dialog-' . $name . '");
';
2968 $out .= ' if ($dialog.length > 0) {
2971 jQuery(
"body").append(dialogHtml);
';
2973 // Configuration of popup
2974 $out .= ' jQuery(
"#custom-dialog-' . $name . '").dialog({
';
2975 $out .= ' autoOpen:
false,
';
2976 $out .= ' modal:
true,
';
2977 $out .= ' height: 290,
';
2978 $out .= ' width:
"40%",
';
2979 $out .= ' title:
"' . dol_escape_js($label) . '",
';
2982 // Simulate a click on the original "submit" input to export the site.
2983 $out .= ' jQuery(
"#export-site-' . $name . '").click(
function () {
';
2984 $out .= ' console.log(
"Clic on exportsite.");
';
2985 $out .= ' var target = jQuery(
"input[name=\'' . dol_escape_js($exportSiteName) . '\']");
';
2986 $out .= ' console.log(
"element founded:", target.length > 0);
';
2987 $out .= ' if (target.length > 0) { target.click(); }
';
2988 $out .= ' jQuery(
"#custom-dialog-' . $name . '").dialog(
"close");
';
2992 $out .= ' jQuery(
"#custom-dialog-' . $name . '").dialog(
"open");
';
2993 $out .= ' return false;
';
2996 $out .= '</script>
';
3018function dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled = '
', $morecss = 'classlink
button bordertransp
', $jsonopen = '', $jsonclose = '', $accesskey = '')
3022 if (strpos($url, '?
') > 0) {
3023 $url .= '&dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup=
' . urlencode($name);
3025 $url .= '?dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup=
' . urlencode($name);
3028 if (preg_match('/^https/i
', $url)) {
3031 $urltoopen = DOL_URL_ROOT . $url;
3036 //print '<input
type=
"submit" class=
"button bordertransp"'.$disabled.' value=
"'.dol_escape_htmltag($langs->trans("MediaFiles
")).'" name=
"file_manager">
';
3037 $out .= '<!-- a link
for button to open url into a dialog popup -->
';
3038 $out .= '<a
' . ($accesskey ? ' accesskey=
"' . $accesskey . '"' : '') . ' class=
"cursorpointer reposition button_' . $name . ($morecss ? ' ' . $morecss : '') . '"' . $disabled . ' title=
"' . dol_escape_htmltag($label) . '"';
3039 if (empty($conf->use_javascript_ajax)) {
3040 $out .= ' href=
"' . $urltoopen . '" target=
"_blank"';
3041 } elseif ($jsonopen) {
3042 $out .= ' href=
"#" onclick=
"' . $jsonopen . '"';
3044 $out .= ' href=
"#"';
3046 $out .= '>
' . $buttonstring . '</a>
';
3048 if (!empty($conf->use_javascript_ajax)) {
3049 // Add code to open url using the popup.
3050 $out .= '<!-- code to open popup and variables to retrieve returned variables -->
';
3051 $out .= '<div
id=
"idfordialog' . $name . '" class=
"hidden">
' . (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER
') < 2 ? 'div
for dialog
' : '') . '</div>
';
3053 $out .= '<!-- Add js code to open dialog popup on dialog -->
';
3054 $out .= '<script nonce=
"' . getNonce() . '" type=
"text/javascript">
3055 jQuery(document).ready(
function () {
3056 jQuery(
".button_' . $name . '").click(
function () {
3057 console.log(\
'Open popup with jQuery(...).dialog() on URL ' .
dol_escape_js($urltoopen) .
'\');
3058 var $tmpdialog = $(\
'#idfordialog' . $name .
'\');
3059 $tmpdialog.html(\
'<iframe class="iframedialog" id="iframedialog' . $name .
'" style="border: 0px;" src="' . $urltoopen .
'" width="100%" height="98%"></iframe>\');
3063 height: (window.innerHeight - 150),
3066 open: function (event, ui) {
3067 console.log(
"open popup name=' . $name . '");
3069 close:
function (event, ui) {
3070 console.log(
"Popup is closed, run jsonclose = ' . $jsonclose . '");
3071 ' . (empty($jsonclose) || preg_match('/^TODO/
', $jsonclose) ? '' : $jsonclose . ';
') . '
3075 $tmpdialog.dialog(\
'open\');
3100function dol_fiche_head($links = array(), $active =
'0', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'')
3102 print
dol_get_fiche_head($links, $active, $title, $notab, $picto, $pictoisfullpath, $morehtmlright, $morecss, $limittoshow, $moretabssuffix);
3122function dol_get_fiche_head($links = array(), $active =
'', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'', $dragdropfile = 0, $morecssdiv =
'')
3124 global
$conf, $langs, $hookmanager;
3128 if (!empty(
$conf->dol_optimize_smallscreen)) {
3132 $out =
"\n" .
'<!-- dol_fiche_head - dol_get_fiche_head -->';
3134 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
3135 $out .=
'<div class="tabs' . ($picto ?
'' :
' nopaddingleft') .
'" data-role="controlgroup" data-type="horizontal">' .
"\n";
3139 if ($morehtmlright) {
3140 $out .=
'<div class="inline-block floatright tabsElem">' . $morehtmlright .
'</div>';
3147 if (is_array($links) && !empty($links)) {
3148 $keys = array_keys($links);
3150 $maxkey = max($keys);
3156 if (empty($limittoshow)) {
3159 if (!empty(
$conf->dol_optimize_smallscreen)) {
3167 for ($i = 0; $i <= $maxkey; $i++) {
3168 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
3170 if ($i >= $limittoshow) {
3176 for ($i = 0; $i <= $maxkey; $i++) {
3177 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
3183 if ($i < $limittoshow || $isactive) {
3185 $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])) .
' -->';
3187 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
3188 if (!empty($links[$i][0])) {
3189 $out .=
'<a class="tabimage' . ($morecss ?
' ' . $morecss :
'') .
'" href="' . $links[$i][0] .
'">' . $links[$i][1] .
'</a>' .
"\n";
3191 $out .=
'<span class="tabspan">' . $links[$i][1] .
'</span>' .
"\n";
3193 } elseif (!empty($links[$i][1])) {
3195 $out .=
'<div class="tab tab' . ($isactive ?
'active' :
'unactive') .
'" style="margin: 0 !important">';
3197 if (!empty($links[$i][0])) {
3198 $titletoshow = preg_replace(
'/<.*$/',
'', $links[$i][1]);
3199 $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) .
'">';
3202 if ($displaytab == 0 && $picto) {
3203 $out .=
img_picto($title, $picto,
'', $pictoisfullpath, 0, 0,
'',
'imgTabTitle paddingright marginrightonlyshort');
3206 $out .= $links[$i][1];
3207 if (!empty($links[$i][0])) {
3208 $out .=
'</a>' .
"\n";
3210 $out .= empty($links[$i][4]) ?
'' : $links[$i][4];
3219 $outmore .=
'<div class="popuptabset wordwrap">';
3221 $outmore_content =
'';
3223 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
3224 if (!empty($links[$i][0])) {
3225 $outmore_content .=
'<a class="tabimage' . ($morecss ?
' ' . $morecss :
'') .
'" href="' . $links[$i][0] .
'">' . $links[$i][1] .
'</a>' .
"\n";
3227 $outmore_content .=
'<span class="tabspan">' . $links[$i][1] .
'</span>' .
"\n";
3229 } elseif (!empty($links[$i][1])) {
3230 $outmore_content .=
'<a' . (!empty($links[$i][2]) ?
' id="' . $links[$i][2] .
'"' :
'') .
' class="wordwrap inline-block' . ($morecss ?
' ' . $morecss :
'') .
'" href="' . $links[$i][0] .
'">';
3231 $outmore_content .= preg_replace(
'/([a-z])\|([a-z])/i',
'\\1 | \\2', $links[$i][1]);
3232 $outmore_content .=
'</a>' .
"\n";
3234 if ($outmore_content !==
'') {
3235 $outmore .=
'<div class="popuptab wordwrap" style="display:inherit;">' . $outmore_content .
'</div>';
3241 $displaytab = $i + 1;
3244 $outmore .=
'</div>';
3248 $left = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'right' :
'left');
3249 $right = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right');
3250 $widthofpopup = 240;
3252 $tabsname = $moretabssuffix;
3253 if (empty($tabsname)) {
3254 $tabsname = str_replace(
"@",
"", $picto);
3256 $out .=
'<div id="moretabs' . $tabsname .
'" class="inline-block tabsElem valignmiddle">';
3258 $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>';
3260 $out .=
'<div id="moretabsList' . $tabsname .
'" style="width: ' . $widthofpopup .
'px; position: absolute; ' . $left .
': -999em; text-align: ' . $left .
'; margin:0px; padding:2px; z-index:10;">';
3263 $out .=
'<div></div>';
3266 $out .=
'<script nonce="' .
getNonce() .
'">';
3267 $out .=
"$('#moretabs" . $tabsname .
"').mouseenter( function() {
3268 var x = this.offsetLeft, y = this.offsetTop;
3269 console.log('mouseenter " . $left .
" x='+x+' y='+y+' window.innerWidth='+window.innerWidth);
3270 if ((window.innerWidth - x) < " . ($widthofpopup + 10) .
") {
3271 $('#moretabsList" . $tabsname .
"').css('" . $right .
"','8px');
3273 $('#moretabsList" . $tabsname .
"').css('" . $left .
"','auto');
3276 $out .=
"$('#moretabs" . $tabsname .
"').mouseleave( function() { console.log('mouseleave " . $left .
"'); $('#moretabsList" . $tabsname .
"').css('" . $left .
"','-999em');});";
3277 $out .=
"</script>";
3280 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
3284 if (!$notab || $notab == -1 || $notab == -2 || $notab == -3 || $notab == -4) {
3285 $out .=
"\n" .
'<div id="dragDropAreaTabBar" class="tabBar' . ($notab == -1 ?
'' : ($notab == -2 ?
' tabBarNoTop' : ((($notab == -3 || $notab == -4) ?
' noborderbottom' :
'') . ($notab == -4 ?
'' :
' tabBarWithBottom'))));
3286 $out .= ($morecssdiv ?
' ' . $morecssdiv :
'');
3287 $out .=
'">' .
"\n";
3289 if (!empty($dragdropfile)) {
3290 include_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
3293 $parameters = array(
'tabname' => $active,
'out' => $out);
3294 $reshook = $hookmanager->executeHooks(
'printTabsHead', $parameters);
3296 $out = $hookmanager->resPrint;
3322 if (!$notab || $notab == -1) {
3323 return "\n</div>\n";
3348function dol_banner_tab(
$object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $onlybanner = 0, $morehtmlright =
'')
3350 global
$conf, $form, $user, $langs, $hookmanager, $action;
3354 $maxvisiblephotos = 1;
3359 if (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'barcode',
'lire_advance')) {
3362 $modulepart =
'unknown';
3364 if (in_array(
$object->element, [
'societe',
'contact',
'product',
'ticket',
'bom'])) {
3365 $modulepart =
$object->element;
3366 } elseif (
$object->element ==
'member') {
3367 $modulepart =
'memberphoto';
3368 } elseif (
$object->element ==
'user') {
3369 $modulepart =
'userphoto';
3372 if (class_exists(
"Imagick")) {
3373 if (
$object->element ==
'expensereport' ||
$object->element ==
'propal' ||
$object->element ==
'commande' ||
$object->element ==
'facture' ||
$object->element ==
'supplier_proposal') {
3374 $modulepart =
$object->element;
3375 } elseif (
$object->element ==
'fichinter' ||
$object->element ==
'intervention') {
3376 $modulepart =
'ficheinter';
3377 } elseif (
$object->element ==
'contrat' ||
$object->element ==
'contract') {
3378 $modulepart =
'contract';
3379 } elseif (
$object->element ==
'order_supplier') {
3380 $modulepart =
'supplier_order';
3381 } elseif (
$object->element ==
'invoice_supplier') {
3382 $modulepart =
'supplier_invoice';
3386 if (
$object->element ==
'product') {
3388 '@phan-var-force Product $object';
3390 $cssclass =
'photowithmargin photoref';
3391 $showimage =
$object->is_photo_available(
$conf->product->multidir_output[$entity]);
3393 if (
$conf->browser->layout ==
'phone') {
3394 $maxvisiblephotos = 1;
3396 $useLinkPathPhoto =
getDolGlobalInt(
'PRODUCT_USE_LINK_PATH_FOR_PHOTO');
3397 if ($showimage || $useLinkPathPhoto) {
3398 $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>';
3402 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3404 $nophoto =
'/public/theme/common/nophoto.png';
3405 $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>';
3408 } elseif (
$object->element ==
'category') {
3410 '@phan-var-force Categorie $object';
3412 $cssclass =
'photowithmargin photoref';
3413 $showimage =
$object->isAnyPhotoAvailable(
$conf->categorie->multidir_output[$entity]);
3415 if (
$conf->browser->layout ==
'phone') {
3416 $maxvisiblephotos = 1;
3419 $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>';
3423 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3425 $nophoto =
'/public/theme/common/nophoto.png';
3426 $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>';
3429 } elseif (
$object->element ==
'bom') {
3431 '@phan-var-force Bom $object';
3433 $cssclass =
'photowithmargin photoref';
3434 $showimage =
$object->is_photo_available(
$conf->bom->multidir_output[$entity]);
3436 if (
$conf->browser->layout ==
'phone') {
3437 $maxvisiblephotos = 1;
3440 $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>';
3444 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3446 $nophoto =
'/public/theme/common/nophoto.png';
3447 $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>';
3450 } elseif (
$object->element ==
'ticket') {
3452 $cssclass =
'photoref';
3454 '@phan-var-force Ticket $object';
3455 $showimage =
$object->is_photo_available(
$conf->ticket->multidir_output[$entity] .
'/' .
$object->ref);
3457 if (
$conf->browser->layout ==
'phone') {
3458 $maxvisiblephotos = 1;
3462 $showphoto =
$object->show_photos(
'ticket',
$conf->ticket->multidir_output[$entity],
'small', $maxvisiblephotos, 0, 0, 0, $width, 0);
3464 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">' . $showphoto .
'</div>';
3472 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
3474 $nophoto =
img_picto(
'No photo',
'object_ticket');
3475 $morehtmlleft .=
'<!-- No photo to show -->';
3476 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
3477 $morehtmlleft .= $nophoto;
3478 $morehtmlleft .=
'</div></div>';
3483 if ($modulepart !=
'unknown' || method_exists(
$object,
'getDataToShowPhoto')) {
3486 if (in_array($modulepart, array(
'propal',
'commande',
'facture',
'ficheinter',
'contract',
'supplier_order',
'supplier_proposal',
'supplier_invoice',
'expensereport')) && class_exists(
"Imagick")) {
3488 $dir_output = (empty(
$conf->$modulepart->multidir_output[$entity]) ?
$conf->$modulepart->dir_output :
$conf->$modulepart->multidir_output[$entity]) .
"/";
3489 if (in_array($modulepart, array(
'invoice_supplier',
'supplier_invoice'))) {
3491 $subdir .= ((!empty($subdir) && !preg_match(
'/\/$/', $subdir)) ?
'/' :
'') . $objectref;
3495 if (empty($subdir)) {
3496 $subdir =
'errorgettingsubdirofobject';
3499 $filepath = $dir_output . $subdir .
"/";
3501 $filepdf = $filepath . $objectref .
".pdf";
3502 $relativepath = $subdir .
'/' . $objectref .
'.pdf';
3505 $fileimage = $filepdf .
'_preview.png';
3506 $relativepathimage = $relativepath .
'_preview.png';
3508 $pdfexists = file_exists($filepdf);
3513 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
3515 include_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
3524 if ($pdfexists && !$error) {
3525 $heightforphotref = 80;
3526 if (!empty(
$conf->dol_optimize_smallscreen)) {
3527 $heightforphotref = 60;
3530 if (file_exists($fileimage)) {
3531 $phototoshow =
'<div class="photoref">';
3532 $phototoshow .=
'<img height="' . $heightforphotref .
'" class="photo photowithborder" src="' . DOL_URL_ROOT .
'/viewimage.php?modulepart=apercu' . $modulepart .
'&file=' . urlencode($relativepathimage) .
'">';
3533 $phototoshow .=
'</div>';
3536 } elseif (!$phototoshow) {
3537 $phototoshow .= $form->showphoto($modulepart,
$object, 0, 0, 0,
'photowithmargin photoref',
'small', 1, 0);
3541 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">';
3542 $morehtmlleft .= $phototoshow;
3543 $morehtmlleft .=
'</div>';
3547 if (empty($phototoshow)) {
3548 if (
$object->element ==
'action') {
3550 $cssclass =
'photorefcenter';
3551 $nophoto =
img_picto(
'No photo',
'title_agenda');
3554 $cssclass =
'photorefcenter';
3556 $prefix =
'object_';
3560 if (strpos($picto,
'fontawesome_') !==
false) {
3563 $nophoto =
img_picto(
'No photo', $prefix . $picto);
3565 $morehtmlleft .=
'<!-- No photo to show -->';
3566 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
3567 $morehtmlleft .= $nophoto;
3568 $morehtmlleft .=
'</div></div>';
3573 $morehtmlref .=
'<div style="clear: both;"></div>';
3574 $morehtmlref .=
'<div class="smallimp refidno opacitymedium banner-object-technical-id">';
3575 $morehtmlref .= $langs->trans(
"TechnicalID") .
': ' . ((int)
$object->id);
3576 $morehtmlref .=
'</div>';
3582 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">' . $form->showbarcode(
$object, 100,
'photoref valignmiddle') .
'</div>';
3585 if (
$object->element ==
'societe') {
3587 if (!empty(
$conf->use_javascript_ajax) && $user->hasRight(
'societe',
'creer') &&
getDolGlobalString(
'MAIN_DIRECT_STATUS_UPDATE')) {
3590 $morehtmlstatus .=
$object->getLibStatut(6);
3592 } elseif (
$object->element ==
'product') {
3595 if (!empty(
$conf->use_javascript_ajax) && $user->hasRight(
'produit',
'creer') &&
getDolGlobalString(
'MAIN_DIRECT_STATUS_UPDATE')) {
3596 $morehtmlstatus .=
ajax_object_onoff(
$object,
'status',
'status',
'ProductStatusOnSell',
'ProductStatusNotOnSell');
3598 $morehtmlstatus .=
'<span class="statusrefsell">' .
$object->getLibStatut(6, 0) .
'</span>';
3600 $morehtmlstatus .=
' ';
3602 if (!empty(
$conf->use_javascript_ajax) && $user->hasRight(
'produit',
'creer') &&
getDolGlobalString(
'MAIN_DIRECT_STATUS_UPDATE')) {
3603 $morehtmlstatus .=
ajax_object_onoff(
$object,
'status_buy',
'status_buy',
'ProductStatusOnBuy',
'ProductStatusNotOnBuy');
3605 $morehtmlstatus .=
'<span class="statusrefbuy">' .
$object->getLibStatut(6, 1) .
'</span>';
3607 } elseif (in_array(
$object->element, array(
'salary'))) {
3609 '@phan-var-force Salary $object';
3611 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3614 $morehtmlstatus .= $tmptxt;
3615 } elseif (in_array(
$object->element, array(
'facture',
'invoice',
'invoice_supplier'))) {
3617 '@phan-var-force Facture|FactureFournisseur|CommonInvoice $object';
3618 if (!isset(
$object->alreadypaid)) {
3624 $tmptxt =
$object->getLibStatut(6, (
float)
$object->alreadypaid);
3625 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3626 $tmptxt =
$object->getLibStatut(5, (
float)
$object->alreadypaid);
3628 $morehtmlstatus .= $tmptxt;
3629 } elseif (in_array(
$object->element, array(
'chargesociales',
'loan',
'tva'))) {
3631 '@phan-var-force ChargeSociales|Loan|Tva $object';
3633 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3636 $morehtmlstatus .= $tmptxt;
3637 } elseif (
$object->element ==
'contrat' ||
$object->element ==
'contract') {
3640 $morehtmlstatus .=
$object->getLibStatut(5);
3642 $morehtmlstatus .=
$object->getLibStatut(4);
3644 } elseif (
$object->element ==
'facturerec') {
3646 '@phan-var-force FactureRec $object';
3647 if (
$object->frequency == 0) {
3648 $morehtmlstatus .=
$object->getLibStatut(2);
3650 $morehtmlstatus .=
$object->getLibStatut(5);
3652 } elseif (
$object->element ==
'project_task') {
3654 $tmptxt =
$object->getLibStatut(4);
3655 $morehtmlstatus .= $tmptxt;
3656 } elseif (method_exists(
$object,
'getLibStatut')) {
3657 $tmptxt =
$object->getLibStatut(6);
3658 if (empty($tmptxt) || $tmptxt ==
$object->getLibStatut(3)) {
3659 $tmptxt =
$object->getLibStatut(5);
3661 $morehtmlstatus .= $tmptxt;
3665 if (
isModEnabled(
'accounting') && in_array(
$object->element, array(
'bank',
'paiementcharge',
'facture',
'invoice',
'invoice_supplier',
'expensereport',
'payment_various'))) {
3667 if (method_exists(
$object,
'getVentilExportCompta')) {
3668 $accounted =
$object->getVentilExportCompta(1);
3669 $langs->load(
"accountancy");
3670 $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>';
3675 if (!empty(
$object->name_alias)) {
3677 '@phan-var-force Societe $object';
3678 $morehtmlref .=
'<div class="refidno opacitymedium banner-object-name-alias">' .
dol_escape_htmltag(
$object->name_alias) .
'</div>';
3682 if (in_array(
$object->element, array(
'product',
'bank_account',
'project_task'))) {
3685 $morehtmlref .=
'<div class="refidno banner-object-label">' .
$object->label .
'</div>';
3689 if (method_exists(
$object,
'getBannerAddress') && !in_array(
$object->element, array(
'product',
'bookmark',
'ecm_directories',
'ecm_files'))) {
3692 $morehtmlref .=
'<div class="refidno refaddress">';
3693 $morehtmlref .= $moreaddress;
3694 $morehtmlref .=
'</div>';
3698 $parameters = array(
'morehtmlref' => &$morehtmlref,
'moreparam' => &$moreparam,
'morehtmlleft' => &$morehtmlleft,
'morehtmlstatus' => &$morehtmlstatus,
'morehtmlright' => &$morehtmlright);
3699 $reshook = $hookmanager->executeHooks(
'formDolBanner', $parameters,
$object, $action);
3702 } elseif (empty($reshook)) {
3703 $morehtmlref .= $hookmanager->resPrint;
3704 } elseif ($reshook > 0) {
3705 $morehtmlref = $hookmanager->resPrint;
3714 print
'<div class="' . ($onlybanner ?
'arearefnobottom ' :
'arearef ') .
'heightref valignmiddle centpercent object-banner-tab-container" data-module-part="'.
dolPrintHTMLForAttribute($modulepart).
'">';
3715 print $form->showrefnav(
$object, $paramid, $morehtml, $shownav, $fieldid, $fieldref, $morehtmlref, $moreparam, $nodbprefix, $morehtmlleft, $morehtmlstatus, $morehtmlright);
3717 print
'<div class="underrefbanner clearboth"></div>';
3729function fieldLabel($langkey, $fieldkey, $fieldrequired = 0)
3733 if ($fieldrequired) {
3734 $ret .=
'<span class="fieldrequired">';
3736 $ret .=
'<label for="' . $fieldkey .
'">';
3737 $ret .= $langs->trans($langkey);
3739 if ($fieldrequired) {
3760 global $langs, $hookmanager;
3763 $countriesusingstate = array(
'AU',
'CA',
'US',
'IN',
'GB',
'ES',
'UK',
'TR',
'CN');
3768 $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)));
3771 if (isset(
$object->country_code) && in_array(
$object->country_code, array(
'AU',
'CA',
'US',
'CN')) ||
getDolGlobalString(
'MAIN_FORCE_STATE_INTO_ADDRESS')) {
3773 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3774 $ret .= (($ret && $town) ? $sep :
'') . $town;
3777 $ret .= ($ret ? ($town ?
", " : $sep) :
'') .
$object->state;
3780 $ret .= ($ret ? (($town ||
$object->state) ?
", " : $sep) :
'') .
$object->zip;
3782 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'GB',
'UK'))) {
3784 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3785 $ret .= ($ret ? $sep :
'') . $town;
3787 $ret .= ($ret ?
", " :
'') .
$object->state;
3790 $ret .= ($ret ? $sep :
'') .
$object->zip;
3792 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'ES',
'TR'))) {
3794 $ret .= ($ret ? $sep :
'') .
$object->zip;
3795 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3796 $ret .= ($town ? ((
$object->zip ?
' ' :
'') . $town) :
'');
3798 $ret .= $sep .
$object->state;
3800 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'JP'))) {
3803 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3805 } elseif (isset(
$object->country_code) && in_array(
$object->country_code, array(
'IT'))) {
3807 $ret .= ($ret ? $sep :
'') .
$object->zip;
3808 $town = ($extralangcode ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3809 $ret .= ($town ? ((
$object->zip ?
' ' :
'') . $town) :
'');
3810 $ret .= (empty(
$object->state_code) ?
'' : (
' ' .
$object->state_code));
3813 $town = (($extralangcode && !empty(
$object->array_languages[
'address'][$extralangcode])) ?
$object->array_languages[
'town'][$extralangcode] : (empty(
$object->town) ?
'' :
$object->town));
3814 $ret .= !empty(
$object->zip) ? (($ret ? $sep :
'') .
$object->zip) :
'';
3815 $ret .= ($town ? ((
$object->zip ?
' ' : ($ret ? $sep :
'')) . $town) :
'');
3816 if (!empty(
$object->state) && in_array(
$object->country_code, $countriesusingstate)) {
3817 $ret .= ($ret ?
", " :
'') .
$object->state;
3821 if (!is_object($outputlangs)) {
3822 $outputlangs = $langs;
3825 $langs->load(
"dict");
3826 $ret .= (empty(
$object->country_code) ?
'' : ($ret ? $sep :
'') . $outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv(
"Country" .
$object->country_code)));
3829 $parameters = array(
'withcountry' => $withcountry,
'sep' => $sep,
'outputlangs' => $outputlangs,
'mode' => $mode,
'extralangcode' => $extralangcode);
3830 $reshook = $hookmanager->executeHooks(
'formatAddress', $parameters,
$object);
3834 $ret .= $hookmanager->resPrint;
3851function dol_strftime($fmt, $ts =
false, $is_gmt =
false)
3853 if ((abs($ts) <= 0x7FFFFFFF)) {
3856 return 'Error date outside supported range';
3882function dol_print_date($time, $format =
'', $tzoutput =
'auto', $outputlangs =
null, $encodetooutput =
false, $decorate = 0)
3884 global
$conf, $langs;
3891 if ($tzoutput ===
'auto') {
3892 $tzoutput = (empty(
$conf) ?
'tzserver' : (isset(
$conf->tzuserinputkey) ?
$conf->tzuserinputkey :
'tzserver'));
3897 $offsettz = $offsetdst = 0;
3900 if (is_string($tzoutput)) {
3901 if ($tzoutput ==
'tzserver') {
3903 $offsettzstring = @date_default_timezone_get();
3908 } elseif ($tzoutput ==
'tzuser' || $tzoutput ==
'tzuserrel') {
3911 $offsettzstring = (empty($_SESSION[
'dol_tz_string']) ?
getDolGlobalString(
'MAIN_DOLIBARR_USER_TIMEZONE',
'UTC') : $_SESSION[
'dol_tz_string']);
3913 if (class_exists(
'DateTimeZone')) {
3915 $user_date_tz =
new DateTimeZone($offsettzstring);
3918 dol_syslog(
"DateInvalidTimeZoneException for timezone string '".$offsettzstring.
"'. Falling back to UTC.", LOG_ERR);
3919 $user_date_tz =
new DateTimeZone(
'UTC');
3921 $user_dt =
new DateTime();
3922 $user_dt->setTimezone($user_date_tz);
3923 $user_dt->setTimestamp($tzoutput ==
'tzuser' ?
dol_now() : (int) $time);
3924 $offsettz = $user_dt->getOffset();
3926 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
3927 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
3932 if (!is_object($outputlangs)) {
3933 $outputlangs = $langs;
3936 $format =
'daytextshort';
3941 $reduceformat = (!empty(
$conf->dol_optimize_smallscreen) && in_array($format, array(
'day',
'dayhour',
'dayhoursec'))) ? 1 : 0;
3942 $format = preg_replace(
'/inputnoreduce/',
'', $format);
3943 $formatwithoutreduce = preg_replace(
'/reduceformat/',
'', $format);
3944 if ($formatwithoutreduce != $format) {
3945 $format = $formatwithoutreduce;
3951 if ($format ==
'day') {
3952 $format = ($outputlangs->trans(
"FormatDateShort") !=
"FormatDateShort" ? $outputlangs->trans(
"FormatDateShort") :
$conf->format_date_short);
3953 } elseif ($format ==
'hour') {
3954 $format = ($outputlangs->trans(
"FormatHourShort") !=
"FormatHourShort" ? $outputlangs->trans(
"FormatHourShort") :
$conf->format_hour_short);
3955 } elseif ($format ==
'hoursec') {
3956 $s1 = $outputlangs->trans(
"FormatDateShort");
3957 $s2 = $outputlangs->trans(
"FormatDateHourSecShort");
3958 $s3 = trim(preg_replace(
'/'.preg_quote($s1,
'/').
'/',
'', $s2));
3961 } elseif ($format ==
'hourduration') {
3962 $format = ($outputlangs->trans(
"FormatHourShortDuration") !=
"FormatHourShortDuration" ? $outputlangs->trans(
"FormatHourShortDuration") :
$conf->format_hour_short_duration);
3963 } elseif ($format ==
'daytext') {
3964 $format = ($outputlangs->trans(
"FormatDateText") !=
"FormatDateText" ? $outputlangs->trans(
"FormatDateText") :
$conf->format_date_text);
3965 } elseif ($format ==
'daytextshort') {
3966 $format = ($outputlangs->trans(
"FormatDateTextShort") !=
"FormatDateTextShort" ? $outputlangs->trans(
"FormatDateTextShort") :
$conf->format_date_text_short);
3967 } elseif ($format ==
'dayhour') {
3968 $format = ($outputlangs->trans(
"FormatDateHourShort") !=
"FormatDateHourShort" ? $outputlangs->trans(
"FormatDateHourShort") :
$conf->format_date_hour_short);
3969 } elseif ($format ==
'dayhoursec') {
3970 $format = ($outputlangs->trans(
"FormatDateHourSecShort") !=
"FormatDateHourSecShort" ? $outputlangs->trans(
"FormatDateHourSecShort") :
$conf->format_date_hour_sec_short);
3971 } elseif ($format ==
'dayhourtext') {
3972 $format = ($outputlangs->trans(
"FormatDateHourText") !=
"FormatDateHourText" ? $outputlangs->trans(
"FormatDateHourText") :
$conf->format_date_hour_text);
3973 } elseif ($format ==
'dayhourtextshort') {
3974 $format = ($outputlangs->trans(
"FormatDateHourTextShort") !=
"FormatDateHourTextShort" ? $outputlangs->trans(
"FormatDateHourTextShort") :
$conf->format_date_hour_text_short);
3975 } elseif ($format ==
'dayhourlog') {
3977 $format =
'%Y%m%d%H%M%S';
3978 } elseif ($format ==
'dayhourlogsmall') {
3980 $format =
'%y%m%d%H%M';
3981 } elseif ($format ==
'dayhourldap') {
3982 $format =
'%Y%m%d%H%M%SZ';
3983 } elseif ($format ==
'dayhourxcard') {
3984 $format =
'%Y%m%dT%H%M%SZ';
3985 } elseif ($format ==
'dayxcard') {
3987 } elseif ($format ==
'dayrfc') {
3988 $format =
'%Y-%m-%d';
3989 } elseif ($format ==
'dayhourrfc') {
3990 $format =
'%Y-%m-%dT%H:%M:%SZ';
3991 } elseif ($format ==
'standard') {
3992 $format =
'%Y-%m-%d %H:%M:%S';
3995 if ($reduceformat) {
3996 $format = str_replace(
'%Y',
'%y', $format);
3997 $format = str_replace(
'yyyy',
'yy', $format);
4001 if (preg_match(
'/%b/i', $format)) {
4003 $format = str_replace(
'%b',
'__b__', $format);
4004 $format = str_replace(
'%B',
'__B__', $format);
4006 if (preg_match(
'/%a/i', $format)) {
4008 $format = str_replace(
'%a',
'__a__', $format);
4009 $format = str_replace(
'%A',
'__A__', $format);
4014 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)) {
4017 } elseif (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', (
string) $time, $reg)) {
4021 $syear = (!empty($reg[1]) ? $reg[1] :
'');
4022 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
4023 $sday = (!empty($reg[3]) ? $reg[3] :
'');
4024 $shour = (!empty($reg[4]) ? $reg[4] :
'');
4025 $smin = (!empty($reg[5]) ? $reg[5] :
'');
4026 $ssec = (!empty($reg[6]) ? $reg[6] :
'');
4028 $time =
dol_mktime((
int) $shour, (
int) $smin, (
int) $ssec, (
int) $smonth, (
int) $sday, (
int) $syear,
true);
4031 $tzo =
new DateTimeZone(
'UTC');
4033 $tzo =
new DateTimeZone(date_default_timezone_get());
4035 $dtts =
new DateTime();
4036 $dtts->setTimestamp($time);
4037 $dtts->setTimezone($tzo);
4038 $newformat = str_replace(
4039 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
4040 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
4043 $ret = $dtts->format($newformat);
4045 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
4046 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
4051 if ($time < 100000000000) {
4052 $dtts =
new DateTime();
4055 $timetouse = (int) $time + $offsettz + $offsetdst;
4057 $tzo =
new DateTimeZone(
'UTC');
4058 $dtts->setTimezone($tzo);
4059 $dtts->setTimestamp($timetouse);
4061 $timetouse = (int) $time + $offsettz + $offsetdst;
4063 $tzo =
new DateTimeZone(date_default_timezone_get());
4064 $dtts->setTimestamp($timetouse);
4065 $dtts->setTimezone($tzo);
4068 $newformat = str_replace(
4069 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'%w',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
4070 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'w',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
4074 $ret = $dtts->format($newformat);
4077 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
4078 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
4082 $ret =
'Bad value ' . $time .
' for date';
4086 if (preg_match(
'/__b__/i', $format)) {
4087 $timetouse = $time + $offsettz + $offsetdst;
4090 $tzo =
new DateTimeZone(
'UTC');
4092 $tzo =
new DateTimeZone(date_default_timezone_get());
4094 $dtts =
new DateTime();
4095 $dtts->setTimestamp($timetouse);
4096 $dtts->setTimezone($tzo);
4097 $month = (int) $dtts->format(
"m");
4098 $month = sprintf(
"%02d", $month);
4099 if ($encodetooutput) {
4100 $monthtext = $outputlangs->transnoentities(
'Month' . $month);
4101 $monthtextshort = $outputlangs->transnoentities(
'MonthShort' . $month);
4103 $monthtext = $outputlangs->transnoentitiesnoconv(
'Month' . $month);
4104 $monthtextshort = $outputlangs->transnoentitiesnoconv(
'MonthShort' . $month);
4107 $ret = str_replace(
'__b__', $monthtextshort, $ret);
4108 $ret = str_replace(
'__B__', $monthtext, $ret);
4112 if (preg_match(
'/__a__/i', $format)) {
4114 $timetouse = $time + $offsettz + $offsetdst;
4117 $tzo =
new DateTimeZone(
'UTC');
4119 $tzo =
new DateTimeZone(date_default_timezone_get());
4121 $dtts =
new DateTime();
4122 $dtts->setTimestamp($timetouse);
4123 $dtts->setTimezone($tzo);
4124 $w = $dtts->format(
"w");
4125 $dayweek = $outputlangs->transnoentitiesnoconv(
'Day' . $w);
4127 $ret = str_replace(
'__A__', $dayweek, $ret);
4128 $ret = str_replace(
'__a__',
dol_substr($dayweek, 0, 3), $ret);
4132 $ret = preg_replace(
'/(\d\d:\d\d [AP]M)$/',
'<span class="'.($decorate === 1 ?
'opacitymedium' : $decorate).
'">\1</span>', $ret);
4133 $ret = preg_replace(
'/(\d\d:\d\d)$/',
'<span class="'.($decorate === 1 ?
'opacitymedium' : $decorate).
'">\1</span>', $ret);
4160function dol_getdate($timestamp, $fast =
false, $forcetimezone =
'')
4162 if ($timestamp ===
'') {
4166 $datetimeobj =
new DateTime();
4167 $datetimeobj->setTimestamp($timestamp);
4168 if ($forcetimezone) {
4169 $datetimeobj->setTimezone(
new DateTimeZone($forcetimezone ==
'gmt' ?
'UTC' : $forcetimezone));
4172 'year' => ((
int) date_format($datetimeobj,
'Y')),
4173 'mon' => ((
int) date_format($datetimeobj,
'm')),
4174 'mday' => ((
int) date_format($datetimeobj,
'd')),
4175 'wday' => ((
int) date_format($datetimeobj,
'w')),
4176 'yday' => ((
int) date_format($datetimeobj,
'z')),
4177 'hours' => ((
int) date_format($datetimeobj,
'H')),
4178 'minutes' => ((
int) date_format($datetimeobj,
'i')),
4179 'seconds' => ((
int) date_format($datetimeobj,
's')),
4207function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm =
'auto', $check = 1)
4212 if ($gm ===
'auto') {
4213 $gm = (empty(
$conf) ?
'tzserver' :
$conf->tzuserinputkey);
4218 if ($hour == -1 || empty($hour)) {
4221 if ($minute == -1 || empty($minute)) {
4224 if ($second == -1 || empty($second)) {
4230 if (!$month || !$day) {
4239 if ($hour < 0 || $hour > 24) {
4242 if ($minute < 0 || $minute > 60) {
4245 if ($second < 0 || $second > 60) {
4250 if (empty($gm) || ($gm ===
'server' || $gm ===
'tzserver')) {
4251 $default_timezone = @date_default_timezone_get();
4252 $localtz =
new DateTimeZone($default_timezone);
4253 } elseif ($gm ===
'user' || $gm ===
'tzuser' || $gm ===
'tzuserrel') {
4255 $default_timezone = (empty($_SESSION[
"dol_tz_string"]) ? @date_default_timezone_get() : $_SESSION[
"dol_tz_string"]);
4257 $localtz =
new DateTimeZone($default_timezone);
4259 dol_syslog(
"Warning dol_tz_string contains an invalid value " . json_encode($_SESSION[
"dol_tz_string"] ??
null), LOG_WARNING);
4260 $default_timezone = @date_default_timezone_get();
4262 } elseif (strrpos($gm,
"tz,") !==
false) {
4263 $timezone = (
string) str_replace(
"tz,",
"", $gm);
4265 $localtz =
new DateTimeZone($timezone);
4267 dol_syslog(
"Warning passed timezone contains an invalid value " . $timezone, LOG_WARNING);
4271 if (empty($localtz)) {
4272 $localtz =
new DateTimeZone(
'UTC');
4274 $dt =
new DateTime(
'now', $localtz);
4275 $dt->setDate((
int) $year, (
int) $month, (
int) $day);
4276 $dt->setTime((
int) $hour, (
int) $minute, (
int) $second);
4277 $date = $dt->getTimestamp();
4293function dol_now($mode =
'gmt')
4297 if ($mode ===
'auto') {
4301 if ($mode ==
'gmt') {
4303 } elseif ($mode ==
'tzserver') {
4304 require_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
4306 $ret = (int) (
dol_now(
'gmt') + ($tzsecond * 3600));
4311 } elseif ($mode ==
'tzuser' || $mode ==
'tzuserrel') {
4314 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
4315 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
4316 $ret = (int) (
dol_now(
'gmt') + ($offsettz + $offsetdst));
4333 global
$conf, $langs;
4336 if (!empty(
$conf->dol_optimize_smallscreen)) {
4341 if (empty($shortvalue) || $size < ($level * 10)) {
4343 $textunitshort = $langs->trans(
"b");
4344 $textunitlong = $langs->trans(
"Bytes");
4346 $ret = round($size / $level, 0);
4347 $textunitshort = $langs->trans(
"Kb");
4348 $textunitlong = $langs->trans(
"KiloBytes");
4351 if (empty($shortunit)) {
4352 $ret .=
' ' . $textunitlong;
4354 $ret .=
' ' . $textunitshort;
4370function dol_print_url($url, $target =
'_blank', $max = 32, $withpicto = 0, $morecss =
'')
4378 $linkstart =
'<a href="';
4379 if (!preg_match(
'/^http/i', $url)) {
4380 $linkstart .=
'http://';
4385 $linkstart .=
' target="' . $target .
'"';
4387 $linkstart .=
' title="' . $langs->trans(
"URL") .
': ' . $url .
'"';
4391 if (!preg_match(
'/^http/i', $url)) {
4398 if ($morecss ==
'float') {
4399 return '<div class="nospan' . ($morecss ?
' ' . $morecss :
'') .
'" style="margin-right: 10px">' . ($withpicto ?
img_picto($langs->trans(
"Url"),
'globe',
'class="paddingrightonly"') :
'') . $link .
'</div>';
4401 return $linkstart .
'<span class="nospan' . ($morecss ?
' ' . $morecss :
'') .
'" style="margin-right: 10px">' . ($withpicto ?
img_picto(
'',
'globe',
'class="paddingrightonly"') :
'') . $link .
'</span>' . $linkend;
4418function dol_print_email($email, $contactid = 0, $socid = 0, $addlink = 0, $max = 0, $showinvalid = 2, $withpicto = 0, $morecss =
'paddingrightonly')
4420 global $user, $langs, $hookmanager;
4431 if (empty($email)) {
4435 if ($addlink == 1) {
4436 $newemail =
'<a class="' . ($morecss ? $morecss :
'') .
'" style="text-overflow: ellipsis;" href="';
4437 if (!preg_match(
'/^mailto:/i', $email)) {
4438 $newemail .=
'mailto:';
4440 $newemail .= $email;
4441 $newemail .=
'" target="_blank">';
4443 $newemail .= ($withpicto ?
img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'');
4448 $newemail .= $email;
4450 $newemail .=
'</a>';
4453 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
4454 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
4457 $langs->load(
"errors");
4458 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadEMail", $emailonly),
'',
'paddingrightonly');
4460 $langs->load(
"errors");
4461 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadMXDomain", $emailonly),
'',
'paddingrightonly');
4465 if (($contactid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
4467 $linktoaddaction =
'';
4469 $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>';
4471 if ($linktoaddaction) {
4472 $newemail =
'<div>' . $newemail .
' ' . $linktoaddaction .
'</div>';
4475 } elseif ($addlink ===
'thirdparty') {
4476 $tmpnewemail =
'<a class="' . ($morecss ? $morecss :
'') .
'" style="text-overflow: ellipsis;" href="' . DOL_URL_ROOT .
'/societe/card.php?socid=' . $socid .
'&action=presend&mode=init#formmailbeforetitle">';
4477 $tmpnewemail .= ($withpicto ?
img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'');
4478 if ($withpicto == 1) {
4479 $tmpnewemail .= $newemail;
4481 $tmpnewemail .=
'</a>';
4483 $newemail = $tmpnewemail;
4485 $newemail = ($withpicto ?
img_picto($langs->trans(
"EMail") .
' : ' . $email, (is_numeric($withpicto) ?
'email' : $withpicto),
'class="paddingrightonly"') :
'') . $newemail;
4488 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
4489 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
4492 $langs->load(
"errors");
4493 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadEMail", $email));
4495 $langs->load(
"errors");
4496 $newemail .=
img_warning($langs->transnoentitiesnoconv(
"ErrorBadMXDomain", $emailonly));
4510 $parameters = array(
'cid' => $contactid,
'socid' => $socid,
'addlink' => $addlink,
'picto' => $withpicto);
4512 $reshook = $hookmanager->executeHooks(
'printEmail', $parameters, $email);
4516 $rep .= $hookmanager->resPrint;
4538function dolOutputDates($datep, $datef =
null, $fullday = 0, $addseconds = 0, $pictotoadd =
'', $tzoutput =
'tzuserrel', $reduceformat = 0)
4541 if (empty($datef)) {
4549 if ($tmpa[
'mday'] == $tmpb[
'mday'] && $tmpa[
'mon'] == $tmpb[
'mon'] && $tmpa[
'year'] == $tmpb[
'year']) {
4551 $s .=
'<div class="center inline-block">';
4552 if ($tmpa[
'hours'] != $tmpb[
'hours'] || $tmpa[
'minutes'] != $tmpb[
'minutes']) {
4554 $s .=
dol_print_date($datep,
'day'.($reduceformat ?
'reduceformat' :
''), $tzoutput);
4556 if (empty($fullday)) {
4557 $s .=
'<br><span class="small opacitymedium">';
4558 $s .=
dol_print_date($datep,
'hour'.($addseconds ?
'sec' :
'').
'reduceformat', $tzoutput);
4559 $s .=
'-'.dol_print_date($datef,
'hour'.($addseconds ?
'sec' :
'').
'reduceformat', $tzoutput);
4564 $s .=
dol_print_date($datep,
'day'.($reduceformat ?
'reduceformat' :
''),
'tzuserrel');
4566 if (empty($fullday)) {
4567 $s .=
'<br><span class="small opacitymedium">';
4568 $s .=
dol_print_date($datep,
'hour'.($addseconds ?
'sec' :
'').
'reduceformat', $tzoutput);
4575 $s .=
'<div class="center inline-block dateborderright">';
4576 $s .=
dol_print_date($datep,
'day'.($reduceformat ?
'reduceformat' :
''), $tzoutput);
4577 if (empty($fullday)) {
4578 $s .=
'<br><span class="small opacitymedium">';
4579 $s .=
dol_print_date($datep,
'hour'.($addseconds ?
'sec' :
'').
'reduceformat', $tzoutput);
4583 $s .=
'<div class="center inline-block dateborderleft">';
4584 $s .=
dol_print_date($datef,
'day'.($reduceformat ?
'reduceformat' :
''),
'tzuserrel');
4586 if (empty($fullday)) {
4587 $s .=
'<br><span class="small opacitymedium">';
4588 $s .=
dol_print_date($datef,
'hour'.($addseconds ?
'sec' :
'').
'reduceformat', $tzoutput);
4607 $socialnetworks = array();
4609 require_once DOL_DOCUMENT_ROOT .
'/core/lib/memory.lib.php';
4613 if (!is_null($dataretrieved)) {
4614 $socialnetworks = $dataretrieved;
4616 $sql =
"SELECT rowid, code, label, url, icon, active FROM " . MAIN_DB_PREFIX .
"c_socialnetworks";
4617 $sql .=
" WHERE entity IN (" .
getEntity(
'c_socialnetworks').
")";
4619 $resql =
$db->query($sql);
4621 while ($obj =
$db->fetch_object($resql)) {
4622 $socialnetworks[$obj->code] = array(
4623 'rowid' => $obj->rowid,
4624 'label' => $obj->label,
4626 'icon' => $obj->icon,
4627 'active' => $obj->active,
4634 return (is_array($socialnetworks) ? $socialnetworks : array());
4649 global $hookmanager, $langs, $user;
4653 if (empty($value)) {
4657 if (!empty($type)) {
4658 $htmllink =
'<div class="divsocialnetwork inline-block valignmiddle">';
4660 $htmllink .=
'<span class="fab pictofixedwidth ' . ($dictsocialnetworks[$type][
'icon'] ? $dictsocialnetworks[$type][
'icon'] :
'fa-link') .
'"></span>';
4661 if ($type ==
'skype') {
4663 $htmllink .=
' <a href="skype:';
4665 $htmllink .=
'?call" alt="' . $langs->trans(
"Call") .
' ' . $value .
'" title="' .
dol_escape_htmltag($langs->trans(
"Call") .
' ' . $value) .
'">';
4666 $htmllink .=
'<img src="' . DOL_URL_ROOT .
'/theme/common/skype_callbutton.png" border="0">';
4667 $htmllink .=
'</a><a href="skype:';
4669 $htmllink .=
'?chat" alt="' . $langs->trans(
"Chat") .
' ' . $value .
'" title="' .
dol_escape_htmltag($langs->trans(
"Chat") .
' ' . $value) .
'">';
4670 $htmllink .=
'<img class="paddingleft" src="' . DOL_URL_ROOT .
'/theme/common/skype_chatbutton.png" border="0">';
4671 $htmllink .=
'</a>';
4672 if (($contactid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
'agenda',
'myactions',
'create')) {
4673 $addlink =
'AC_SKYPE';
4676 $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>';
4678 $htmllink .= ($link ?
' ' . $link :
'');
4681 if (!empty($dictsocialnetworks[$type][
'url'])) {
4682 $tmpvirginurl = preg_replace(
'/\/?{socialid}/',
'', $dictsocialnetworks[$type][
'url']);
4683 if ($tmpvirginurl) {
4684 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl,
'/') .
'\/?/',
'', $value);
4685 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl,
'/') .
'\/?/',
'', $value);
4687 $tmpvirginurl3 = preg_replace(
'/^https:\/\//i',
'https://www.', $tmpvirginurl);
4688 if ($tmpvirginurl3) {
4689 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl3,
'/') .
'\/?/',
'', $value);
4690 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl3,
'/') .
'\/?/',
'', $value);
4693 $tmpvirginurl2 = preg_replace(
'/^https?:\/\//i',
'', $tmpvirginurl);
4694 if ($tmpvirginurl2) {
4695 $value = preg_replace(
'/^www\.' . preg_quote($tmpvirginurl2,
'/') .
'\/?/',
'', $value);
4696 $value = preg_replace(
'/^' . preg_quote($tmpvirginurl2,
'/') .
'\/?/',
'', $value);
4699 if (preg_match(
'/^https?:\/\//i', $value)) {
4702 $link = str_replace(
'{socialid}', $value, $dictsocialnetworks[$type][
'url']);
4704 $valuetoshow = $value;
4705 $valuetoshow = preg_replace(
'/https:\/\/www\.(twitter|x|linkedin)\.com\/?/',
'', $valuetoshow);
4706 if (preg_match(
'/^https?:\/\//i', $link)) {
4715 $htmllink .=
'</div>';
4717 $langs->load(
"errors");
4718 $htmllink .=
img_warning($langs->trans(
"ErrorBadSocialNetworkValue", $value));
4722 $parameters = array(
4724 'cid' => $contactid,
4727 'dictsocialnetworks' => $dictsocialnetworks,
4730 $reshook = $hookmanager->executeHooks(
'printSocialNetworks', $parameters);
4734 $htmllink .= $hookmanager->resPrint;
4749function dol_print_profids($profID, $profIDtype, $countrycode =
'', $addcpButton = 1)
4753 if (empty($profID) || empty($profIDtype)) {
4756 if (empty($countrycode)) {
4757 $countrycode =
$mysoc->country_code;
4759 $newProfID = $profID;
4760 $id = substr($profIDtype, -1);
4762 if (strtoupper($countrycode) ==
'FR') {
4768 $newProfID = substr($newProfID, 0, 3) .
' ' . substr($newProfID, 3, 3) .
' ' . substr($newProfID, 6, 3);
4772 $newProfID = substr($newProfID, 0, 3) .
' ' . substr($newProfID, 3, 3) .
' ' . substr($newProfID, 6, 3) .
' ' . substr($newProfID, 9, 5);
4776 $newProfID = substr($newProfID, 0, 2) .
'.' . substr($newProfID, 2, 3);
4778 if ($profIDtype ===
'VAT' &&
dol_strlen($newProfID) == 13) {
4780 $newProfID = substr($newProfID, 0, 4) .
' ' . substr($newProfID, 4, 3) .
' ' . substr($newProfID, 7, 3) .
' ' . substr($newProfID, 10, 3);
4783 if (!empty($addcpButton)) {
4806function dol_print_phone($phone, $countrycode =
'', $contactid = 0, $socid = 0, $addlink =
'', $separ =
" ", $withpicto =
'', $titlealt =
'', $adddivfloat = 0, $morecss =
'paddingright')
4808 global
$conf, $user, $langs,
$mysoc, $hookmanager;
4811 $phone = is_null($phone) ?
'' : preg_replace(
"/[\s.-]/",
"", trim($phone));
4812 if (empty($phone)) {
4818 if (empty($countrycode) && is_object(
$mysoc)) {
4819 $countrycode =
$mysoc->country_code;
4823 if (!empty(
$conf->dol_optimize_smallscreen) && $separ !=
'hidenum') {
4828 $newphonewa = $phone;
4829 if (strtoupper($countrycode) ==
"FR") {
4832 $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);
4834 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 2);
4836 $newphone = substr($newphone, 0, 2) . $separ . substr($newphone, 2, 3) . $separ . substr($newphone, 5, 2) . $separ . substr($newphone, 7, 2);
4838 $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);
4840 $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);
4842 $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);
4844 } elseif (strtoupper($countrycode) ==
"CA") {
4846 $newphone = ($separ !=
'' ?
'(' :
'') . substr($newphone, 0, 3) . ($separ !=
'' ?
')' :
'') . $separ . substr($newphone, 3, 3) . ($separ !=
'' ?
'-' :
'') . substr($newphone, 6, 4);
4848 } elseif (strtoupper($countrycode) ==
"PT") {
4850 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
4852 } elseif (strtoupper($countrycode) ==
"SR") {
4854 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3);
4856 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 4);
4858 } elseif (strtoupper($countrycode) ==
"DE") {
4860 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 4) . $separ . substr($newphone, 11, 3);
4862 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 4) . $separ . substr($newphone, 10, 3);
4864 } elseif (strtoupper($countrycode) ==
"ES") {
4866 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4868 } elseif (strtoupper($countrycode) ==
"BF") {
4870 $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);
4872 } elseif (strtoupper($countrycode) ==
"RO") {
4874 $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);
4876 } elseif (strtoupper($countrycode) ==
"TR") {
4878 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 4);
4880 } elseif (strtoupper($countrycode) ==
"US") {
4882 $newphone = substr($newphone, 0, 2) . $separ . substr($newphone, 2, 3) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 4);
4884 } elseif (strtoupper($countrycode) ==
"MX") {
4886 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 2);
4888 $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);
4890 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 4);
4892 } elseif (strtoupper($countrycode) ==
"ML") {
4894 $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);
4896 } elseif (strtoupper($countrycode) ==
"TH") {
4898 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 3);
4900 $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);
4902 } elseif (strtoupper($countrycode) ==
"MU") {
4905 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 2) . $separ . substr($newphone, 9, 2);
4907 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 4) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 2);
4909 } elseif (strtoupper($countrycode) ==
"ZA") {
4911 $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);
4913 } elseif (strtoupper($countrycode) ==
"SY") {
4915 $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);
4917 $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);
4919 } elseif (strtoupper($countrycode) ==
"AE") {
4921 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 2);
4923 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
4925 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 4);
4927 } elseif (strtoupper($countrycode) ==
"DZ") {
4929 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
4931 } elseif (strtoupper($countrycode) ==
"BE") {
4933 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 3);
4935 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4937 } elseif (strtoupper($countrycode) ==
"PF") {
4939 $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);
4941 } elseif (strtoupper($countrycode) ==
"CO") {
4943 $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);
4945 } elseif (strtoupper($countrycode) ==
"JO") {
4947 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 1) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 2) . $separ . substr($newphone, 10, 2);
4949 } elseif (strtoupper($countrycode) ==
"JM") {
4951 $newphone = substr($newphone, 0, 5) . $separ . substr($newphone, 5, 3) . $separ . substr($newphone, 8, 4);
4953 } elseif (strtoupper($countrycode) ==
"MG") {
4955 $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);
4957 } elseif (strtoupper($countrycode) ==
"GB") {
4959 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4) . $separ . substr($newphone, 7, 3) . $separ . substr($newphone, 10, 3);
4961 } elseif (strtoupper($countrycode) ==
"CH") {
4963 $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);
4965 $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);
4967 } elseif (strtoupper($countrycode) ==
"TN") {
4969 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4971 } elseif (strtoupper($countrycode) ==
"GF") {
4973 $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);
4975 } elseif (strtoupper($countrycode) ==
"GP") {
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) ==
"MQ") {
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) ==
"IT") {
4985 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
4987 $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);
4989 } elseif (strtoupper($countrycode) ==
"AU") {
4993 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 1) . $separ . substr($newphone, 4, 4) . $separ . substr($newphone, 8, 4);
4995 } elseif (strtoupper($countrycode) ==
"LU") {
4998 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 2) . $separ . substr($newphone, 6, 2) . $separ . substr($newphone, 8, 2);
5000 $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);
5002 $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);
5004 $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);
5006 } elseif (strtoupper($countrycode) ==
"PE") {
5009 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 4);
5011 $newphonewa =
'+51' . $newphone;
5012 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3);
5014 $newphone = substr($newphone, 0, 4) . $separ . substr($newphone, 4, 3) . $separ . substr($newphone, 7, 4);
5016 $newphonewa = $newphone;
5017 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 3) . $separ . substr($newphone, 6, 3) . $separ . substr($newphone, 9, 3);
5019 } elseif (strtoupper($countrycode) ==
"IN") {
5021 if ($withpicto ==
'phone') {
5022 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 2) . $separ . substr($newphone, 5, 4) . $separ . substr($newphone, 9, 4);
5024 $newphone = substr($newphone, 0, 3) . $separ . substr($newphone, 3, 5) . $separ . substr($newphone, 8, 5);
5029 $newphoneastart = $newphoneaend =
'';
5030 if (!empty($addlink)) {
5032 $newphoneastart =
'<a href="tel:' . urlencode($phone) .
'">';
5033 $newphoneaend .=
'</a>';
5034 } elseif (
isModEnabled(
'clicktodial') && $addlink ==
'AC_TEL') {
5035 if (empty($user->clicktodial_loaded)) {
5036 $user->fetch_clicktodial();
5040 $urlmask =
getDolGlobalString(
'CLICKTODIAL_URL',
'ErrorClickToDialModuleNotConfigured');
5041 if (!empty($user->clicktodial_url)) {
5042 $urlmask = $user->clicktodial_url;
5045 $clicktodial_poste = (!empty($user->clicktodial_poste) ? urlencode($user->clicktodial_poste) :
'');
5046 $clicktodial_login = (!empty($user->clicktodial_login) ? urlencode($user->clicktodial_login) :
'');
5047 $clicktodial_password = (!empty($user->clicktodial_password) ? urlencode($user->clicktodial_password) :
'');
5049 $url = sprintf($urlmask, urlencode($phone), $clicktodial_poste, $clicktodial_login, $clicktodial_password);
5051 $substitarray = array(
5052 '__PHONEFROM__' => $clicktodial_poste,
5053 '__PHONETO__' => urlencode($phone),
5054 '__LOGIN__' => $clicktodial_login,
5055 '__PASS__' => $clicktodial_password
5060 $newphoneastart =
'<a href="' . $url .
'" class="cssforclicktodial">';
5061 $newphoneaend =
'</a>';
5064 $newphoneastart =
'<a href="' . $url .
'"';
5066 $newphoneastart .=
' target="_blank" rel="noopener noreferrer"';
5068 $newphoneastart .=
'>';
5069 $newphoneaend .=
'</a>';
5074 if (
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
5076 $addlinktoagenda =
'';
5077 if ($addlink ==
'AC_FAX') {
5081 $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>';
5083 if ($addlinktoagenda) {
5084 $newphone =
'<span>' . $newphone .
' ' . $addlinktoagenda .
'</span>';
5089 if (
getDolGlobalString(
'CONTACT_PHONEMOBILE_SHOW_LINK_TO_WHATSAPP') && $withpicto ==
'mobile') {
5091 $newphone .=
' <a href="https://wa.me/' . $newphonewa .
'" target="_blank"';
5092 $newphone .=
'><span class="paddingright fab fa-whatsapp" style="color:#25D366;" title="WhatsApp"></span></a>';
5095 if (empty($titlealt)) {
5096 $titlealt = ($withpicto ==
'fax' ? $langs->trans(
"Fax") : $langs->trans(
"Phone"));
5101 $parameters = array(
'countrycode' => $countrycode,
'cid' => $contactid,
'socid' => $socid,
'titlealt' => $titlealt,
'picto' => $withpicto);
5102 $reshook = $hookmanager->executeHooks(
'printPhone', $parameters, $phone);
5103 $rep .= $hookmanager->resPrint;
5105 if (empty($reshook)) {
5108 if ($withpicto ==
'fax') {
5109 $picto =
'phoning_fax';
5110 } elseif ($withpicto ==
'phone') {
5112 } elseif ($withpicto ==
'mobile') {
5113 $picto =
'phoning_mobile';
5118 if ($adddivfloat == 1) {
5119 $rep .=
'<div class="nospan float' . ($morecss ?
' ' . $morecss :
'') .
'">';
5120 } elseif (empty($adddivfloat)) {
5121 $rep .=
'<span' . ($morecss ?
' class="' . $morecss .
'"' :
'') .
'>';
5124 $rep .= $newphoneastart;
5125 $rep .= ($withpicto ?
img_picto($titlealt, $picto) :
'');
5126 if ($separ !=
'hidenum') {
5127 $rep .= ($withpicto ?
' ' :
'') . $newphone;
5129 $rep .= $newphoneaend;
5131 if ($adddivfloat == 1) {
5133 } elseif (empty($adddivfloat)) {
5154 if (!isset(
$conf->cache[
'resolveips'])) {
5155 $conf->cache[
'resolveips'] = array();
5161 if (file_exists(DOL_DOCUMENT_ROOT .
'/theme/common/flags/' . $countrycode .
'.png')) {
5164 $ret .=
'(' . $countrycode .
')';
5172 if (in_array($mode, [0, 2])) {
5175 if (!array_key_exists($ip,
$conf->cache[
'resolveips'])) {
5176 $domain = gethostbyaddr($ip);
5177 $conf->cache[
'resolveips'][$ip] = $domain;
5179 $domain =
$conf->cache[
'resolveips'][$ip];
5207 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
5214 if (empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) || preg_match(
'/[^0-9\.\:,\[\]\s]/', $_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
5215 if (empty($_SERVER[
'HTTP_CLIENT_IP']) || preg_match(
'/[^0-9\.\:,\[\]\s]/', $_SERVER[
'HTTP_CLIENT_IP'])) {
5216 if (empty($_SERVER[
"HTTP_CF_CONNECTING_IP"])) {
5217 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
5219 $ip = $_SERVER[
"HTTP_CF_CONNECTING_IP"];
5222 $ip = preg_replace(
'/,.*$/',
'', $_SERVER[
'HTTP_CLIENT_IP']);
5225 $ip = preg_replace(
'/,.*$/',
'', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
5245 $datafile = $diroffile .
'/' .
getDolGlobalString(
'GEOIPMAXMIND_COUNTRY_DATAFILE_EMBEDDED');
5251 include_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeoip.class.php';
5252 $geoip =
new DolGeoIP(
'country', $datafile);
5254 $countrycode = $geoip->getCountryCodeFromIP($ip);
5261 return $countrycode;
5273 global
$conf, $langs, $user;
5282 include_once DOL_DOCUMENT_ROOT .
'/core/class/dolgeoip.class.php';
5283 $geoip =
new DolGeoIP(
'country', $datafile);
5284 $countrycode = $geoip->getCountryCodeFromIP($ip);
5285 $ret = $countrycode;
5304 global $hookmanager;
5310 $parameters = array(
'element' => $element,
'id' =>
$id);
5311 $reshook = $hookmanager->executeHooks(
'printAddress', $parameters, $address);
5312 $out .= $hookmanager->resPrint;
5314 if (empty($reshook)) {
5315 if (empty($charfornl)) {
5316 $out .= nl2br((
string) $address);
5318 $out .= preg_replace(
'/[\r\n]+/', $charfornl, (
string) $address);
5322 $showgmap = $showomap = 0;
5348 $url =
dol_buildpath(
'/google/gmaps.php?mode=' . $element .
'&id=' .
$id, 1);
5349 $out .=
' <a href="' . $url .
'" target="_gmaps"><img id="' . $htmlid .
'" class="valigntextbottom" src="' . DOL_URL_ROOT .
'/theme/common/gmap.png"></a>';
5352 $url =
dol_buildpath(
'/openstreetmap/maps.php?mode=' . $element .
'&id=' .
$id, 1);
5353 $out .=
' <a href="' . $url .
'" target="_gmaps"><img id="' . $htmlid .
'_openstreetmap" class="valigntextbottom" src="' . DOL_URL_ROOT .
'/theme/common/gmap.png"></a>';
5375function isValidEmail($address, $acceptsupervisorkey = 0, $acceptuserkey = 0)
5377 if ($acceptsupervisorkey && $address ==
'__SUPERVISOREMAIL__') {
5380 if ($acceptuserkey && $address ==
'__USER_EMAIL__') {
5383 if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
5401 if (function_exists(
'idn_to_ascii') && function_exists(
'checkdnsrr')) {
5402 if (!checkdnsrr(idn_to_ascii($domain),
'MX')) {
5405 if (function_exists(
'getmxrr')) {
5408 getmxrr(idn_to_ascii($domain), $mxhosts, $weight);
5409 if (count($mxhosts) > 1) {
5412 if (count($mxhosts) == 1 && !in_array((
string) $mxhosts[0], array(
'',
'.'))) {
5449 $tmparray = explode(
' ', $s);
5450 foreach ($tmparray as $tmps) {
5465function dol_strlen($string, $stringencoding =
'UTF-8')
5467 if (is_null($string)) {
5471 if (function_exists(
'mb_strlen')) {
5472 return mb_strlen($string, $stringencoding);
5474 return strlen($string);
5488function dol_substr($string, $start, $length =
null, $stringencoding =
'', $trunconbytes = 0)
5492 if (empty($stringencoding)) {
5493 $stringencoding = (empty($langs) ?
'UTF-8' : $langs->charset_output);
5497 if (empty($trunconbytes)) {
5498 if (function_exists(
'mb_substr')) {
5499 $ret = mb_substr($string, $start, $length, $stringencoding);
5501 $ret = substr($string, $start, $length);
5504 if (function_exists(
'mb_strcut')) {
5505 $ret = mb_strcut($string, $start, $length, $stringencoding);
5507 $ret = substr($string, $start, $length);
5527function dol_trunc($string, $size = 40, $trunc =
'right', $stringencoding =
'UTF-8', $nodot = 0, $display = 0)
5535 if (empty($stringencoding)) {
5536 $stringencoding =
'UTF-8';
5539 if (!empty(
$conf->dol_optimize_smallscreen) &&
$conf->dol_optimize_smallscreen == 1 && $display == 1) {
5540 $size = round($size / 3);
5544 if ($trunc ==
'right') {
5546 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
5548 return dol_substr($newstring, 0, $size, $stringencoding) . ($nodot ?
'' :
'…');
5553 } elseif ($trunc ==
'middle') {
5555 if (
dol_strlen($newstring, $stringencoding) > 2 &&
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
5556 $size1 = (int) round($size / 2);
5557 $size2 = (int) round($size / 2);
5558 return dol_substr($newstring, 0, $size1, $stringencoding) .
'…' .
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
5562 } elseif ($trunc ==
'left') {
5564 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
5566 return '…' .
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
5570 } elseif ($trunc ==
'wrap') {
5572 if (
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
5578 return 'BadParam3CallingDolTrunc';
5592 $type2picto = array(
5593 'varchar' =>
'font',
5596 'int' =>
'sort-numeric-down',
5597 'double' =>
'sort-numeric-down',
5598 'price' =>
'currency',
5599 'pricecy' =>
'multicurrency',
5600 'password' =>
'key',
5601 'boolean' =>
'check-square',
5602 'date' =>
'calendar',
5603 'datetime' =>
'calendar',
5604 'duration' =>
'hourglass',
5610 'sellist' =>
'list',
5611 'stars' =>
'fontawesome_star_fas',
5612 'radio' =>
'check-circle',
5613 'checkbox' =>
'list',
5614 'chkbxlst' =>
'list',
5616 'icon' =>
"question",
5617 'point' =>
"country",
5618 'multipts' =>
'country',
5619 'linestrg' =>
"country",
5620 'polygon' =>
"country",
5621 'separate' =>
'minus'
5624 if (!empty($type2picto[$key])) {
5625 return img_picto(
'', $type2picto[$key],
'class="pictofixedwidth' . ($morecss ?
' ' . $morecss :
'') .
'"');
5628 return img_picto(
'',
'generic',
'class="pictofixedwidth' . ($morecss ?
' ' . $morecss :
'') .
'"');
5655function img_picto($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $srconly = 0, $notitle = 0, $alt =
'', $morecss =
'', $marginleftonlyshort = 2, $allowothertags = array())
5660 $url = DOL_URL_ROOT;
5661 $theme = isset(
$conf->theme) ?
$conf->theme :
null;
5662 $path =
'theme/' . $theme;
5663 if (empty($picto)) {
5668 if ($pictoisfullpath) {
5670 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
5673 $fullpathpicto = $picto;
5675 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
5676 $morecss .= ($morecss ?
' ' :
'') . $reg[1];
5677 $moreatt = str_replace(
'class="' . $reg[1] .
'"',
'', $moreatt);
5682 $pictowithouttext = preg_replace(
'/(\.png|\.gif|\.svg)$/',
'', $picto);
5683 $pictowithouttext = str_replace(
'object_',
'', $pictowithouttext);
5684 $pictowithouttext = str_replace(
'_nocolor',
'', $pictowithouttext);
5687 $pictoconvertkey = array(
5688 'facture' =>
'bill',
5689 'shipping' =>
'shipment',
5690 'fichinter' =>
'intervention',
5691 'agenda' =>
'calendar',
5692 'invoice_supplier' =>
'supplier_invoice',
5693 'order_supplier' =>
'supplier_order');
5694 if (in_array($pictowithouttext, array_keys($pictoconvertkey))) {
5695 $pictowithouttext = $pictoconvertkey[$pictowithouttext];
5698 if (strpos($pictowithouttext,
'fontawesome_') === 0 || strpos($pictowithouttext,
'fa-') === 0) {
5700 $pictowithouttext = str_replace(
'fontawesome_',
'', $pictowithouttext);
5701 $pictowithouttext = str_replace(
'fa-',
'', $pictowithouttext);
5704 if ($pictowithouttext ==
'file-o') {
5705 $pictowithouttext =
'file';
5708 $pictowithouttextarray = explode(
'_', $pictowithouttext);
5709 $marginleftonlyshort = 0;
5711 if (!empty($pictowithouttextarray[1])) {
5713 $fakey =
'fa-' . $pictowithouttextarray[0];
5714 $faprefix = empty($pictowithouttextarray[1]) ?
'fas' : $pictowithouttextarray[1];
5715 $facolor = empty($pictowithouttextarray[2]) ?
'' : $pictowithouttextarray[2];
5716 $fasize = empty($pictowithouttextarray[3]) ?
'' : $pictowithouttextarray[3];
5718 $fakey =
'fa-' . $pictowithouttext;
5728 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
5729 $morecss .= ($morecss ?
' ' :
'') . $reg[1];
5730 $moreatt = str_replace(
'class="' . $reg[1] .
'"',
'', $moreatt);
5732 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
5733 $morestyle = $reg[1];
5734 $moreatt = str_replace(
'style="' . $reg[1] .
'"',
'', $moreatt);
5736 $moreatt = trim($moreatt);
5738 $enabledisablehtml =
'<span class="' . $faprefix .
' ' . $fakey . ($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
5739 $enabledisablehtml .= ($morecss ?
' ' . $morecss :
'') .
'" style="' . ($fasize ? (
'font-size: ' . $fasize .
';') :
'') . ($facolor ? (
' color: ' . $facolor .
';') :
'') . ($morestyle ?
' ' . $morestyle :
'') .
'"' . (($notitle || empty($titlealt)) ?
'' :
' title="' .
dol_escape_htmltag($titlealt) .
'"') . ($moreatt ?
' ' . $moreatt :
'') .
'>';
5740 $enabledisablehtml .=
'</span>';
5742 return $enabledisablehtml;
5745 if (empty($srconly) && !preg_match(
'/[\.\/@]/', $picto)) {
5746 $fakey = $pictowithouttext;
5750 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'))) {
5753 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'))) {
5759 if ($pictowithouttext ==
'off') {
5760 $fakey =
'fa-square';
5762 } elseif ($pictowithouttext ==
'on') {
5763 $fakey =
'fa-check-square';
5765 } elseif ($pictowithouttext ==
'listlight') {
5766 $fakey =
'fa-download';
5767 $marginleftonlyshort = 1;
5768 } elseif ($pictowithouttext ==
'printer') {
5769 $fakey =
'fa-print';
5771 } elseif ($pictowithouttext ==
'note') {
5772 $fakey =
'fa-sticky-note';
5773 $marginleftonlyshort = 1;
5774 } elseif (in_array($pictowithouttext, array(
'1uparrow',
'1downarrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected'))) {
5775 $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');
5776 $fakey =
'fa-' . $convertarray[$pictowithouttext];
5777 if (preg_match(
'/selected/', $pictowithouttext)) {
5780 $marginleftonlyshort = 1;
5781 } elseif (!empty($arrayconvpictotofa[$pictowithouttext])) {
5782 $fakey =
'fa-' . $arrayconvpictotofa[$pictowithouttext];
5784 $fakey =
'fa-' . $pictowithouttext;
5787 if (in_array($pictowithouttext, array(
'dollyrevert',
'member',
'members',
'contract',
'group',
'resource',
'shipment',
'reception'))) {
5788 $morecss .=
' em092';
5790 if (in_array($pictowithouttext, array(
'conferenceorbooth',
'eventorganization',
'holiday',
'info',
'info_black',
'project',
'workstation'))) {
5791 $morecss .=
' em088';
5793 if (in_array($pictowithouttext, array(
'asset',
'intervention',
'payment',
'loan',
'partnership',
'stock',
'technic'))) {
5794 $morecss .=
' em080';
5798 $arrayconvpictotomarginleftonly = array(
5828 '1uparrow_selected',
5829 '1downarrow_selected',
5830 '1leftarrow_selected',
5831 '1rightarrow_selected'
5833 if (!array_key_exists($pictowithouttext, $arrayconvpictotomarginleftonly)) {
5834 $marginleftonlyshort = 0;
5838 $arrayconvpictotomorcess = array(
5839 'action' =>
'infobox-action',
5840 'account' =>
'infobox-bank_account',
5841 'accounting_account' =>
'infobox-bank_account',
5842 'accountline' =>
'infobox-bank_account',
5843 'accountancy' =>
'infobox-bank_account',
5844 'admin' =>
'opacitymedium',
5845 'asset' =>
'infobox-bank_account',
5846 'bank_account' =>
'infobox-bank_account',
5847 'bill' =>
'infobox-commande',
5848 'billa' =>
'infobox-commande',
5849 'billr' =>
'infobox-commande',
5850 'billd' =>
'infobox-commande',
5851 'bookcal' =>
'infobox-portal',
5852 'margin' =>
'infobox-bank_account',
5853 'conferenceorbooth' =>
'infobox-project',
5854 'cash-register' =>
'infobox-portal',
5855 'contract' =>
'infobox-contrat',
5856 'check' =>
'font-status4',
5857 'conversation' =>
'infobox-contrat',
5858 'donation' =>
'infobox-commande',
5859 'dolly' =>
'infobox-commande',
5860 'dollyrevert' =>
'flip infobox-order_supplier',
5861 'ecm' =>
'infobox-action',
5862 'eventorganization' =>
'infobox-project',
5863 'hrm' =>
'infobox-adherent',
5864 'group' =>
'infobox-adherent',
5865 'intervention' =>
'infobox-contrat',
5866 'incoterm' =>
'infobox-supplier_proposal',
5867 'intracommreport' =>
'infobox-bank_account',
5868 'currency' =>
'infobox-bank_account',
5869 'multicurrency' =>
'infobox-bank_account',
5870 'members' =>
'infobox-adherent',
5871 'member' =>
'infobox-adherent',
5872 'money-bill-alt' =>
'infobox-bank_account',
5873 'order' =>
'infobox-commande',
5874 'user' =>
'infobox-adherent',
5875 'users' =>
'infobox-adherent',
5876 'error' =>
'pictoerror',
5877 'warning' =>
'pictowarning',
5878 'switch_on' =>
'font-status4',
5879 'switch_on_warning' =>
'font-status4 warning',
5880 'switch_on_red' =>
'font-status8',
5881 'switch_off_warning' =>
'font-status4 warning',
5882 'switch_off_red' =>
'font-status8',
5883 'holiday' =>
'infobox-holiday',
5884 'info' =>
'opacityhigh',
5885 'info_black' =>
'purple',
5886 'invoice' =>
'infobox-commande',
5887 'knowledgemanagement' =>
'infobox-contrat rotate90',
5888 'loan' =>
'infobox-commande',
5889 'payment' =>
'infobox-bank_account',
5890 'payment_vat' =>
'infobox-bank_account',
5891 'poll' =>
'infobox-portal',
5892 'pos' =>
'infobox-bank_account',
5893 'project' =>
'infobox-project',
5894 'projecttask' =>
'infobox-project',
5895 'propal' =>
'infobox-propal',
5896 'proposal' =>
'infobox-propal',
5897 'private' =>
'infobox-project',
5898 'reception' =>
'flip infobox-order_supplier',
5899 'recruitmentjobposition' =>
'infobox-adherent',
5900 'recruitmentcandidature' =>
'infobox-adherent',
5901 'resource' =>
'infobox-action',
5902 'salary' =>
'infobox-commande',
5903 'shapes' =>
'infobox-adherent',
5904 'shipment' =>
'infobox-commande',
5905 'store' =>
'infobox-portal',
5906 'stripe' =>
'infobox-bank_account',
5907 'supplier_invoice' =>
'infobox-order_supplier',
5908 'supplier_invoicea' =>
'infobox-order_supplier',
5909 'supplier_invoiced' =>
'infobox-order_supplier',
5910 'supplier_invoicer' =>
'infobox-order_supplier',
5911 'supplier' =>
'infobox-order_supplier',
5912 'supplier_order' =>
'infobox-order_supplier',
5913 'supplier_proposal' =>
'infobox-supplier_proposal',
5914 'ticket' =>
'infobox-contrat',
5915 'title_accountancy' =>
'infobox-bank_account',
5916 'title_hrm' =>
'infobox-holiday',
5917 'expensereport' =>
'infobox-expensereport',
5918 'trip' =>
'infobox-expensereport',
5919 'title_agenda' =>
'infobox-action',
5920 'vat' =>
'infobox-bank_account',
5921 'webportal' =>
'infobox-portal',
5922 'website' =>
'infobox-portal',
5924 'list-alt' =>
'imgforviewmode',
5925 'calendar' =>
'imgforviewmode',
5926 'calendarweek' =>
'imgforviewmode',
5927 'calendarmonth' =>
'imgforviewmode',
5928 'calendarday' =>
'imgforviewmode',
5929 'calendarperuser' =>
'imgforviewmode',
5930 'calendarpertype' =>
'imgforviewmode'
5932 if (!empty($arrayconvpictotomorcess[$pictowithouttext]) && strpos($picto,
'_nocolor') ===
false) {
5933 $morecss .= ($morecss ?
' ' :
'') . $arrayconvpictotomorcess[$pictowithouttext];
5937 $arrayconvpictotocolor = array(
5938 'address' =>
'#6c6aa8',
5939 'building' =>
'#6c6aa8',
5943 'companies' =>
'#6c6aa8',
5944 'company' =>
'#6c6aa8',
5945 'contact' =>
'#6c6aa8',
5947 'dynamicprice' =>
'#a69944',
5952 'listlight' =>
'#999',
5953 'language' =>
'#555',
5957 'map-marker-alt' =>
'#aaa',
5959 'product' =>
'#a69944',
5960 'service' =>
'#a69944',
5961 'inventory' =>
'#a69944',
5962 'stock' =>
'#a69944',
5963 'movement' =>
'#a69944',
5965 'world' =>
'#986c6a',
5966 'partnership' =>
'#6c6aa8',
5967 'playdisabled' =>
'#ccc',
5968 'printer' =>
'#444',
5969 'projectpub' =>
'#986c6a',
5973 'search-plus' =>
'#808080',
5974 'security' =>
'#999',
5976 'stop-circle' =>
'#888',
5978 'superadmin' =>
'#600',
5979 'switch_off' =>
'#999',
5980 'technic' =>
'#999',
5982 'timespent' =>
'#555',
5983 'uncheck' =>
'#800',
5984 'uparrow' =>
'#555',
5985 'user-cog' =>
'#999',
5986 'country' =>
'#aaa',
5987 'globe-americas' =>
'#aaa',
5991 'workstation' =>
'#a69944'
5993 if (isset($arrayconvpictotocolor[$pictowithouttext]) && strpos($picto,
'_nocolor') ===
false) {
5994 $facolor = $arrayconvpictotocolor[$pictowithouttext];
6001 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
6002 $morecss .= ($morecss ?
' ' :
'') . $reg[1];
6003 $moreatt = str_replace(
'class="' . $reg[1] .
'"',
'', $moreatt);
6005 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
6006 $morestyle = $reg[1];
6007 $moreatt = str_replace(
'style="' . $reg[1] .
'"',
'', $moreatt);
6009 $moreatt = trim($moreatt);
6011 $enabledisablehtml =
'<span class="' . $fa .
' ' . $fakey . ($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
6012 $enabledisablehtml .= ($morecss ?
' ' . $morecss :
'') .
'" style="' . ($fasize ? (
'font-size: ' . $fasize .
';') :
'') . ($facolor ? (
' color: ' . $facolor .
';') :
'') . ($morestyle ?
' ' . $morestyle :
'') .
'"' . (($notitle || empty($titlealt)) ?
'' :
' title="' .
dol_escape_htmltag($titlealt) .
'"') . ($moreatt ?
' ' . $moreatt :
'') .
'>';
6013 $enabledisablehtml .=
'</span>';
6015 return $enabledisablehtml;
6022 } elseif (!empty(
$conf->modules_parts[
'theme']) && array_key_exists($theme,
$conf->modules_parts[
'theme'])) {
6023 $path = $theme .
'/theme/' . $theme;
6028 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $picto, $regs)) {
6034 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
6039 foreach (
$conf->file->dol_document_root as $type => $dirroot) {
6040 if ($type ==
'main') {
6044 if (file_exists($dirroot .
'/' . $path .
'/img/' . $picto) && !empty(
$conf->file->dol_url_root)) {
6045 $url = DOL_URL_ROOT .
$conf->file->dol_url_root[$type];
6051 $fullpathpicto = $url .
'/' . $path .
'/img/' . $picto;
6055 return $fullpathpicto;
6059 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 :
'') .
'"') .
'>';
6073 if (empty($mode) || $mode ==
'fa') {
6075 $arrayconvpictotofa = array(
6076 'account' =>
'university',
6077 'accounting_account' =>
'clipboard-list',
6078 'accountline' =>
'receipt',
6079 'accountancy' =>
'search-dollar',
6080 'action' =>
'calendar-alt',
6081 'add' =>
'plus-circle',
6082 'address' =>
'address-book',
6085 'asset' =>
'money-check-alt',
6086 'autofill' =>
'fill',
6087 'back' =>
'arrow-left',
6088 'bank_account' =>
'university',
6089 'bill' =>
'file-invoice-dollar',
6090 'billa' =>
'file-excel',
6091 'billr' =>
'file-invoice-dollar',
6092 'billd' =>
'file-medical',
6093 'blockedlog' =>
'file-archive',
6094 'bookcal' =>
'calendar-check',
6095 'supplier_invoice' =>
'file-invoice-dollar',
6096 'supplier_invoicea' =>
'file-excel',
6097 'supplier_invoicer' =>
'file-invoice-dollar',
6098 'supplier_invoiced' =>
'file-medical',
6100 'card' =>
'address-card',
6101 'chart' =>
'chart-line',
6102 'company' =>
'building',
6103 'contact' =>
'address-book',
6104 'contract' =>
'suitcase',
6105 'collab' =>
'people-arrows',
6106 'conversation' =>
'comments',
6107 'country' =>
'globe-americas',
6108 'cron' =>
'business-time',
6110 'chevron-double-left' =>
'angle-double-left',
6111 'chevron-double-right' =>
'angle-double-right',
6112 'chevron-double-down' =>
'angle-double-down',
6113 'chevron-double-top' =>
'angle-double-up',
6114 'donation' =>
'gift',
6115 'dynamicprice' =>
'hand-holding-usd',
6117 'companies' =>
'building',
6118 'products' =>
'cube',
6119 'commercial' =>
'suitcase',
6120 'invoicing' =>
'coins',
6121 'accounting' =>
'search-dollar',
6122 'category' =>
'tag',
6123 'dollyrevert' =>
'dolly',
6125 'generate' =>
'plus-square',
6126 'hrm' =>
'user-tie',
6127 'incoterm' =>
'truck-loading',
6128 'margin' =>
'calculator',
6129 'members' =>
'user-friends',
6130 'ticket' =>
'ticket-alt',
6131 'globe' =>
'external-link-alt',
6134 'establishment' =>
'building',
6135 'edit' =>
'pencil-alt',
6136 'entity' =>
'globe',
6137 'graph' =>
'chart-line',
6138 'grip_title' =>
'arrows-alt',
6139 'grip' =>
'arrows-alt',
6140 'help' =>
'question-circle',
6141 'generic' =>
'file',
6142 'holiday' =>
'umbrella-beach',
6143 'info' =>
'info-circle',
6144 'info_black' =>
'info-circle',
6145 'inventory' =>
'boxes',
6146 'intracommreport' =>
'globe-europe',
6147 'jobprofile' =>
'cogs',
6148 'knowledgemanagement' =>
'ticket-alt',
6149 'label' =>
'layer-group',
6150 'layout' =>
'columns',
6152 'loan' =>
'money-bill-alt',
6153 'member' =>
'user-alt',
6154 'meeting' =>
'chalkboard-teacher',
6156 'next' =>
'arrow-alt-circle-right',
6158 'expensereport' =>
'wallet',
6160 'movement' =>
'people-carry',
6161 'sign-out' =>
'sign-out-alt',
6162 'superadmin' =>
'star',
6163 'switch_off' =>
'toggle-off',
6164 'switch_off_grey' =>
'toggle-off',
6165 'switch_off_warning' =>
'toggle-off',
6166 'switch_off_red' =>
'toggle-off',
6167 'switch_on' =>
'toggle-on',
6168 'switch_on_grey' =>
'toggle-on',
6169 'switch_on_warning' =>
'toggle-on',
6170 'switch_on_red' =>
'toggle-on',
6172 'bookmark' =>
'star',
6173 'bank' =>
'university',
6174 'close_title' =>
'times',
6175 'delete' =>
'trash',
6176 'filter' =>
'filter',
6177 'list-alt' =>
'list-alt',
6178 'calendarlist' =>
'bars',
6179 'calendar' =>
'calendar-alt',
6180 'calendarmonth' =>
'calendar-alt',
6181 'calendarweek' =>
'calendar-week',
6182 'calendarday' =>
'calendar-day',
6183 'calendarperuser' =>
'table',
6184 'calendarpertype' =>
'table',
6185 'intervention' =>
'ambulance',
6186 'invoice' =>
'file-invoice-dollar',
6187 'order' =>
'file-invoice',
6188 'error' =>
'exclamation-triangle',
6189 'warning' =>
'exclamation-triangle',
6190 'other' =>
'square',
6191 'playdisabled' =>
'play',
6192 'pdf' =>
'file-pdf',
6193 'poll' =>
'check-double',
6194 'pos' =>
'cash-register',
6195 'preview' =>
'binoculars',
6196 'project' =>
'project-diagram',
6197 'projectpub' =>
'project-diagram',
6198 'projecttask' =>
'tasks',
6199 'propal' =>
'file-signature',
6200 'proposal' =>
'file-signature',
6201 'partnership' =>
'handshake',
6202 'payment' =>
'money-check-alt',
6203 'payment_vat' =>
'money-check-alt',
6204 'pictoconfirm' =>
'check-square',
6205 'phoning' =>
'phone',
6206 'phoning_mobile' =>
'mobile-alt',
6207 'phoning_fax' =>
'fax',
6208 'previous' =>
'arrow-alt-circle-left',
6209 'printer' =>
'print',
6210 'product' =>
'cube',
6211 'puce' =>
'angle-right',
6212 'recent' =>
'check-square',
6213 'reception' =>
'dolly',
6214 'recruitmentjobposition' =>
'id-card-alt',
6215 'recruitmentcandidature' =>
'id-badge',
6217 'supplier_order' =>
'dol-order_supplier',
6218 'supplier_proposal' =>
'file-signature',
6219 'refresh' =>
'redo',
6220 'region' =>
'map-marked',
6221 'replacement' =>
'exchange-alt',
6222 'resource' =>
'laptop-house',
6223 'recurring' =>
'history',
6224 'service' =>
'concierge-bell',
6225 'skill' =>
'shapes',
6226 'state' =>
'map-marked-alt',
6227 'security' =>
'key',
6228 'salary' =>
'wallet',
6229 'shipment' =>
'dolly',
6230 'stock' =>
'box-open',
6231 'stats' =>
'chart-bar',
6232 'split' =>
'code-branch',
6233 'status' =>
'stop-circle',
6234 'stripe' =>
'stripe-s',
6235 'supplier' =>
'building',
6236 'technic' =>
'cogs',
6238 'timespent' =>
'clock',
6239 'title_setup' =>
'tools',
6240 'title_accountancy' =>
'money-check-alt',
6241 'title_bank' =>
'university',
6242 'title_hrm' =>
'umbrella-beach',
6243 'title_agenda' =>
'calendar-alt',
6244 'uncheck' =>
'times',
6245 'uparrow' =>
'share',
6246 'url' =>
'external-link-alt',
6247 'vat' =>
'money-check-alt',
6248 'vcard' =>
'arrow-alt-circle-down',
6249 'jabber' =>
'comment',
6250 'website' =>
'globe-americas',
6251 'workstation' =>
'pallet',
6252 'webhook' =>
'bullseye',
6254 'private' =>
'user-lock',
6255 'conferenceorbooth' =>
'chalkboard-teacher',
6256 'eventorganization' =>
'project-diagram',
6257 'webportal' =>
'door-open'
6260 if (
$conf->currency ==
'EUR') {
6261 $arrayconvpictotofa[
'currency'] =
'euro-sign';
6262 $arrayconvpictotofa[
'multicurrency'] =
'dollar-sign';
6264 $arrayconvpictotofa[
'currency'] =
'dollar-sign';
6265 $arrayconvpictotofa[
'multicurrency'] =
'euro-sign';
6268 $arrayconvpictotofa = array();
6271 return $arrayconvpictotofa;
6289function img_object($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $srconly = 0, $notitle = 0, $allowothertags = array())
6291 if (strpos($picto,
'^') === 0) {
6292 return img_picto($titlealt, str_replace(
'^',
'', $picto), $moreatt, $pictoisfullpath, $srconly, $notitle,
'',
'', 2, $allowothertags);
6294 return img_picto($titlealt,
'object_' . $picto, $moreatt, $pictoisfullpath, $srconly, $notitle,
'',
'', 2, $allowothertags);
6309function img_weather($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $morecss =
'')
6313 if (is_numeric($picto)) {
6316 return '<i class="fa fa-weather-level' . $picto .
'"></i>';
6317 } elseif (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
6321 $path = DOL_URL_ROOT .
'/theme/' .
$conf->theme .
'/img/weather/' . $picto;
6323 return img_picto($titlealt, $path, $moreatt, 1, 0, 0,
'', $morecss);
6337function img_picto_common($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $notitle = 0)
6341 if (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
6345 if ($pictoisfullpath) {
6348 $path = DOL_URL_ROOT .
'/theme/common/' . $picto;
6351 $themepath = DOL_DOCUMENT_ROOT .
'/theme/' .
$conf->theme .
'/img/' . $picto;
6353 if (file_exists($themepath)) {
6359 return img_picto($titlealt, $path, $moreatt, 1, 0, $notitle);
6375function img_action($titlealt, $numaction, $picto =
'', $moreatt =
'')
6379 if (empty($titlealt) || $titlealt ==
'default') {
6380 if ($numaction ==
'-1' || $numaction ==
'ST_NO') {
6382 $titlealt = $langs->transnoentitiesnoconv(
'ChangeDoNotContact');
6383 } elseif ($numaction ==
'0' || $numaction ==
'ST_NEVER') {
6385 $titlealt = $langs->transnoentitiesnoconv(
'ChangeNeverContacted');
6386 } elseif ($numaction ==
'1' || $numaction ==
'ST_TODO') {
6388 $titlealt = $langs->transnoentitiesnoconv(
'ChangeToContact');
6389 } elseif ($numaction ==
'2' || $numaction ==
'ST_PEND') {
6391 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactInProcess');
6392 } elseif ($numaction ==
'3' || $numaction ==
'ST_DONE') {
6394 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactDone');
6396 $titlealt = $langs->transnoentitiesnoconv(
'ChangeStatus ' . $numaction);
6400 if (!is_numeric($numaction)) {
6404 return img_picto($titlealt, (empty($picto) ?
'stcomm' . $numaction .
'.png' : $picto), $moreatt);
6414function img_edit_add($titlealt =
'default', $other =
'')
6418 if ($titlealt ==
'default') {
6419 $titlealt = $langs->trans(
'Add');
6422 return img_picto($titlealt,
'edit_add.png', $other);
6435 if ($titlealt ==
'default') {
6436 $titlealt = $langs->trans(
'Remove');
6439 return img_picto($titlealt,
'edit_remove.png', $other);
6450function img_edit($titlealt =
'default', $float = 0, $other =
'')
6454 if ($titlealt ==
'default') {
6455 $titlealt = $langs->trans(
'Modify');
6458 return img_picto($titlealt,
'edit', ($float ?
'style="float: ' . ($langs->tab_translate[
"DIRECTION"] ==
'rtl' ?
'left' :
'right') .
'"' :
"") . ($other ?
' ' . $other :
''));
6469function img_view($titlealt =
'default', $float = 0, $other =
'class="valignmiddle"')
6473 if ($titlealt ==
'default') {
6474 $titlealt = $langs->trans(
'View');
6477 $moreatt = ($float ?
'style="float: right" ' :
'') . $other;
6479 return img_picto($titlealt,
'eye', $moreatt);
6490function img_delete($titlealt =
'default', $other =
'class="pictodelete"', $morecss =
'')
6494 if ($titlealt ==
'default') {
6495 $titlealt = $langs->trans(
'Delete');
6498 return img_picto($titlealt,
'delete', $other, 0, 0, 0,
'', $morecss);
6508function img_printer($titlealt =
"default", $other =
'')
6511 if ($titlealt ==
"default") {
6512 $titlealt = $langs->trans(
"Print");
6514 return img_picto($titlealt,
'printer', $other);
6524function img_split($titlealt =
'default', $other =
'class="pictosplit"')
6528 if ($titlealt ==
'default') {
6529 $titlealt = $langs->trans(
'Split');
6532 return img_picto($titlealt,
'split', $other);
6542function img_help($usehelpcursor = 1, $usealttitle = 1)
6547 if (is_string($usealttitle)) {
6550 $usealttitle = $langs->trans(
'Info');
6554 return img_picto($usealttitle,
'info',
'style="vertical-align: middle;' . ($usehelpcursor == 1 ?
' cursor: help' : ($usehelpcursor == 2 ?
' cursor: pointer' :
'')) .
'"');
6563function img_info($titlealt =
'default')
6567 if ($titlealt ==
'default') {
6568 $titlealt = $langs->trans(
'Informations');
6571 return img_picto($titlealt,
'info',
'style="vertical-align: middle;"');
6582function img_warning($titlealt =
'default', $moreatt =
'', $morecss =
'pictowarning')
6586 if ($titlealt ==
'default') {
6587 $titlealt = $langs->trans(
'Warning');
6591 return img_picto($titlealt,
'warning',
'class="' . $morecss .
'"' . ($moreatt ? ($moreatt ==
'1' ?
' style="float: right"' :
' ' . $moreatt) :
''));
6600function img_error($titlealt =
'default')
6604 if ($titlealt ==
'default') {
6605 $titlealt = $langs->trans(
'Error');
6618function img_next($titlealt =
'default', $moreatt =
'')
6622 if ($titlealt ==
'default') {
6623 $titlealt = $langs->trans(
'Next');
6627 return '<span class="fa fa-chevron-right paddingright paddingleft" title="' .
dol_escape_htmltag($titlealt) .
'"></span>';
6637function img_previous($titlealt =
'default', $moreatt =
'')
6641 if ($titlealt ==
'default') {
6642 $titlealt = $langs->trans(
'Previous');
6646 return '<span class="fa fa-chevron-left paddingright paddingleft" title="' .
dol_escape_htmltag($titlealt) .
'"></span>';
6657function img_down($titlealt =
'default', $selected = 0, $moreclass =
'')
6661 if ($titlealt ==
'default') {
6662 $titlealt = $langs->trans(
'Down');
6665 return img_picto($titlealt, ($selected ?
'1downarrow_selected' :
'1downarrow'),
'class="imgdown' . ($moreclass ?
" " . $moreclass :
"") .
'"');
6676function img_up($titlealt =
'default', $selected = 0, $moreclass =
'')
6680 if ($titlealt ==
'default') {
6681 $titlealt = $langs->trans(
'Up');
6684 return img_picto($titlealt, ($selected ?
'1uparrow_selected' :
'1uparrow'),
'class="imgup' . ($moreclass ?
" " . $moreclass :
"") .
'"');
6695function img_left($titlealt =
'default', $selected = 0, $moreatt =
'')
6699 if ($titlealt ==
'default') {
6700 $titlealt = $langs->trans(
'Left');
6703 return img_picto($titlealt, ($selected ?
'1leftarrow_selected' :
'1leftarrow'), $moreatt);
6714function img_right($titlealt =
'default', $selected = 0, $moreatt =
'')
6718 if ($titlealt ==
'default') {
6719 $titlealt = $langs->trans(
'Right');
6722 return img_picto($titlealt, ($selected ?
'1rightarrow_selected' :
'1rightarrow'), $moreatt);
6732function img_allow($allow, $titlealt =
'default')
6736 if ($titlealt ==
'default') {
6737 $titlealt = $langs->trans(
'Active');
6754function img_credit_card($brand, $morecss =
'fa-2x inline-block valignmiddle')
6756 if (is_null($morecss)) {
6760 if ($brand ==
'visa' || $brand ==
'Visa') {
6762 } elseif ($brand ==
'mastercard' || $brand ==
'MasterCard') {
6763 $brand =
'cc-mastercard';
6764 } elseif ($brand ==
'amex' || $brand ==
'American Express') {
6766 } elseif ($brand ==
'discover' || $brand ==
'Discover') {
6767 $brand =
'cc-discover';
6768 } elseif ($brand ==
'jcb' || $brand ==
'JCB') {
6770 } elseif ($brand ==
'diners' || $brand ==
'Diners club') {
6771 $brand =
'cc-diners-club';
6772 } elseif (!in_array($brand, array(
'cc-visa',
'cc-mastercard',
'cc-amex',
'cc-discover',
'cc-jcb',
'cc-diners-club'))) {
6773 $brand =
'credit-card';
6776 return '<span class="fa fa-' . $brand .
' fa-fw' . ($morecss ?
' ' . $morecss :
'') .
'"></span>';
6787function img_mime($file, $titlealt =
'', $morecss =
'')
6789 require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
6795 if (empty($titlealt)) {
6796 $titlealt =
'Mime type: ' . $mimetype;
6800 return '<i class="fa fa-' . $mimefa .
' ' . (preg_match(
'/pictofixedwidth/', $morecss) ?
'' :
'paddingright ') . ($morecss ?
' ' . $morecss :
'') .
'"' . ($titlealt ?
' title="' .
dolPrintHTMLForAttribute($titlealt) .
'"' :
'') .
'></i>';
6811function img_search($titlealt =
'default', $other =
'')
6815 if ($titlealt ==
'default') {
6816 $titlealt = $langs->trans(
'Search');
6819 $img =
img_picto($titlealt,
'search', $other, 0, 1);
6821 $input =
'<input type="image" class="liste_titre" name="button_search" src="' . $img .
'" ';
6838 if ($titlealt ==
'default') {
6839 $titlealt = $langs->trans(
'Search');
6842 $img =
img_picto($titlealt,
'searchclear.png', $other, 0, 1);
6844 $input =
'<input type="image" class="liste_titre" name="button_removefilter" src="' . $img .
'" ';
6864function info_admin($text, $infoonimgalt = 0, $nodiv = 0, $admin =
'1', $morecss =
'hideonsmartphone', $textfordropdown =
'', $picto =
'', $textonpictotooltip =
'', $cssfordropdown =
'info_admin')
6866 global
$conf, $langs;
6868 if ($infoonimgalt) {
6869 $result =
img_picto($text,
'info',
'class="' . ($morecss ?
' ' . $morecss :
'') .
'"');
6871 if (empty(
$conf->use_javascript_ajax)) {
6872 $textfordropdown =
'';
6875 $class = (empty($admin) ?
'undefined' : ((
string) $admin ==
'1' ?
'info' : $admin));
6876 $fa =
'info-circle';
6877 if ($picto ==
'warning') {
6878 $fa =
'exclamation-triangle';
6880 $result = ($nodiv ?
'' :
'<div class="wordbreak ' . $class . ($cssfordropdown ?
' ' . $cssfordropdown :
'') . ($morecss ?
' ' . $morecss :
'') . ($textfordropdown ?
' hidden' :
'') .
'">');
6881 $result .=
img_picto(((
string) $admin ? $langs->trans(
'InfoAdmin') : $langs->trans(
'Note')).($textonpictotooltip ?
' : '.$textonpictotooltip :
''), $fa);
6884 $result .= ($nodiv ?
'' :
'</div>');
6886 if ($textfordropdown) {
6887 $tmpresult =
'<span class="' . $class .
' '. $cssfordropdown.
'text opacitymedium cursorpointer">' . $langs->trans($textfordropdown) .
' ' .
img_picto($langs->trans($textfordropdown),
'1downarrow') .
'</span>';
6888 $tmpresult .=
'<script nonce="' .
getNonce() .
'" type="text/javascript">
6889 jQuery(document).ready(function() {
6890 jQuery(".' . $cssfordropdown .
'text").click(function() {
6891 console.log("toggle text of .'.$cssfordropdown.
'");
6892 jQuery(".' . $cssfordropdown .
'").toggle().removeClass("hidden");
6897 $result = $tmpresult . $result;
6918 global
$conf, $langs, $user, $argv;
6919 global $dolibarr_main_prod;
6926 require_once DOL_DOCUMENT_ROOT .
'/core/class/translate.class.php';
6928 $langs->load(
"main");
6932 $langs->loadLangs(array(
'main',
'errors'));
6934 if ($_SERVER[
'DOCUMENT_ROOT']) {
6935 $out .= $langs->trans(
"DolibarrHasDetectedError") .
".<br>\n";
6937 $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";
6939 $out .= $langs->trans(
"InformationToHelpDiagnose") .
":<br>\n";
6941 $out .=
"<b>" . $langs->trans(
"Date") .
":</b> " .
dol_print_date(time(),
'dayhourlog') .
"<br>\n";
6942 $out .=
"<b>" . $langs->trans(
"Dolibarr") .
":</b> " . DOL_VERSION .
" - https://www.dolibarr.org<br>\n";
6943 if (isset(
$conf->global->MAIN_FEATURES_LEVEL)) {
6944 $out .=
"<b>" . $langs->trans(
"LevelOfFeature") .
":</b> " .
getDolGlobalInt(
'MAIN_FEATURES_LEVEL') .
"<br>\n";
6946 if ($user instanceof
User) {
6947 $out .=
"<b>" . $langs->trans(
"Login") .
":</b> " . $user->login .
"<br>\n";
6949 if (function_exists(
"phpversion")) {
6950 $out .=
"<b>" . $langs->trans(
"PHP") .
":</b> " . phpversion() .
"<br>\n";
6952 $out .=
"<b>" . $langs->trans(
"Server") .
":</b> " . (isset($_SERVER[
"SERVER_SOFTWARE"]) ?
dol_htmlentities($_SERVER[
"SERVER_SOFTWARE"], ENT_COMPAT) :
'') .
"<br>\n";
6953 if (function_exists(
"php_uname")) {
6954 $out .=
"<b>" . $langs->trans(
"OS") .
":</b> " . php_uname() .
"<br>\n";
6956 $out .=
"<b>" . $langs->trans(
"UserAgent") .
":</b> " . (isset($_SERVER[
"HTTP_USER_AGENT"]) ?
dol_htmlentities($_SERVER[
"HTTP_USER_AGENT"], ENT_COMPAT) :
'') .
"<br>\n";
6958 $out .=
"<b>" . $langs->trans(
"RequestedUrl") .
":</b> " . (isset($_SERVER[
"REQUEST_URI"]) ?
dol_htmlentities($_SERVER[
"REQUEST_URI"], ENT_COMPAT) :
'') .
"<br>\n";
6959 $out .=
"<b>" . $langs->trans(
"Referer") .
":</b> " . (isset($_SERVER[
"HTTP_REFERER"]) ?
dol_htmlentities($_SERVER[
"HTTP_REFERER"], ENT_COMPAT) :
'') .
"<br>\n";
6960 $out .=
"<b>" . $langs->trans(
"MenuManager") .
":</b> " . (isset(
$conf->standard_menu) ?
dol_htmlentities(
$conf->standard_menu, ENT_COMPAT) :
'') .
"<br>\n";
6962 $syslog .=
"url=" . (isset($_SERVER[
"REQUEST_URI"]) ?
dol_escape_htmltag($_SERVER[
"REQUEST_URI"]) :
'');
6963 $syslog .=
", query_string=" . (isset($_SERVER[
"QUERY_STRING"]) ?
dol_escape_htmltag($_SERVER[
"QUERY_STRING"]) :
'');
6965 $out .=
'> ' . $langs->transnoentities(
"ErrorInternalErrorDetected") .
":\n" . $argv[0] .
"\n";
6969 if (!empty(
$conf->modules)) {
6970 $out .=
"<b>" . $langs->trans(
"Modules") .
":</b> " . implode(
', ',
$conf->modules) .
"<br>\n";
6973 if (is_object(
$db)) {
6974 if ($_SERVER[
'DOCUMENT_ROOT']) {
6975 $out .=
"<b>" . $langs->trans(
"DatabaseTypeManager") .
":</b> " .
$db->type .
"<br>\n";
6976 $lastqueryerror =
$db->lastqueryerror();
6978 $lastqueryerror =
"SQL error string is not a valid UTF8 string. We can't show it.";
6980 $out .=
"<b>" . $langs->trans(
"RequestLastAccessInError") .
":</b> " . ($lastqueryerror ?
dol_escape_htmltag($lastqueryerror) : $langs->trans(
"ErrorNoRequestInError")) .
"<br>\n";
6981 $out .=
"<b>" . $langs->trans(
"ReturnCodeLastAccessInError") .
":</b> " . (
$db->lasterrno() ?
dol_escape_htmltag(
$db->lasterrno()) : $langs->trans(
"ErrorNoRequestInError")) .
"<br>\n";
6982 $out .=
"<b>" . $langs->trans(
"InformationLastAccessInError") .
":</b> " . (
$db->lasterror() ?
dol_escape_htmltag(
$db->lasterror()) : $langs->trans(
"ErrorNoRequestInError")) .
"<br>\n";
6986 $out .=
'> ' . $langs->transnoentities(
"DatabaseTypeManager") .
":\n" .
$db->type .
"\n";
6987 $out .=
'> ' . $langs->transnoentities(
"RequestLastAccessInError") .
":\n" . (
$db->lastqueryerror() ?
$db->lastqueryerror() : $langs->transnoentities(
"ErrorNoRequestInError")) .
"\n";
6988 $out .=
'> ' . $langs->transnoentities(
"ReturnCodeLastAccessInError") .
":\n" . (
$db->lasterrno() ?
$db->lasterrno() : $langs->transnoentities(
"ErrorNoRequestInError")) .
"\n";
6989 $out .=
'> ' . $langs->transnoentities(
"InformationLastAccessInError") .
":\n" . (
$db->lasterror() ?
$db->lasterror() : $langs->transnoentities(
"ErrorNoRequestInError")) .
"\n";
6991 $syslog .=
", sql=" .
$db->lastquery();
6992 $syslog .=
", db_error=" .
$db->lasterror();
6995 if ($error || $errors) {
6997 if (is_array($error) && is_array($errors)) {
6998 $errors = array_merge($error, $errors);
6999 } elseif (is_array($error)) {
7001 } elseif (is_array($errors) && !empty($error)) {
7002 $errors = array_merge(array($error), $errors);
7003 } elseif (!empty($error)) {
7004 $errors = array_merge(array($error), array($errors));
7007 $langs->load(
"errors");
7009 foreach ($errors as $msg) {
7013 if ($_SERVER[
'DOCUMENT_ROOT']) {
7014 $out .=
"<b>" . $langs->trans(
"Message") .
":</b> " .
dol_escape_htmltag($msg) .
"<br>\n";
7016 $out .=
'> ' . $langs->transnoentities(
"Message") .
":\n" . $msg .
"\n";
7018 $syslog .=
", msg=" . $msg;
7021 if (empty($dolibarr_main_prod) && $_SERVER[
'DOCUMENT_ROOT'] && function_exists(
'xdebug_print_function_stack') && function_exists(
'xdebug_call_file')) {
7022 xdebug_print_function_stack();
7023 $out .=
'<b>XDebug information:</b>' .
"<br>\n";
7024 $out .=
'File: ' . xdebug_call_file() .
"<br>\n";
7025 $out .=
'Line: ' . xdebug_call_line() .
"<br>\n";
7026 $out .=
'Function: ' . xdebug_call_function() .
"<br>\n";
7031 if (!headers_sent()) {
7032 if (function_exists(
'top_httphead')) {
7036 http_response_code(202);
7039 if (empty($dolibarr_main_prod)) {
7042 if (empty($langs->defaultlang)) {
7043 $langs->setDefaultLang();
7045 $langs->loadLangs(array(
"main",
"errors"));
7047 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";
7048 print $langs->trans(
"DolibarrHasDetectedError") .
'. ';
7049 print $langs->trans(
"YouCanSetOptionDolibarrMainProdToZero");
7050 if (!defined(
"MAIN_CORE_ERROR")) {
7051 define(
"MAIN_CORE_ERROR", 1);
7068function dol_print_error_email($prefixcode, $errormessage =
'', $errormessages = array(), $morecss =
'error', $email =
'')
7072 if (empty($email)) {
7076 $langs->load(
"errors");
7079 print
'<br><div class="center login_main_message"><div class="' . $morecss .
'">';
7080 print $langs->trans(
"ErrorContactEMail", $email, $prefixcode .
'-' .
dol_print_date($now,
'%Y%m%d%H%M%S'));
7081 if ($errormessage) {
7082 print
'<br><br>' . $errormessage;
7084 if (is_array($errormessages) && count($errormessages)) {
7085 foreach ($errormessages as $mesgtoshow) {
7086 print
'<br><br>' . $mesgtoshow;
7089 print
'</div></div>';
7108function print_liste_field_titre($name, $file =
"", $field =
"", $begin =
"", $param =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $tooltip =
"", $forcenowrapcolumntitle = 0)
7110 print
getTitleFieldOfList($name, 0, $file, $field, $begin, $param, $moreattrib, $sortfield, $sortorder, $prefix, 0, $tooltip, $forcenowrapcolumntitle);
7131function getTitleFieldOfList($name, $thead = 0, $file =
"", $field =
"", $begin =
"", $moreparam =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $disablesortlink = 0, $tooltip =
'', $forcenowrapcolumntitle = 0)
7133 global $langs, $form;
7136 if ($moreattrib ==
'class="right"') {
7137 $prefix .=
'right ';
7140 $tooltip = (
string) $tooltip;
7142 $sortorder = strtoupper((
string) $sortorder);
7151 $tmpsortfield = explode(
',', (
string) $sortfield);
7152 $sortfield1 = trim($tmpsortfield[0]);
7153 $tmpfield = explode(
',', $field);
7154 $field1 = trim($tmpfield[0]);
7156 if (strpos((
string) $tooltip,
':') !==
false) {
7157 $tmptooltip = explode(
':', (
string) $tooltip);
7159 $tmptooltip = array($tooltip);
7162 $wrapcolumntitle = (empty($forcenowrapcolumntitle) || (!empty($tmptooltip[2]) && $tmptooltip[2] ==
'-1'));
7164 if (!
getDolGlobalString(
'MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE') && $wrapcolumntitle) {
7165 $prefix =
'wrapcolumntitle ' . $prefix;
7171 $liste_titre =
'liste_titre';
7172 if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace(
"/^[^\.]+\./",
"", $field1))) {
7173 $liste_titre =
'liste_titre_sel';
7176 $tagstart =
'<' . $tag .
' class="' . $prefix . $liste_titre .
'" ' . $moreattrib;
7181 if (empty($thead) && $field && empty($disablesortlink)) {
7182 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
7183 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
7184 $options = preg_replace(
'/&+/i',
'&', $options);
7185 if (!preg_match(
'/^&/', $options)) {
7186 $options =
'&' . $options;
7189 $sortordertouseinlink =
'';
7190 if ($field1 != $sortfield1) {
7191 if (preg_match(
'/^DESC/i', $sortorder)) {
7192 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
7194 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
7197 if (preg_match(
'/^ASC/i', $sortorder)) {
7198 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
7200 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
7203 $sortordertouseinlink = preg_replace(
'/,$/',
'', $sortordertouseinlink);
7204 $out .=
'<a class="reposition" href="' .
dolBuildUrl($file, [
'sortfield' => $field,
'sortorder' => $sortordertouseinlink,
'begin' => $begin]) . $options .
'"';
7208 if ($tooltip && $tmptooltip[0]) {
7210 $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]));
7212 $out .= $langs->trans((
string) $name);
7215 if (empty($thead) && $field && empty($disablesortlink)) {
7219 if (empty($thead) && $field) {
7220 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
7221 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
7222 $options = preg_replace(
'/&+/i',
'&', $options);
7223 if (!preg_match(
'/^&/', $options)) {
7224 $options =
'&' . $options;
7227 if (!$sortorder || ($field1 != $sortfield1)) {
7230 if (preg_match(
'/^DESC/', $sortorder)) {
7231 $sortimg .=
'<span class="nowrap">' .
img_up(
"Z-A", 0,
'paddingright') .
'</span>';
7233 if (preg_match(
'/^ASC/', $sortorder)) {
7234 $sortimg .=
'<span class="nowrap">' .
img_down(
"A-Z", 0,
'paddingright') .
'</span>';
7239 $tagend =
'</' . $tag .
'>';
7241 $out = $tagstart . $sortimg . $out . $tagend;
7256 dol_syslog(__FUNCTION__ .
" is deprecated", LOG_WARNING);
7258 print
'<div class="titre">' . $title .
'</div>';
7272function print_fiche_titre($title, $mesg =
'', $picto =
'generic', $pictoisfullpath = 0,
$id =
'')
7291function load_fiche_titre($title, $morehtmlright =
'', $picto =
'generic', $pictoisfullpath = 0,
$id =
'', $morecssontable =
'', $morehtmlcenter =
'', $morecssonpicto =
'widthpictotitle')
7295 if ($picto ==
'setup') {
7300 $return .=
'<table ' . (
$id ?
'id="' .
$id .
'" ' :
'') .
'class="centpercent notopnoleftnoright table-fiche-title' . ($morecssontable ?
' ' . $morecssontable :
'') .
'">';
7301 $return .=
'<tr class="toptitle">';
7303 $return .=
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">' .
img_picto(
'', $picto,
'class="valignmiddle pictotitle'.($morecssonpicto ?
' '.$morecssonpicto :
'').
'"', $pictoisfullpath) .
'</td>';
7305 $return .=
'<td class="nobordernopadding valignmiddle col-title">';
7306 $return .=
'<div class="titre inline-block">';
7307 $return .=
'<span class="inline-block valignmiddle print-barre-liste">' . $title .
'</span>';
7308 $return .=
'</div>';
7311 $return .=
'<td class="nobordernopadding center valignmiddle col-center">' . $morehtmlcenter .
'</td>';
7314 $return .=
'<td class="nobordernopadding titre_right wordbreakimp right valignmiddle col-right">' . $morehtmlright .
'</td>';
7316 $return .=
'</tr></table>' .
"\n";
7344function 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 =
'')
7346 global
$conf, $langs;
7349 $savtotalnboflines = $totalnboflines;
7350 if (is_numeric($totalnboflines)) {
7351 $totalnboflines = abs($totalnboflines);
7356 $tmparray = preg_split(
'/<br>/i', $title, 2);
7357 if (!empty($tmparray[1])) {
7358 $title = $tmparray[0];
7359 $subtitle = $tmparray[1];
7362 $page = (int) $page;
7364 if ($picto ==
'setup') {
7365 $picto =
'title_setup';
7367 if ((
$conf->browser->name ==
'ie') && $picto ==
'generic') {
7368 $picto =
'title.gif';
7371 $limit =
$conf->liste_limit;
7374 if ($savlimit != 0 && (($num > $limit) || ($num == -1) || ($limit == 0))) {
7382 print
"<!-- Begin print_barre_liste -->\n";
7383 print
'<table class="centpercent notopnoleftnoright table-fiche-title' . ($morecss ?
' ' . $morecss :
'') .
'">';
7384 print
'<tr class="toptitle">';
7388 if ($picto && $title) {
7389 print
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">';
7390 print
img_picto(
'', $picto,
'class="valignmiddle pictotitle widthpictotitle"', $pictoisfullpath);
7394 print
'<td class="nobordernopadding valignmiddle col-title">';
7395 print
'<div class="titre inline-block nowrap">';
7396 print
'<span class="inline-block valignmiddle print-barre-liste">' . $title .
'</span>';
7397 if (!empty($title) && $savtotalnboflines >= 0 && (
string) $savtotalnboflines !=
'') {
7398 if (is_numeric($totalnboflines) && (
int) $totalnboflines > 0) {
7399 print
'<span class="opacitymedium colorblack marginleftonly totalnboflines valignmiddle" title="' . $langs->trans(
"NbRecordQualified") .
'">(' . $totalnboflines .
')</span>';
7401 print
'<span class="opacitymedium colorblack marginleftonly totalnboflines valignmiddle">(' . $totalnboflines .
')</span>';
7405 if (!empty($subtitle)) {
7406 print
'<br><div class="subtitle inline-block hideonsmartphone">' . $subtitle .
'</div>';
7411 if ($morehtmlcenter && empty(
$conf->dol_optimize_smallscreen)) {
7412 print
'<td class="nobordernopadding center valignmiddle col-center">' . $morehtmlcenter .
'</td>';
7416 print
'<td class="nobordernopadding valignmiddle right col-right">';
7417 print
'<input type="hidden" name="pageplusoneold" value="' . ((int) $page + 1) .
'">';
7419 parse_str($options, $query);
7421 $query += [
'sortfield' => $sortfield];
7424 $query += [
'sortorder' => $sortorder];
7427 $options =
'&' . http_build_query($query);
7429 $query = array_merge($query, [
'page' => $page]);
7433 if ($savlimit != 0 && ($page > 0 || $num > $limit)) {
7434 if ($totalnboflines) {
7436 $maxnbofpage = (empty(
$conf->dol_optimize_smallscreen) ? 4 : 0);
7439 $nbpages = ceil($totalnboflines / $limit);
7443 $cpt = ($page - $maxnbofpage);
7449 if (empty($pagenavastextinput)) {
7451 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">1</a></li>';
7453 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
7454 } elseif ($cpt == 2) {
7456 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">2</a></li>';
7462 if ($pagenavastextinput) {
7463 if ($cpt == $page) {
7464 $pagelist .=
'<li class="pagination pageplusone valignmiddle"><input type="text" class="' . ($totalnboflines > 100 ?
'width40' :
'width25') .
' center pageplusone heightofcombo" name="pageplusone" value="' . ($page + 1) .
'"></li>';
7468 if ($cpt == $page) {
7469 $pagelist .=
'<li class="pagination"><span class="active">' . ($page + 1) .
'</span></li>';
7471 $query[
'page'] = $cpt;
7472 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">' . ($cpt + 1) .
'</a></li>';
7476 }
while ($cpt < $nbpages && $cpt <= ($page + $maxnbofpage));
7478 if (empty($pagenavastextinput)) {
7479 if ($cpt < $nbpages) {
7480 if ($cpt < $nbpages - 2) {
7481 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
7482 } elseif ($cpt == $nbpages - 2) {
7483 $query[
'page'] = ($nbpages - 2);
7484 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">' . ($nbpages - 1) .
'</a></li>';
7486 $query[
'page'] = ($nbpages - 1);
7487 $pagelist .=
'<li class="pagination"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">' . $nbpages .
'</a></li>';
7490 $query[
'page'] = ($nbpages - 1);
7491 $pagelist .=
'<li class="pagination paginationlastpage"><a class="reposition" href="' .
dolBuildUrl($file, $query) .
'">' . $nbpages .
'</a></li>';
7494 $pagelist .=
'<li class="pagination"><span class="active">' . ($page + 1) .
"</li>";
7498 if ($savlimit || $morehtmlright || $morehtmlrightbeforearrow) {
7500 print_fleche_navigation($page, $file, $options, $nextpage, $pagelist, $morehtmlright, $savlimit, $totalnboflines, $selectlimitsuffix, $morehtmlrightbeforearrow, $hidenavigation);
7504 if ($pagenavastextinput) {
7514 if ($morehtmlcenter && !empty(
$conf->dol_optimize_smallscreen)) {
7515 print
'<div class="nobordernopadding marginbottomonly center valignmiddle col-center centpercent">' . $morehtmlcenter .
'</div>';
7518 print
"<!-- End title -->\n\n";
7537function print_fleche_navigation($page, $file, $options =
'', $nextpage = 0, $betweenarrows =
'', $afterarrows =
'', $limit = -1, $totalnboflines = 0, $selectlimitsuffix =
'', $beforearrows =
'', $hidenavigation = 0)
7539 global
$conf, $langs;
7541 print
'<div class="pagination"><ul>';
7542 if ($beforearrows) {
7543 print
'<li class="paginationbeforearrows">';
7544 print $beforearrows;
7548 if (empty($hidenavigation)) {
7549 if ((
int) $limit > 0 && (empty($selectlimitsuffix) || !is_numeric($selectlimitsuffix))) {
7550 $pagesizechoices =
'10:10,15:15,20:20,25:25,50:50,100:100,250:250,500:500,1000:1000';
7551 $pagesizechoices .=
',5000:5000';
7561 print
'<li class="pagination">';
7562 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 .
'">';
7563 print
'<datalist id="limitlist">';
7565 print
'<li class="paginationcombolimit valignmiddle">';
7566 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")) .
'">';
7568 $tmpchoice = explode(
',', $pagesizechoices);
7569 $tmpkey = $limit .
':' . $limit;
7570 if (!in_array($tmpkey, $tmpchoice)) {
7571 $tmpchoice[$tmpkey] = $tmpkey;
7573 $tmpkey =
$conf->liste_limit .
':' .
$conf->liste_limit;
7574 if (!in_array($tmpkey, $tmpchoice)) {
7575 $tmpchoice[$tmpkey] = $tmpkey;
7577 asort($tmpchoice, SORT_NUMERIC);
7578 foreach ($tmpchoice as $val) {
7580 $tmp = explode(
':', $val);
7583 if ($key !=
'' && $val !=
'') {
7584 if ((
int) $key == (
int) $limit) {
7585 $selected =
' selected="selected"';
7587 print
'<option name="' . $key .
'"' . $selected .
'>' .
dol_escape_htmltag($val) .
'</option>' .
"\n";
7591 print
'</datalist>';
7594 print
ajax_combobox(
"limit" . (is_numeric($selectlimitsuffix) ?
'' : $selectlimitsuffix), array(), 0, 0,
'resolve',
'-1',
'limit');
7598 if (
$conf->use_javascript_ajax) {
7599 print
'<!-- JS CODE TO ENABLE select limit to launch submit of page -->
7601 jQuery(document).ready(function () {
7602 jQuery(".selectlimit").change(function() {
7603 console.log("We change limit so we submit the form");
7604 $(this).parents(\'form:first\').submit();
7613 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>';
7615 if ($betweenarrows) {
7616 print
'<!--<div class="betweenarrows nowraponall inline-block">-->';
7617 print $betweenarrows;
7618 print
'<!--</div>-->';
7620 if ($nextpage > 0) {
7621 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>';
7624 print
'<li class="paginationafterarrows">';
7629 print
'</ul></div>' .
"\n";
7644function vatrate($rate, $addpercent =
false, $info_bits = 0, $usestarfornpr = 0, $html = 0)
7648 if (preg_match(
'/%/', $rate)) {
7649 $rate = str_replace(
'%',
'', $rate);
7653 if (preg_match(
'/\((.*)\)/', $rate, $reg)) {
7654 $morelabel =
' (' . $reg[1] .
')';
7655 $rate = preg_replace(
'/\s*' . preg_quote($morelabel,
'/') .
'/',
'', $rate);
7656 $morelabel =
' ' . ($html ?
'<span class="opacitymedium small">' :
'') .
'(' . $reg[1] .
')' . ($html ?
'</span>' :
'');
7658 if (preg_match(
'/\*/', $rate)) {
7659 $rate = str_replace(
'*',
'', $rate);
7664 if (!preg_match(
'/\//', $rate)) {
7665 $ret =
price($rate, 0,
'', 0, 0) . ($addpercent ?
'%' :
'');
7668 $ret = $rate . ($addpercent ?
'%' :
'');
7670 if (($info_bits & 1) && $usestarfornpr >= 0) {
7692function price($amount, $form = 0, $outlangs =
'', $trunc = 1, $rounding = -1, $forcerounding = -1, $currency_code =
'')
7694 global $langs,
$conf;
7697 if (empty($amount)) {
7700 $amount = (is_numeric($amount) ? $amount : 0);
7701 if ($rounding == -1) {
7704 $nbdecimal = $rounding;
7706 if ($outlangs ===
'none') {
7716 if (!($outlangs instanceof
Translate)) {
7720 if ($outlangs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
7721 $dec = $outlangs->transnoentitiesnoconv(
"SeparatorDecimal");
7723 if ($outlangs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
7724 $thousand = $outlangs->transnoentitiesnoconv(
"SeparatorThousand");
7726 if ($thousand ==
'None') {
7728 } elseif ($thousand ==
'Space') {
7735 $amount = str_replace(
',',
'.', $amount);
7737 $data = explode(
'.', $amount);
7738 $decpart = isset($data[1]) ? $data[1] :
'';
7739 $decpart = preg_replace(
'/0+$/i',
'', $decpart);
7749 $nbdecimalmaxshown = (int) str_replace(
'...',
'',
getDolGlobalString(
'MAIN_MAX_DECIMALS_SHOWN'));
7750 if ($trunc && $nbdecimal > $nbdecimalmaxshown) {
7751 $nbdecimal = $nbdecimalmaxshown;
7759 if ((
string) $forcerounding !=
'-1' && (
string) $forcerounding !=
'') {
7760 if ($forcerounding ===
'MU') {
7762 } elseif ($forcerounding ===
'MT') {
7764 } elseif ($forcerounding >= 0) {
7765 $nbdecimal = (int) $forcerounding;
7770 $output = number_format((
float) $amount, $nbdecimal, $dec, $thousand);
7772 $cursymbolbefore = $cursymbolafter =
'';
7773 if ($currency_code && is_object($outlangs)) {
7774 if ($currency_code ==
'auto') {
7775 $currency_code =
$conf->currency;
7778 $listofcurrenciesbefore = array(
'AUD',
'CAD',
'CNY',
'COP',
'CLP',
'GBP',
'HKD',
'MXN',
'PEN',
'USD',
'CRC',
'ZAR');
7779 $listoflanguagesbefore = array(
'nl_NL');
7780 if (in_array($currency_code, $listofcurrenciesbefore) || in_array($outlangs->defaultlang, $listoflanguagesbefore)) {
7781 $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
7783 $tmpcur = $outlangs->getCurrencySymbol($currency_code);
7784 $cursymbolafter .= ($tmpcur == $currency_code ?
' ' . $tmpcur : $tmpcur);
7788 $output = preg_replace(
'/\s/',
' ', $output);
7789 $output = $cursymbolbefore . $output . $end . ($cursymbolafter ?
' <span class="small">'.$cursymbolafter.
'</span>' :
'');
7790 $output = preg_replace(
'/\'/',
''', $output);
7792 $output = $cursymbolbefore . $output . $end . ($cursymbolafter ?
' '.$cursymbolafter :
'');
7823function price2num($amount, $rounding =
'', $option = 0)
7828 if (is_null($amount)) {
7837 if (is_null($langs)) {
7841 if ($langs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
7842 $dec = $langs->transnoentitiesnoconv(
"SeparatorDecimal");
7844 if ($langs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
7845 $thousand = $langs->transnoentitiesnoconv(
"SeparatorThousand");
7848 if ($thousand ==
'None') {
7850 } elseif ($thousand ==
'Space') {
7858 if (!is_numeric($amount)) {
7859 $amount = preg_replace(
'/[a-zA-Z\/\\\*\(\)<>\_]/',
'', $amount);
7862 if ($option == 2 && $thousand ==
'.' && preg_match(
'/\.(\d\d\d)$/', (
string) $amount)) {
7863 $amount = str_replace($thousand,
'', $amount);
7869 if (is_numeric($amount)) {
7871 $temps = sprintf(
"%10.10F", $amount - intval($amount));
7872 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
7874 $amount = number_format($amount, $nbofdec, $dec, $thousand);
7880 if ($thousand !=
',' && $thousand !=
'.') {
7893 if (preg_match(
'/^(?<int>[^,]*,|[^.]*\.)(?<dec>[^.,]*)$/u', $amount, $matches)) {
7894 $intPart = $matches[
'int'];
7895 $decPart = $matches[
'dec'];
7898 $intPart = str_replace([
'.',
','],
'', $intPart);
7901 $amount = $intPart . $dec . $decPart;
7905 $amount = str_replace(
' ',
'', $amount);
7906 $amount = str_replace($thousand,
'', $amount);
7907 $amount = str_replace($dec,
'.', $amount);
7909 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
7915 $nbofdectoround =
'';
7916 if ($rounding ==
'MU') {
7918 } elseif ($rounding ==
'MT') {
7920 } elseif ($rounding ==
'MS') {
7922 } elseif ($rounding ==
'CU') {
7924 } elseif ($rounding ==
'CT') {
7926 } elseif (is_numeric($rounding)) {
7927 $nbofdectoround = (int) $rounding;
7932 $amount = round(is_string($amount) ? (
float) $amount : $amount, $nbofdectoround);
7934 return 'ErrorBadParameterProvidedToFunction';
7940 if (is_numeric($amount)) {
7942 $temps = sprintf(
"%10.10F", $amount - intval($amount));
7943 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
7945 $amount = number_format($amount, min($nbofdec, $nbofdectoround), $dec, $thousand);
7951 if ($thousand !=
',' && $thousand !=
'.') {
7952 $amount = str_replace(
',',
'.', $amount);
7955 $amount = str_replace(
' ',
'', $amount);
7956 $amount = str_replace($thousand,
'', $amount);
7957 $amount = str_replace($dec,
'.', $amount);
7959 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
7977function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round = -1, $forceunitoutput =
'no', $use_short_label = 0)
7979 require_once DOL_DOCUMENT_ROOT .
'/core/lib/product.lib.php';
7981 if (($forceunitoutput ==
'no' && $dimension < 1 / 10000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -6)) {
7982 $dimension *= 1000000;
7984 } elseif (($forceunitoutput ==
'no' && $dimension < 1 / 10 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -3)) {
7987 } elseif (($forceunitoutput ==
'no' && $dimension > 100000000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 6)) {
7988 $dimension /= 1000000;
7990 } elseif (($forceunitoutput ==
'no' && $dimension > 100000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 3)) {
8007 $ret =
price($dimension, 0, $outputlangs, 0, 0, $round);
8027function get_localtax($vatrate, $local, $thirdparty_buyer =
null, $thirdparty_seller =
null, $vatnpr = 0)
8031 if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) {
8032 $thirdparty_seller =
$mysoc;
8035 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);
8037 $vatratecleaned = $vatrate;
8039 if (preg_match(
'/^(.*)\s*\((.*)\)$/', (
string) $vatrate, $reg)) {
8040 $vatratecleaned = trim($reg[1]);
8041 $vatratecode = $reg[2];
8050 if (
$mysoc->country_code ==
'ES') {
8052 if (!
$mysoc->localtax1_assuj || (
string) $vatratecleaned ==
"0") {
8055 if ($thirdparty_seller->id ==
$mysoc->id) {
8056 if (!$thirdparty_buyer->localtax1_assuj) {
8060 if (!$thirdparty_seller->localtax1_assuj) {
8068 if (!
$mysoc->localtax2_assuj) {
8071 if ($thirdparty_seller->id ==
$mysoc->id) {
8072 if (!$thirdparty_buyer->localtax2_assuj) {
8076 if (!$thirdparty_seller->localtax2_assuj) {
8082 if ($local == 1 && !$thirdparty_seller->localtax1_assuj) {
8085 if ($local == 2 && !$thirdparty_seller->localtax2_assuj) {
8091 if (in_array(
$mysoc->country_code, array(
'ES'))) {
8092 $conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY = 1;
8098 if ($thirdparty_seller !=
$mysoc) {
8100 return $thirdparty_seller->localtax1_value;
8109 if ($thirdparty_seller !=
$mysoc) {
8112 return $thirdparty_seller->localtax2_value;
8115 if (in_array(
$mysoc->country_code, array(
'ES'))) {
8116 return $thirdparty_buyer->localtax2_value;
8125 $sql =
"SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
8126 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
8127 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" .
$db->escape($thirdparty_seller->country_code) .
"'";
8128 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
8129 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
8130 if (!empty($vatratecode)) {
8131 $sql .=
" AND t.code ='" .
$db->escape($vatratecode) .
"'";
8133 $sql .=
" AND t.recuperableonly = '" .
$db->escape((
string) $vatnpr) .
"'";
8136 $resql =
$db->query($sql);
8139 $obj =
$db->fetch_object($resql);
8142 return $obj->localtax1;
8143 } elseif ($local == 2) {
8144 return $obj->localtax2;
8165 $valors = explode(
":", $tax);
8167 if (count($valors) > 1) {
8184 $sql =
" SELECT t.localtax" . ((int) $local) .
" as localtax";
8185 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t INNER JOIN " . MAIN_DB_PREFIX .
"c_country as c ON c.rowid = t.fk_pays";
8186 $sql .=
" WHERE c.code = '" .
$db->escape(
$mysoc->country_code) .
"' AND t.active = 1 AND t.entity IN (" .
getEntity(
'c_tva') .
") AND t.taux = (";
8187 $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";
8188 $sql .=
" WHERE c.code = '" .
$db->escape(
$mysoc->country_code) .
"' AND t.entity IN (" .
getEntity(
'c_tva') .
") AND tt.active = 1)";
8189 $sql .=
" AND t.localtax" . ((int) $local) .
"_type <> '0'";
8190 $sql .=
" ORDER BY t.rowid DESC";
8192 $resql =
$db->query($sql);
8194 $obj =
$db->fetch_object($resql);
8196 return $obj->localtax;
8217function getTaxesFromId($vatrate, $buyer =
null, $seller =
null, $firstparamisid = 1)
8221 dol_syslog(
"getTaxesFromId vat id or rate = " . $vatrate);
8224 $sql =
"SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy,";
8225 $sql .=
" t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type";
8226 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t";
8227 if ($firstparamisid) {
8228 $sql .=
" WHERE t.rowid = " . (int) $vatrate;
8230 $vatratecleaned = $vatrate;
8233 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
8234 $vatratecleaned = $reg[1];
8235 $vatratecode = $reg[2];
8238 $sql .=
", " . MAIN_DB_PREFIX .
"c_country as c";
8241 $sql .=
" WHERE t.fk_pays = c.rowid";
8243 $sql .=
" AND c.code = '" .
$db->escape($buyer->country_code) .
"'";
8245 $sql .=
" AND c.code = '" .
$db->escape($seller->country_code) .
"'";
8247 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
8248 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
8250 $sql .=
" AND t.code = '" .
$db->escape($vatratecode) .
"'";
8254 $resql =
$db->query($sql);
8256 $obj =
$db->fetch_object($resql);
8259 'rowid' => $obj->rowid,
8260 'code' => $obj->code,
8261 'rate' => $obj->rate,
8262 'localtax1' => $obj->localtax1,
8263 'localtax1_type' => $obj->localtax1_type,
8264 'localtax2' => $obj->localtax2,
8265 'localtax2_type' => $obj->localtax2_type,
8267 'accountancy_code_sell' => $obj->accountancy_code_sell,
8268 'accountancy_code_buy' => $obj->accountancy_code_buy
8300 dol_syslog(
"getLocalTaxesFromRate vatrate=" . $vatrate .
" local=" . $local);
8303 $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";
8304 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t";
8305 if ($firstparamisid) {
8306 $sql .=
" WHERE t.rowid = " . (int) $vatrate;
8308 $vatratecleaned = $vatrate;
8311 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
8312 $vatratecleaned = $reg[1];
8313 $vatratecode = $reg[2];
8316 $sql .=
", " . MAIN_DB_PREFIX .
"c_country as c";
8318 $countrycodetouse = ((empty($buyer) || empty($buyer->country_code)) ?
$mysoc->country_code : $buyer->country_code);
8319 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" .
$db->escape($countrycodetouse) .
"'";
8321 $countrycodetouse = ((empty($seller) || empty($seller->country_code)) ?
$mysoc->country_code : $seller->country_code);
8322 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '" .
$db->escape($countrycodetouse) .
"'";
8324 $sql .=
" AND t.taux = " . ((float) $vatratecleaned) .
" AND t.active = 1";
8326 $sql .=
" AND t.code = '" .
$db->escape($vatratecode) .
"'";
8330 $resql =
$db->query($sql);
8332 $obj =
$db->fetch_object($resql);
8335 $vateratestring = $obj->rate . ($obj->code ?
' (' . $obj->code .
')' :
'');
8338 return array($obj->localtax1_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
8339 } elseif ($local == 2) {
8340 return array($obj->localtax2_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
8342 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);
8364 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
8372 $product->fetch($idprod);
8374 if ((
$mysoc->country_code == $thirdpartytouseforcountry->country_code)
8375 || (in_array(
$mysoc->country_code, array(
'FR',
'MC')) && in_array($thirdpartytouseforcountry->country_code, array(
'FR',
'MC')))
8376 || (in_array(
$mysoc->country_code, array(
'MQ',
'GP')) && in_array($thirdpartytouseforcountry->country_code, array(
'MQ',
'GP')))
8379 if ($idprodfournprice > 0) {
8380 $result = $product->get_buyprice($idprodfournprice, 0, 0,
'');
8382 $ret = $product->vatrate_supplier;
8383 if ($product->default_vat_code_supplier) {
8384 $ret .=
' (' . $product->default_vat_code_supplier .
')';
8390 $ret = $product->tva_tx;
8391 if ($product->default_vat_code) {
8392 $ret .=
' (' . $product->default_vat_code .
')';
8405 $sql =
"SELECT t.taux as vat_rate, t.code as default_vat_code";
8406 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
8407 $sql .=
" WHERE t.active = 1 AND t.fk_pays = c.rowid AND c.code = '" .
$db->escape($thirdpartytouseforcountry->country_code) .
"'";
8408 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
8409 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
8410 $sql .=
$db->plimit(1);
8412 $resql =
$db->query($sql);
8414 $obj =
$db->fetch_object($resql);
8416 $ret = $obj->vat_rate;
8417 if ($obj->default_vat_code) {
8418 $ret .=
' (' . $obj->default_vat_code .
')';
8442 dol_syslog(
"get_product_vat_for_country: ret=" . $ret);
8460 if (!class_exists(
'Product')) {
8461 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
8470 $result = $product->fetch($idprod);
8472 if (
$mysoc->country_code == $thirdpartytouseforcountry->country_code) {
8486 $sql =
"SELECT taux as vat_rate, localtax1, localtax2";
8487 $sql .=
" FROM " . MAIN_DB_PREFIX .
"c_tva as t, " . MAIN_DB_PREFIX .
"c_country as c";
8488 $sql .=
" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='" .
$db->escape($thirdpartytouseforcountry->country_code) .
"'";
8489 $sql .=
" AND t.entity IN (" .
getEntity(
'c_tva') .
")";
8490 $sql .=
" ORDER BY t.taux DESC, t.recuperableonly ASC";
8491 $sql .=
$db->plimit(1);
8493 $resql =
$db->query($sql);
8495 $obj =
$db->fetch_object($resql);
8498 $ret = $obj->localtax1;
8499 } elseif ($local == 2) {
8500 $ret = $obj->localtax2;
8508 dol_syslog(
"get_product_localtax_for_country: ret=" . $ret);
8534 require_once DOL_DOCUMENT_ROOT .
'/core/lib/company.lib.php';
8537 $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;
8539 if (empty($thirdparty_seller->country_code)) {
8540 $thirdparty_seller->country_code =
$mysoc->country_code;
8542 $seller_country_code = $thirdparty_seller->country_code;
8543 $seller_in_cee =
isInEEC($thirdparty_seller);
8545 if (empty($thirdparty_buyer->country_code)) {
8546 $thirdparty_buyer->country_code =
$mysoc->country_code;
8548 $buyer_country_code = $thirdparty_buyer->country_code;
8549 $buyer_in_cee =
isInEEC($thirdparty_buyer);
8551 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'));
8559 if ($seller_in_cee && $buyer_in_cee) {
8560 $isacompany = $thirdparty_buyer->
isACompany();
8561 if ($isacompany && !
getDolGlobalString(
'MAIN_USE_VAT_ZERO_FOR_COMPANIES_IN_EEC_EVEN_IF_VAT_ID_UNKNOWN')) {
8562 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
8570 $vatrule =
'VATRULE 0';
8576 if (empty($vatrule) && !$seller_use_vat) {
8584 $vatrule =
'VATRULE 1';
8588 if (empty($vatrule) && !empty($thirdparty_buyer->state_id)) {
8589 $sql =
"SELECT d.rowid, t.taux as vat_default_rate, t.code as vat_default_code ";
8590 $sql .=
" FROM " .
$db->prefix() .
"c_tva as t";
8591 $sql .=
" INNER JOIN " .
$db->prefix() .
"c_departements as d ON t.fk_department_buyer = d.rowid";
8592 $sql .=
" WHERE d.rowid = " . ((int) $thirdparty_buyer->state_id);
8593 $sql .=
" AND t.active > 0";
8594 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
8595 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
8597 $res =
$db->query($sql);
8599 if (
$db->num_rows($res)) {
8600 $obj =
$db->fetch_object($res);
8602 $vatvalue = $obj->vat_default_rate .
' (' . $obj->vat_default_code .
')';
8603 $vatrule =
'VATRULE 2';
8610 if (empty($vatrule) && (
8611 ($seller_country_code == $buyer_country_code)
8612 || (in_array($seller_country_code, array(
'FR',
'MC')) && in_array($buyer_country_code, array(
'FR',
'MC')))
8613 || (in_array($seller_country_code, array(
'MQ',
'GP')) && in_array($buyer_country_code, array(
'MQ',
'GP')))
8618 if ($seller_country_code ==
'IN' &&
getDolGlobalString(
'MAIN_SALETAX_AUTOSWITCH_I_CS_FOR_INDIA')) {
8622 if (preg_match(
'/C+S-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id != $thirdparty_buyer->state_id) {
8624 $tmpvat = str_replace(
"C+S",
"I", $tmpvat);
8625 } elseif (preg_match(
'/I-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id == $thirdparty_buyer->state_id) {
8627 $tmpvat = str_replace(
"I",
"C+S", $tmpvat);
8631 $vatvalue = $tmpvat;
8632 $vatrule =
'VATRULE 3b';
8640 if (empty($vatrule) && ($seller_in_cee && $buyer_in_cee)) {
8641 $isacompany = $thirdparty_buyer->
isACompany();
8642 if ($isacompany && !
getDolGlobalString(
'MAIN_USE_VAT_ZERO_FOR_COMPANIES_IN_EEC_EVEN_IF_VAT_ID_UNKNOWN')) {
8643 require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
8652 $vatrule =
'VATRULE 5';
8659 $vatrule =
'VATRULE 6';
8665 if (empty($vatrule) &&
getDolGlobalString(
'MAIN_USE_VAT_OF_PRODUCT_FOR_INDIVIDUAL_CUSTOMER_OUT_OF_EEC') && empty($buyer_in_cee)) {
8666 $isacompany = $thirdparty_buyer->
isACompany();
8669 $vatrule =
'VATRULE extra';
8682 $parameters = array(
'vatvalue' => $vatvalue,
'vatrule' => $vatrule);
8686 $reshook = $hookmanager->executeHooks(
'get_default_tva', $parameters, $tmpobject, $tmpaction);
8687 if ($reshook > 0 && !empty($hookmanager->resArray[
'vatvalue'])) {
8688 $vatvalue = $hookmanager->resArray[
'vatvalue'];
8689 $vatrule = $hookmanager->resArray[
'vatrule'];
8710 if ($idprodfournprice > 0) {
8711 if (!class_exists(
'ProductFournisseur')) {
8712 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.product.class.php';
8715 $prodprice->fetch_product_fournisseur_price($idprodfournprice);
8716 return $prodprice->fourn_tva_npr;
8717 } elseif ($idprod > 0) {
8718 if (!class_exists(
'Product')) {
8719 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
8722 $prod->fetch($idprod);
8723 return $prod->tva_npr;
8746 if (!is_object($thirdparty_seller)) {
8749 if (!is_object($thirdparty_buyer)) {
8753 if (empty($thirdparty_seller->country_code)) {
8754 $thirdparty_seller->country_code =
$mysoc->country_code;
8756 $seller_country_code = $thirdparty_seller->country_code;
8759 if (empty($thirdparty_buyer->country_code)) {
8760 $thirdparty_buyer->country_code =
$mysoc->country_code;
8762 $buyer_country_code = $thirdparty_buyer->country_code;
8766 if (
$mysoc->country_code ==
'ES') {
8767 if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) {
8772 if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) {
8775 if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj ==
'localtax1off') {
8779 } elseif ($local == 2) {
8781 if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) {
8784 if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj ==
'localtax2off') {
8789 if ($seller_country_code == $buyer_country_code) {
8804function yn($yesno, $format = 1, $color = 0)
8808 $result =
'unknown';
8810 if ($yesno ===
true || (
int) $yesno == 1 || (isset($yesno) && (strtolower($yesno) ==
'yes' || strtolower($yesno) ==
'true'))) {
8811 $result = $langs->trans(
'yes');
8812 if ($format == 1 || $format == 3) {
8813 $result = $langs->trans(
"Yes");
8816 $result =
'<input type="checkbox" value="1" checked disabled>';
8819 $result =
'<input type="checkbox" value="1" checked disabled> ' . $result;
8821 if ($format == 4 || !is_numeric($format)) {
8822 $result =
img_picto(is_numeric($format) ?
'' : $format,
'check');
8827 $result = $langs->trans(
"no");
8828 if ($format == 1 || $format == 3) {
8829 $result = $langs->trans(
"No");
8832 $result =
'<input type="checkbox" value="0" disabled>';
8835 $result =
'<input type="checkbox" value="0" disabled> ' . $result;
8837 if ($format == 4 || !is_numeric($format)) {
8838 $result =
img_picto(is_numeric($format) ?
'' : $format,
'uncheck');
8844 $classname =
'error';
8848 return '<span class="' . $classname .
'">' . $result .
'</span>';
8871function get_exdir($num, $level, $alpha, $withoutslash,
$object, $modulepart =
'')
8873 if (empty($modulepart) && is_object(
$object)) {
8874 if (!empty(
$object->module)) {
8875 $modulepart =
$object->module;
8876 } elseif (!empty(
$object->element)) {
8877 $modulepart =
$object->element;
8884 $arrayforoldpath = array(
'cheque' => 2,
'category' => 2,
'supplier_invoice' => 2,
'invoice_supplier' => 2,
'mailing' => 2,
'supplier_payment' => 2);
8886 $arrayforoldpath[
'product'] = 2;
8889 if (empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
8890 $level = $arrayforoldpath[$modulepart];
8892 if (!empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
8894 if (empty($num) && is_object(
$object)) {
8897 if (empty($alpha)) {
8898 $num = preg_replace(
'/([^0-9])/i',
'', $num);
8900 $num = preg_replace(
'/^.*\-/i',
'', $num);
8902 $num = substr(
"000" . $num, -$level);
8904 $path = substr($num, 0, 1);
8907 $path = substr($num, 1, 1) .
'/' . substr($num, 0, 1);
8910 $path = substr($num, 2, 1) .
'/' . substr($num, 1, 1) .
'/' . substr($num, 0, 1);
8916 if (in_array($modulepart, array(
'societe',
'thirdparty')) &&
$object instanceof
Societe) {
8924 if (empty($withoutslash) && !empty($path)) {
8939function dol_mkdir($dir, $dataroot =
'', $newmask =
'')
8941 dol_syslog(
"functions.lib::dol_mkdir: dir=" . $dir, LOG_INFO);
8946 if (@is_dir($dir_osencoded)) {
8954 if (!empty($dataroot)) {
8956 $dir = str_replace($dataroot .
'/',
'', $dir);
8957 $ccdir = $dataroot .
'/';
8960 $cdir = explode(
"/", $dir);
8961 $num = count($cdir);
8962 for ($i = 0; $i < $num; $i++) {
8964 $ccdir .=
'/' . $cdir[$i];
8966 $ccdir .= $cdir[$i];
8969 if (preg_match(
"/^.:$/", $ccdir, $regs)) {
8977 if (!@is_dir($ccdir_osencoded)) {
8978 dol_syslog(
"functions.lib::dol_mkdir: Directory '" . $ccdir .
"' is not found (does not exists or is outside open_basedir PHP setting).", LOG_DEBUG);
8981 $dirmaskdec = octdec((
string) $newmask);
8982 if (empty($newmask)) {
8985 $dirmaskdec |= octdec(
'0111');
8986 if (!@mkdir($ccdir_osencoded, $dirmaskdec)) {
8988 dol_syslog(
"functions.lib::dol_mkdir: Fails to create directory '" . $ccdir .
"' (no permission to write into parent or directory already exists).", LOG_WARNING);
8991 dol_syslog(
"functions.lib::dol_mkdir: Directory '" . $ccdir .
"' created", LOG_DEBUG);
9000 return ($nberr ? -$nberr : $nbcreated);
9011function dolChmod($filepath, $newmask =
'')
9013 if (!empty($newmask)) {
9014 @chmod($filepath, octdec($newmask));
9028 return '<span class="fieldrequired">*</span>';
9048function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto =
'UTF-8', $strip_tags = 0, $removedoublespaces = 1)
9050 if (is_null($stringtoclean)) {
9054 if ($removelinefeed == 2) {
9055 $stringtoclean = preg_replace(
'/<br[^>]*>(\n|\r)+/ims',
'<br>', $stringtoclean);
9057 $temp = preg_replace(
'/<br[^>]*>/i',
"\n", $stringtoclean);
9062 $temp = str_replace(
'< ',
'__ltspace__', $temp);
9063 $temp = str_replace(
'<:',
'__lttwopoints__', $temp);
9066 $temp = strip_tags($temp);
9069 $pattern =
"/<[^<>]+>/";
9076 $tempbis = str_replace(
'<>',
'', $temp);
9077 $tempbis = preg_replace($pattern,
'', $tempbis);
9079 }
while ($tempbis != $temp);
9084 $temp = preg_replace(
'/<+([a-z]+)/i',
'\1', $temp);
9090 if ($removelinefeed == 1) {
9091 $temp = str_replace(array(
"\r\n",
"\r",
"\n"),
" ", $temp);
9095 if ($removedoublespaces) {
9096 while (strpos($temp,
" ") !==
false) {
9097 $temp = str_replace(
" ",
" ", $temp);
9101 $temp = str_replace(
'__ltspace__',
'< ', $temp);
9102 $temp = str_replace(
'__lttwopoints__',
'<:', $temp);
9126function dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles = 1, $removeclassattribute = 1, $cleanalsojavascript = 0, $allowiframe = 0, $allowed_tags = array(), $allowlink = 0, $allowscript = 0, $allowstyle = 0, $allowphp = 0)
9128 $sav_allowed_tags = $allowed_tags;
9130 if (empty($allowed_tags) || (is_string($allowed_tags) && preg_match(
'/^common/', $allowed_tags))) {
9131 $allowed_tags = array(
9188 $allowed_tags[] =
"comment";
9190 if (!in_array(
'iframe', $allowed_tags)) {
9191 $allowed_tags[] =
"iframe";
9195 if (!in_array(
'link', $allowed_tags)) {
9196 $allowed_tags[] =
"link";
9198 if (!in_array(
'meta', $allowed_tags)) {
9199 $allowed_tags[] =
"meta";
9203 if (!in_array(
'script', $allowed_tags)) {
9204 $allowed_tags[] =
"script";
9208 if (!in_array(
'style', $allowed_tags)) {
9209 $allowed_tags[] =
"style";
9212 if (is_string($sav_allowed_tags)) {
9213 $tmptags = explode(
',', $sav_allowed_tags);
9214 foreach ($tmptags as $tag) {
9215 if ($tag !=
'common') {
9216 $allowed_tags[] = $tag;
9222 $allowed_tags_string = implode(
"><", $allowed_tags);
9223 $allowed_tags_string =
'<' . $allowed_tags_string .
'>';
9225 $stringtoclean = str_replace(
'<!DOCTYPE html>',
'__!DOCTYPE_HTML__', $stringtoclean);
9230 $stringtoclean = preg_replace(
'/<!--([^>]*)-->/',
'<comment>\1</comment>', $stringtoclean);
9233 $allowed_tags[] =
"commentphp";
9234 $stringtoclean = preg_replace(
'/^<\?php([^"]+)\?>$/i',
'<commentphp>\1__</commentphp>', $stringtoclean);
9235 $stringtoclean = preg_replace(
'/"<\?php([^"]+)\?>"/i',
'"<commentphp>\1</commentphp>"', $stringtoclean);
9238 $stringtoclean = preg_replace(
'/:/i',
':', $stringtoclean);
9239 $stringtoclean = preg_replace(
'/:|�+58|:/i',
'', $stringtoclean);
9242 $temp = strip_tags($stringtoclean, $allowed_tags_string);
9244 if ($cleanalsosomestyles) {
9246 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)/i',
'', $temp);
9247 $temp = preg_replace(
'/z-index\s*:/i',
'', $temp);
9249 if ($removeclassattribute) {
9250 $temp = preg_replace(
'/(<[^>]+)\s+class=((["\']).*?\\3|\\w*)/i',
'\\1', $temp);
9255 if ($cleanalsojavascript) {
9256 $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);
9259 $temp = str_replace(
'__!DOCTYPE_HTML__',
'<!DOCTYPE html>', $temp);
9262 $temp = preg_replace(
'/<commentphp>(.*)<\/commentphp>/',
'<?php\1?>', $temp);
9265 $temp = preg_replace(
'/<comment>([^>]*)<\/comment>/',
'<!--\1-->', $temp);
9286 if (is_null($allowed_attributes)) {
9287 $allowed_attributes = array(
9321 if (!in_array(
"content", $allowed_attributes)) {
9322 $allowed_attributes[] =
"content";
9324 if (!in_array(
"http-equiv", $allowed_attributes)) {
9325 $allowed_attributes[] =
"http-equiv";
9328 if (class_exists(
'DOMDocument') && !empty($stringtoclean)) {
9330 $stringtoclean =
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>' . $stringtoclean .
'</body></html>';
9333 $dom =
new DOMDocument(
'',
'UTF-8');
9335 $savwarning = error_reporting();
9336 error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE);
9337 $dom->loadHTML($stringtoclean, LIBXML_ERR_NONE | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_NOXMLDECL);
9338 error_reporting($savwarning);
9340 if ($dom instanceof DOMDocument) {
9341 for ($els = $dom->getElementsByTagname(
'*'), $i = $els->length - 1; $i >= 0; $i--) {
9342 $el = $els->item($i);
9343 if (!$el instanceof DOMElement) {
9346 $attrs = $el->attributes;
9347 for ($ii = $attrs->length - 1; $ii >= 0; $ii--) {
9349 if (!empty($attrs->item($ii)->name)) {
9350 if (! in_array($attrs->item($ii)->name, $allowed_attributes)) {
9352 $els->item($i)->removeAttribute($attrs->item($ii)->name);
9353 } elseif (in_array($attrs->item($ii)->name, array(
'style'))) {
9355 $valuetoclean = $attrs->item($ii)->value;
9357 if (isset($valuetoclean)) {
9359 $oldvaluetoclean = $valuetoclean;
9360 $valuetoclean = preg_replace(
'/\/\*.*\*\//m',
'', $valuetoclean);
9361 $valuetoclean = preg_replace(
'/position\s*:\s*[a-z]+/mi',
'', $valuetoclean);
9362 if ($els->item($i)->tagName ==
'a') {
9363 $valuetoclean = preg_replace(
'/display\s*:/mi',
'', $valuetoclean);
9364 $valuetoclean = preg_replace(
'/z-index\s*:/mi',
'', $valuetoclean);
9365 $valuetoclean = preg_replace(
'/\s+(top|left|right|bottom)\s*:/mi',
'', $valuetoclean);
9369 $valuetoclean = preg_replace(
'/(logout|passwordforgotten)\.php/mi',
'', $valuetoclean);
9370 $valuetoclean = preg_replace(
'/action=/mi',
'', $valuetoclean);
9371 }
while ($oldvaluetoclean != $valuetoclean);
9374 $attrs->item($ii)->value = $valuetoclean;
9381 $dom->encoding =
'UTF-8';
9383 $return = $dom->saveHTML();
9387 $return = preg_replace(
'/^' . preg_quote(
'<html><head><',
'/') .
'[^<>]*' . preg_quote(
'></head><body>',
'/') .
'/',
'', $return);
9388 $return = preg_replace(
'/' . preg_quote(
'</body></html>',
'/') .
'$/',
'', trim($return));
9390 return trim($return);
9392 return $stringtoclean;
9409 $temp = $stringtoclean;
9410 foreach ($disallowed_tags as $tagtoremove) {
9411 $temp = preg_replace(
'/<\/?' . $tagtoremove .
'>/',
'', $temp);
9412 $temp = preg_replace(
'/<\/?' . $tagtoremove .
'\s+[^>]*>/',
'', $temp);
9415 if ($cleanalsosomestyles) {
9416 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)\s*!\s*important/',
'', $temp);
9434 if (!is_string($text) || $text ===
'') {
9439 $selfclosing = array(
'br',
'hr',
'img',
'input',
'meta',
'link',
'source',
'col',
'area',
'base',
'embed',
'param',
'track',
'wbr');
9442 if (preg_match_all(
'/<\s*(\/?)([a-zA-Z][a-zA-Z0-9]*)[^>]*?(\/?)\s*>/', $text, $matches, PREG_SET_ORDER)) {
9443 foreach ($matches as $match) {
9444 $tag = strtolower($match[2]);
9445 if (in_array($tag, $selfclosing) || !empty($match[3])) {
9448 if (empty($match[1])) {
9452 $idx = array_search($tag, array_reverse($opened,
true),
true);
9453 if ($idx !==
false) {
9454 unset($opened[$idx]);
9460 foreach (array_reverse($opened) as $tag) {
9461 $text .=
'</'.$tag.
'>';
9478 if ($nboflines == 1) {
9480 $firstline = preg_replace(
'/<br[^>]*>.*$/s',
'', $text);
9481 $firstline = preg_replace(
'/<div[^>]*>.*$/s',
'', $firstline);
9484 $firstline = preg_replace(
'/[\n\r].*/',
'', $text);
9489 return $firstline . (isset($firstline) && isset($text) && (strlen($firstline) != strlen($text)) ?
'...' :
'');
9493 $text = preg_replace(
'/\n/',
'', $text);
9495 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
9497 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
9500 $text = strtr($text, $repTable);
9501 if ($charset ==
'UTF-8') {
9502 $pattern =
'/(<br[^>]*>)/Uu';
9505 $pattern =
'/(<br[^>]*>)/U';
9507 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
9512 $lastaddediscontent = 1;
9513 while ($countline < $nboflines && isset($a[$i])) {
9514 if (preg_match(
'/<br[^>]*>/', $a[$i])) {
9515 if (array_key_exists($i + 1, $a) && !empty($a[$i + 1])) {
9516 $firstline .= ($ishtml ?
"<br>\n" :
"\n");
9518 if (!$lastaddediscontent) {
9521 $lastaddediscontent = 0;
9524 $firstline .= $a[$i];
9525 $lastaddediscontent = 1;
9531 $adddots = (isset($a[$i]) && (!preg_match(
'/<br[^>]*>/', $a[$i]) || (array_key_exists($i + 1, $a) && !empty($a[$i + 1]))));
9533 $ret = $firstline . ($adddots ?
'...' :
'');
9551function dol_nl2br($stringtoencode, $nl2brmode = 0, $forxml =
false)
9553 if (is_null($stringtoencode)) {
9558 return nl2br($stringtoencode, $forxml);
9560 $ret = preg_replace(
'/(\r\n|\r|\n)/i', ($forxml ?
'<br />' :
'<br>'), $stringtoencode);
9574function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check =
'restricthtml')
9576 if (empty($nouseofiframesandbox) &&
getDolGlobalString(
'MAIN_SECURITY_USE_SANDBOX_FOR_HTMLWITHNOJS')) {
9581 return $stringtoencode;
9583 $out = $stringtoencode;
9587 $oldstringtoclean = $out;
9595 if (!empty($out) &&
getDolGlobalInt(
'MAIN_RESTRICTHTML_ONLY_VALID_HTML') && $check !=
'restricthtmlallowunvalid') {
9597 libxml_use_internal_errors(
false);
9598 if (LIBXML_VERSION < 20900) {
9602 libxml_disable_entity_loader(
true);
9605 $dom =
new DOMDocument();
9613 $out =
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body><div class="tricktoremove">' . $out .
'</div></body></html>';
9617 $out = preg_replace(
'/&(?![a-zA-Z0-9#]+;)/',
'__AMPINTEXT__', $out);
9620 $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>';
9626 $out = preg_replace_callback(
9627 '/__\[([0-9a-zA-Z_]+)\]__/',
9633 return '__BRACKETSTART' . $m[1] .
'BRACKETEND__';
9638 $dom->loadHTML($out, LIBXML_HTML_NODEFDTD | LIBXML_ERR_NONE | LIBXML_HTML_NOIMPLIED | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_NOERROR | LIBXML_NOXMLDECL);
9640 $dom->encoding =
'UTF-8';
9644 foreach ($dom->getElementsByTagName(
'*') as $el) {
9645 if (!$el instanceof DOMElement) {
9650 if ($el->hasAttribute(
'style')) {
9652 $style = $el->getAttribute(
'style');
9655 $style = preg_replace(
'/z-index\s*:/i',
'', $style);
9656 $style = preg_replace(
'/position\s*:/i',
'', $style);
9657 $style = preg_replace(
'/top\s*:/i',
'', $style);
9658 $style = preg_replace(
'/left\s*:/i',
'', $style);
9659 $style = preg_replace(
'/background\s*:/i',
'', $style);
9665 if (trim($style) ===
'') {
9667 $el->removeAttribute(
'style');
9670 $el->setAttribute(
'style', $style);
9676 $out = trim($dom->saveHTML());
9679 $out = preg_replace_callback(
9680 '/__BRACKETSTART([0-9a-zA-Z_]+)BRACKETEND__/',
9686 return '__[' . $m[1] .
']__';
9693 $out = preg_replace(
'/^' . preg_quote(
'<html><head><',
'/') .
'[^<>]+' . preg_quote(
'></head><body><div class="tricktoremove">',
'/') .
'/',
'', $out);
9694 $out = preg_replace(
'/' . preg_quote(
'</div></body></html>',
'/') .
'$/',
'', trim($out));
9699 $out = str_replace(
'__AMPINTEXT__',
'&', $out);
9700 $out = str_replace(
'<br>',
'', $out);
9705 $out =
'InvalidHTMLStringCantBeCleaned ' . $e->getMessage();
9712 if (!empty($out) &&
getDolGlobalInt(
'MAIN_RESTRICTHTML_ONLY_VALID_HTML_TIDY') && !in_array($check, array(
'restricthtmlallowunvalid',
'restricthtmlallowlinkscript')) && $outishtml) {
9718 if (extension_loaded(
'tidy') && class_exists(
"tidy")) {
9725 'quote-marks' =>
false,
9726 'doctype' =>
'strict',
9727 'show-body-only' =>
true,
9728 "indent-attributes" =>
false,
9729 "vertical-space" =>
false,
9732 'preserve-entities' =>
true
9741 $locale = setlocale(LC_NUMERIC,
'0');
9744 $out = $tidy->repairString($out, $config,
'utf8');
9746 setlocale(LC_NUMERIC, $locale);
9755 $out =
'InvalidHTMLStringCantBeCleaned ' . $e->getMessage();
9761 $out = preg_replace(
'/[\x{200B}-\x{200D}\x{FEFF}]/u',
' ', $out);
9764 $out = preg_replace(
'/&(tab|newline);/i',
' ', $out);
9768 $out = preg_replace(
'/'/i',
''', $out);
9773 if (function_exists(
'realCharForNumericEntities')) {
9774 $out = preg_replace_callback(
9775 '/&#(x?[0-9][0-9a-f]+;?)/i',
9780 static function ($m) {
9788 $out = preg_replace(
'/&#x?[0-9]+/i',
'', $out);
9791 if ($check ==
'restricthtmlallowlinkscript') {
9793 } elseif ($check ==
'restricthtmlallowclass' || $check ==
'restricthtmlallowunvalid') {
9795 } elseif ($check ==
'restricthtmlallowiframe') {
9808 $out = preg_replace(
'/'/i',
"'", $out);
9812 $out = preg_replace(
'/on(mouse|drag|key|load|touch|pointer|select|transition)[a-z]*\s*=/i',
'', $out);
9813 $out = preg_replace(
'/on(abort|after|animation|auxclick|before|blur|cancel|canplay|canplaythrough|change|click|close|command|contentvisibility|context|cuechange|copy|cut)[a-z]*\s*=/i',
'', $out);
9814 $out = preg_replace(
'/on(dblclick|drop|durationchange|emptied|end|ended|error|focus(in|out)?|formdata|gotpointercapture|hashchange|input|invalid)[a-z]*\s*=/i',
'', $out);
9815 $out = preg_replace(
'/on(lost|offline|online|message|pagehide|pageshow)[a-z]*\s*=/i',
'', $out);
9816 $out = preg_replace(
'/on(paste|pause|play|playing|progress|ratechange|rejectionn|reset|resize|scroll|search|security|seeked|seeking|show|stalled|start|submit|suspend)[a-z]*\s*=/i',
'', $out);
9817 $out = preg_replace(
'/on(timeupdate|toggle|unhandled|unload|volumechange|waiting|wheel)[a-z]*\s*=/i',
'', $out);
9819 $out = preg_replace(
'/on(repeat|begin|finish|beforeinput)[a-z]*\s*=/i',
'', $out);
9821 $out = preg_replace(
'/\son[a-z]+\s*=/i',
' ', $out);
9822 }
while ($oldstringtoclean != $out);
9829 $tmpout = preg_replace(
'/<img src="data:/mi',
'<__IMG_SRC_DATA__ src="data:', $out);
9830 preg_match_all(
'/(<img|url\(|<link)/i', $tmpout, $reg);
9831 $nblinks = count($reg[0]);
9832 if ($nblinks >
getDolGlobalInt(
"MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", 1000)) {
9833 $out =
'ErrorTooManyLinksIntoHTMLString';
9836 if (
getDolGlobalInt(
'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 2 || $check ==
'restricthtmlnolink') {
9838 $out =
'ErrorHTMLLinksNotAllowed';
9840 } elseif (
getDolGlobalInt(
'MAIN_DISALLOW_URL_INTO_DESCRIPTIONS') == 1) {
9845 $pattern =
'/src=["\']?(http[^"\']+)|url\(["\']?(http[^\)]+)/';
9850 if (preg_match_all($pattern, $out, $matches)) {
9853 foreach ($matches[1] as $tmpval) {
9854 if (!empty($tmpval)) {
9858 foreach ($matches[2] as $tmpval) {
9859 if (!empty($tmpval)) {
9867 foreach ($urls as $url) {
9869 $parsedurl = parse_url($url);
9870 if (!empty($parsedurl)) {
9879 if (empty($firstexturl)) {
9880 $firstexturl = $url;
9881 } elseif (empty($secondexturl)) {
9882 $secondexturl = $url;
9888 $out =
'ErrorHTMLExternalLinksNotAllowed (Example: '.$firstexturl.($secondexturl ?
' '.$secondexturl :
'').
')';
9917function dol_htmlentitiesbr($stringtoencode, $nl2brmode = 0, $pagecodefrom =
'UTF-8', $removelasteolbr = 1)
9919 if (is_null($stringtoencode)) {
9923 $newstring = $stringtoencode;
9925 $newstring = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
'<br>', $newstring);
9926 if ($removelasteolbr) {
9927 $newstring = preg_replace(
'/<br>$/i',
'', $newstring);
9929 $newstring = preg_replace(
'/[\x{200B}-\x{200D}\x{FEFF}]/u',
' ', $newstring);
9930 $newstring = strtr($newstring, array(
'&' =>
'__PROTECTand__',
'<' =>
'__PROTECTlt__',
'>' =>
'__PROTECTgt__',
'"' =>
'__PROTECTdquot__'));
9932 $newstring = strtr($newstring, array(
'__PROTECTand__' =>
'&',
'__PROTECTlt__' =>
'<',
'__PROTECTgt__' =>
'>',
'__PROTECTdquot__' =>
'"'));
9934 if ($removelasteolbr) {
9935 $newstring = preg_replace(
'/(\r\n|\r|\n)$/i',
'', $newstring);
9954 $ret = preg_replace(
'/' .
"\r\n" .
'<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"<br>", $ret);
9955 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>' .
"\r\n" .
'/i',
"\r\n", $ret);
9956 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>' .
"\n" .
'/i',
"\n", $ret);
9957 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"\n", $ret);
9969 $ret = preg_replace(
'/ $/i',
"", $stringtodecode);
9970 $ret = preg_replace(
'/(<br>|<br(\s[\sa-zA-Z_="]*)?\/?>|' .
"\n" .
'|' .
"\r" .
')+$/i',
"", $ret);
9986 if ($keepsomeentities) {
9987 $newstring = strtr($newstring, array(
'&' =>
'__andamp__',
'<' =>
'__andlt__',
'>' =>
'__andgt__',
'"' =>
'__dquot__'));
9989 $newstring = html_entity_decode((
string) $newstring, (
int) $b, (
string)
$c);
9990 if ($keepsomeentities) {
9991 $newstring = strtr($newstring, array(
'__andamp__' =>
'&',
'__andlt__' =>
'<',
'__andgt__' =>
'>',
'__dquot__' =>
'"'));
10007function dol_htmlentities($string, $flags = ENT_QUOTES | ENT_SUBSTITUTE, $encoding =
'UTF-8', $double_encode =
false)
10009 return htmlentities($string, $flags, $encoding, $double_encode);
10028 for ($scursor = 0; $scursor < $len; $scursor++) {
10029 $ordchar = ord($s[$scursor]);
10031 if ($ordchar < 32 && $ordchar != 13 && $ordchar != 10) {
10034 } elseif ($ordchar > 126 && $ordchar < 160) {
10037 } elseif ($clean) {
10038 $out .= $s[$scursor];
10060 $arraystring = explode(
"\n", $s);
10061 $nb = count($arraystring);
10078 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
10080 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
10083 $text = strtr($text, $repTable);
10084 if ($charset ==
'UTF-8') {
10085 $pattern =
'/(<br[^>]*>)/Uu';
10088 $pattern =
'/(<br[^>]*>)/U';
10090 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
10092 $nblines = (int) floor((count($a) + 1) / 2);
10094 if ($maxlinesize) {
10095 foreach ($a as $line) {
10098 $line_dec = html_entity_decode($line);
10100 $line_dec = wordwrap($line_dec, $maxlinesize,
'\n',
true);
10101 $nblines += substr_count($line_dec,
'\n');
10121 if (is_null($msg)) {
10125 if ($option == 1) {
10126 if (preg_match(
'/<(html|link|script)/i', $msg)) {
10128 } elseif (preg_match(
'/<body/i', $msg)) {
10130 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
10132 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
10134 } elseif (preg_match(
'/<br/i', $msg)) {
10140 $msg = preg_replace(
'/https?:\/\/[^"\'\s]+/i',
'', $msg);
10141 if (preg_match(
'/<(html|link|script|body)/i', $msg)) {
10143 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
10145 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
10147 } elseif (preg_match(
'/<(br|hr)\/>/i', $msg)) {
10149 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)>/i', $msg)) {
10151 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)\s+[^<>\/]*\/?>/i', $msg)) {
10153 } elseif (preg_match(
'/<img\s+[^<>]*src[^<>]*>/i', $msg)) {
10155 } elseif (preg_match(
'/<a\s+[^<>]*href[^<>]*>/i', $msg)) {
10157 } elseif (preg_match(
'/<h[0-9]>/i', $msg)) {
10159 } elseif (preg_match(
'/&[A-Z0-9]{1,6};/i', $msg)) {
10162 } elseif (preg_match(
'/&#[0-9]{2,3};/i', $msg)) {
10164 } elseif (preg_match(
'/&#x[a-f0-9][a-f0-9];/i', $msg)) {
10186function dol_concatdesc($text1, $text2, $forxml =
false, $invert =
false)
10188 if (!empty($invert)) {
10196 $ret .= (!empty($text1) && !empty($text2)) ? ((
dol_textishtml($text1) ||
dol_textishtml($text2)) ? ($forxml ?
"<br >\n" :
"<br>\n") :
"\n") :
"";
10211 return $text1.$text2;
10223 if (!is_string($callback)) {
10224 throw new InvalidArgumentException(
"Les callbacks sont désactivés.");
10227 $allowed_callbacks = [
'strtolower',
'strtoupper',
'intval'];
10228 if (!in_array($callback, $allowed_callbacks,
true)) {
10229 throw new InvalidArgumentException(
"Callback function not allowed.");
10231 return array_map($callback, $array);
10248function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude =
null,
$object =
null, $include =
null)
10252 $substitutionarray = array();
10254 if ((empty($exclude) || !in_array(
'user', $exclude)) && (empty($include) || in_array(
'user', $include)) && $user instanceof
User) {
10258 $emailsendersignature = $user->signature;
10259 $usersignature = $user->signature;
10260 $substitutionarray = array_merge($substitutionarray, array(
10261 '__SENDEREMAIL_SIGNATURE__' => (
string) ((!
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN')) ? ($onlykey == 2 ?
dol_trunc(
'SignatureFromTheSelectedSenderProfile', 30) : $emailsendersignature) :
''),
10265 if (is_object($user) && ($user instanceof
User)) {
10266 $substitutionarray = array_merge($substitutionarray, array(
10267 '__USER_ID__' => (
string) $user->id,
10268 '__USER_LOGIN__' => (
string) $user->login,
10269 '__USER_EMAIL__' => (
string) $user->email,
10270 '__USER_PHONE__' => (
string)
dol_print_phone($user->office_phone,
'', 0, 0,
'',
" ",
'',
'', -1),
10271 '__USER_PHONEPRO__' => (
string)
dol_print_phone($user->user_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
10272 '__USER_PHONEMOBILE__' => (
string)
dol_print_phone($user->personal_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
10273 '__USER_FAX__' => (
string) $user->office_fax,
10274 '__USER_LASTNAME__' => (
string) $user->lastname,
10275 '__USER_FIRSTNAME__' => (
string) $user->firstname,
10276 '__USER_FULLNAME__' => (
string) $user->getFullName($outputlangs),
10277 '__USER_SUPERVISOR_ID__' => (
string) ($user->fk_user ? $user->fk_user :
'0'),
10278 '__USER_JOB__' => (
string) $user->job,
10280 '__USER_VCARD_URL__' => (
string) $user->getOnlineVirtualCardUrl(
'',
'external')
10284 if ((empty($exclude) || !in_array(
'mycompany', $exclude)) && is_object(
$mysoc) && (empty($include) || in_array(
'mycompany', $include))) {
10285 $substitutionarray = array_merge($substitutionarray, array(
10286 '__MYCOMPANY_NAME__' =>
$mysoc->name,
10287 '__MYCOMPANY_EMAIL__' =>
$mysoc->email,
10288 '__MYCOMPANY_URL__' =>
$mysoc->url,
10290 '__MYCOMPANY_PHONEMOBILE__' =>
dol_print_phone((
string)
$mysoc->phone_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
10292 '__MYCOMPANY_PROFID1__' =>
$mysoc->idprof1,
10293 '__MYCOMPANY_PROFID2__' =>
$mysoc->idprof2,
10294 '__MYCOMPANY_PROFID3__' =>
$mysoc->idprof3,
10295 '__MYCOMPANY_PROFID4__' =>
$mysoc->idprof4,
10296 '__MYCOMPANY_PROFID5__' =>
$mysoc->idprof5,
10297 '__MYCOMPANY_PROFID6__' =>
$mysoc->idprof6,
10298 '__MYCOMPANY_PROFID7__' =>
$mysoc->idprof7,
10299 '__MYCOMPANY_PROFID8__' =>
$mysoc->idprof8,
10300 '__MYCOMPANY_PROFID9__' =>
$mysoc->idprof9,
10301 '__MYCOMPANY_PROFID10__' =>
$mysoc->idprof10,
10302 '__MYCOMPANY_CAPITAL__' =>
$mysoc->capital,
10303 '__MYCOMPANY_FULLADDRESS__' => (method_exists(
$mysoc,
'getFullAddress') ?
$mysoc->getFullAddress(1,
', ') :
''),
10305 '__MYCOMPANY_VATNUMBER__' =>
$mysoc->tva_intra,
10306 '__MYCOMPANY_ZIP__' =>
$mysoc->zip,
10307 '__MYCOMPANY_TOWN__' =>
$mysoc->town,
10308 '__MYCOMPANY_STATE__' =>
$mysoc->state,
10309 '__MYCOMPANY_COUNTRY__' =>
$mysoc->country,
10310 '__MYCOMPANY_COUNTRY_ID__' =>
$mysoc->country_id,
10311 '__MYCOMPANY_COUNTRY_CODE__' =>
$mysoc->country_code,
10312 '__MYCOMPANY_CURRENCY_CODE__' =>
$conf->currency
10316 if (($onlykey || is_object(
$object)) && (empty($exclude) || !in_array(
'object', $exclude)) && (empty($include) || in_array(
'object', $include))) {
10318 $substitutionarray[
'__ID__'] =
'__ID__';
10319 $substitutionarray[
'__REF__'] =
'__REF__';
10320 $substitutionarray[
'__NEWREF__'] =
'__NEWREF__';
10321 $substitutionarray[
'__LABEL__'] =
'__LABEL__';
10322 $substitutionarray[
'__REF_CLIENT__'] =
'__REF_CLIENT__';
10323 $substitutionarray[
'__REF_SUPPLIER__'] =
'__REF_SUPPLIER__';
10324 $substitutionarray[
'__NOTE_PUBLIC__'] =
'__NOTE_PUBLIC__';
10325 $substitutionarray[
'__NOTE_PRIVATE__'] =
'__NOTE_PRIVATE__';
10326 $substitutionarray[
'__EXTRAFIELD_XXX__'] =
'__EXTRAFIELD_XXX__';
10329 $substitutionarray[
'__THIRDPARTY_ID__'] =
'__THIRDPARTY_ID__';
10330 $substitutionarray[
'__THIRDPARTY_NAME__'] =
'__THIRDPARTY_NAME__';
10331 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
'__THIRDPARTY_NAME_ALIAS__';
10332 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
'__THIRDPARTY_CODE_CLIENT__';
10333 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
'__THIRDPARTY_CODE_FOURNISSEUR__';
10334 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
'__THIRDPARTY_EMAIL__';
10336 $substitutionarray[
'__THIRDPARTY_URL__'] =
'__THIRDPARTY_URL__';
10338 $substitutionarray[
'__THIRDPARTY_PHONE__'] =
'__THIRDPARTY_PHONE__';
10339 $substitutionarray[
'__THIRDPARTY_FAX__'] =
'__THIRDPARTY_FAX__';
10340 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
'__THIRDPARTY_ADDRESS__';
10341 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
'__THIRDPARTY_ZIP__';
10342 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
'__THIRDPARTY_TOWN__';
10343 $substitutionarray[
'__THIRDPARTY_STATE__'] =
'__THIRDPARTY_STATE__';
10344 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
'__THIRDPARTY_IDPROF1__';
10345 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
'__THIRDPARTY_IDPROF2__';
10346 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
'__THIRDPARTY_IDPROF3__';
10347 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
'__THIRDPARTY_IDPROF4__';
10348 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
'__THIRDPARTY_IDPROF5__';
10349 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
'__THIRDPARTY_IDPROF6__';
10350 $substitutionarray[
'__THIRDPARTY_IDPROF7__'] =
'__THIRDPARTY_IDPROF7__';
10351 $substitutionarray[
'__THIRDPARTY_IDPROF8__'] =
'__THIRDPARTY_IDPROF8__';
10352 $substitutionarray[
'__THIRDPARTY_IDPROF9__'] =
'__THIRDPARTY_IDPROF9__';
10353 $substitutionarray[
'__THIRDPARTY_IDPROF10__'] =
'__THIRDPARTY_IDPROF10__';
10354 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
'__THIRDPARTY_TVAINTRA__';
10355 $substitutionarray[
'__THIRDPARTY_NOTE_PUBLIC__'] =
'__THIRDPARTY_NOTE_PUBLIC__';
10356 $substitutionarray[
'__THIRDPARTY_NOTE_PRIVATE__'] =
'__THIRDPARTY_NOTE_PRIVATE__';
10358 if (
isModEnabled(
'member') && (!is_object(
$object) ||
$object->element ==
'adherent') && (empty($exclude) || !in_array(
'member', $exclude)) && (empty($include) || in_array(
'member', $include))) {
10359 $substitutionarray[
'__MEMBER_ID__'] =
'__MEMBER_ID__';
10360 $substitutionarray[
'__MEMBER_TITLE__'] =
'__MEMBER_TITLE__';
10361 $substitutionarray[
'__MEMBER_FIRSTNAME__'] =
'__MEMBER_FIRSTNAME__';
10362 $substitutionarray[
'__MEMBER_LASTNAME__'] =
'__MEMBER_LASTNAME__';
10363 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'Login and pass of the external user account';
10368 if (
isModEnabled(
'ticket') && (!is_object(
$object) ||
$object->element ==
'ticket') && (empty($exclude) || !in_array(
'ticket', $exclude)) && (empty($include) || in_array(
'ticket', $include))) {
10369 $substitutionarray[
'__TICKET_TRACKID__'] =
'__TICKET_TRACKID__';
10370 $substitutionarray[
'__TICKET_SUBJECT__'] =
'__TICKET_SUBJECT__';
10371 $substitutionarray[
'__TICKET_TYPE__'] =
'__TICKET_TYPE__';
10372 $substitutionarray[
'__TICKET_SEVERITY__'] =
'__TICKET_SEVERITY__';
10373 $substitutionarray[
'__TICKET_CATEGORY__'] =
'__TICKET_CATEGORY__';
10374 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
'__TICKET_ANALYTIC_CODE__';
10375 $substitutionarray[
'__TICKET_MESSAGE__'] =
'__TICKET_MESSAGE__';
10376 $substitutionarray[
'__TICKET_PROGRESSION__'] =
'__TICKET_PROGRESSION__';
10377 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
'__TICKET_USER_ASSIGN__';
10379 if (
isModEnabled(
'recruitment') && (!is_object(
$object) ||
$object->element ==
'recruitmentcandidature') && (empty($exclude) || !in_array(
'recruitment', $exclude)) && (empty($include) || in_array(
'recruitment', $include))) {
10380 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
'__CANDIDATE_FULLNAME__';
10381 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] =
'__CANDIDATE_FIRSTNAME__';
10382 $substitutionarray[
'__CANDIDATE_LASTNAME__'] =
'__CANDIDATE_LASTNAME__';
10384 if (
isModEnabled(
'holiday') && (!is_object(
$object) ||
$object->element ==
'holiday') && (empty($exclude) || !in_array(
'holiday', $exclude)) && (empty($include) || in_array(
'holiday', $include))) {
10385 $substitutionarray[
'__HOLIDAY_ARRAY_PER_EMPLOYEE_FOR_PERIOD__'] =
'__HOLIDAY_ARRAY_PER_EMPLOYEE_FOR_PERIOD__';
10387 if (
isModEnabled(
'project') && (empty($exclude) || !in_array(
'project', $exclude)) && (empty($include) || in_array(
'project', $include))) {
10388 $substitutionarray[
'__PROJECT_ID__'] =
'__PROJECT_ID__';
10389 $substitutionarray[
'__PROJECT_REF__'] =
'__PROJECT_REF__';
10390 $substitutionarray[
'__PROJECT_NAME__'] =
'__PROJECT_NAME__';
10394 if (
isModEnabled(
'contract') && (!is_object(
$object) ||
$object->element ==
'contract') && (empty($exclude) || !in_array(
'contract', $exclude)) && (empty($include) || in_array(
'contract', $include))) {
10395 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
'Highest date planned for a service start';
10396 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
'Highest date and hour planned for service start';
10397 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
'Lowest data for planned expiration of service';
10398 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
'Lowest date and hour for planned expiration of service';
10400 if (
isModEnabled(
"propal") && (!is_object(
$object) ||
$object->element ==
'propal') && (empty($exclude) || !in_array(
'propal', $exclude)) && (empty($include) || in_array(
'propal', $include))) {
10401 $substitutionarray[
'__ONLINE_SIGN_URL__'] =
'ToOfferALinkForOnlineSignature';
10403 if (
isModEnabled(
"intervention") && (!is_object(
$object) ||
$object->element ==
'fichinter') && (empty($exclude) || !in_array(
'intervention', $exclude)) && (empty($include) || in_array(
'intervention', $include))) {
10404 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] =
'ToOfferALinkForOnlineSignature';
10406 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] =
'UrlToPayOnlineIfApplicable';
10407 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'TextAndUrlToPayOnlineIfApplicable';
10408 $substitutionarray[
'__SECUREKEYPAYMENT__'] =
'Security key (if key is not unique per record)';
10409 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
'Security key for payment on a member subscription (one key per member)';
10410 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
'Security key for payment on an order';
10411 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
'Security key for payment on an invoice';
10412 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
'Security key for payment on a service of a contract';
10414 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'Direct download url of a proposal';
10415 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'Direct download url of an order';
10416 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'Direct download url of an invoice';
10417 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'Direct download url of a contract';
10418 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'Direct download url of a supplier proposal';
10419 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_ORDER__'] =
'Direct download url of a supplier order';
10420 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_INVOICE__'] =
'Direct download url of a supplier invoice';
10423 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
'Shipping tracking number';
10424 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
'Shipping tracking url';
10425 $substitutionarray[
'__SHIPPINGMETHOD__'] =
'Shipping method';
10428 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
'Shipping tracking number of shipment';
10429 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
'Shipping tracking url';
10432 '@phan-var-force Adherent|Delivery $object';
10434 $substitutionarray[
'__ID__'] =
$object->id;
10435 $substitutionarray[
'__REF__'] =
$object->ref;
10436 $substitutionarray[
'__NEWREF__'] =
$object->newref;
10438 $substitutionarray[
'__REF_CLIENT__'] = (isset(
$object->ref_client) ?
$object->ref_client : (isset(
$object->ref_customer) ?
$object->ref_customer :
null));
10439 $substitutionarray[
'__REF_SUPPLIER__'] = (isset(
$object->ref_supplier) ?
$object->ref_supplier :
null);
10440 $substitutionarray[
'__NOTE_PUBLIC__'] = (isset(
$object->note_public) ?
$object->note_public :
null);
10441 $substitutionarray[
'__NOTE_PRIVATE__'] = (isset(
$object->note_private) ?
$object->note_private :
null);
10443 $substitutionarray[
'__DATE_CREATION__'] = (isset(
$object->date_creation) ?
dol_print_date(
$object->date_creation,
'day',
false, $outputlangs) :
'');
10444 $substitutionarray[
'__DATE_MODIFICATION__'] = (isset(
$object->date_modification) ?
dol_print_date(
$object->date_modification,
'day',
false, $outputlangs) :
'');
10445 $substitutionarray[
'__DATE_VALIDATION__'] = (isset(
$object->date_validation) ?
dol_print_date(
$object->date_validation,
'day',
false, $outputlangs) :
'');
10448 $date_delivery =
null;
10449 if (property_exists(
$object,
'date_delivery')) {
10450 $date_delivery =
$object->date_delivery;
10451 } elseif (property_exists(
$object,
'delivery_date')) {
10452 $date_delivery =
$object->delivery_date;
10454 $substitutionarray[
'__DATE_DELIVERY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
'day',
false, $outputlangs) :
'');
10455 $substitutionarray[
'__DATE_DELIVERY_DAY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%d") :
'');
10456 $substitutionarray[
'__DATE_DELIVERY_DAY_TEXT__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%A") :
'');
10457 $substitutionarray[
'__DATE_DELIVERY_MON__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%m") :
'');
10458 $substitutionarray[
'__DATE_DELIVERY_MON_TEXT__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%b") :
'');
10459 $substitutionarray[
'__DATE_DELIVERY_YEAR__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%Y") :
'');
10460 $substitutionarray[
'__DATE_DELIVERY_HH__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%H") :
'');
10461 $substitutionarray[
'__DATE_DELIVERY_MM__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%M") :
'');
10462 $substitutionarray[
'__DATE_DELIVERY_SS__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
"%S") :
'');
10465 $substitutionarray[
'__REFCLIENT__'] = (isset(
$object->ref_client) ?
$object->ref_client : (isset(
$object->ref_customer) ?
$object->ref_customer :
null));
10466 $substitutionarray[
'__REFSUPPLIER__'] = (isset(
$object->ref_supplier) ?
$object->ref_supplier :
null);
10468 $substitutionarray[
'__SUPPLIER_ORDER_DATE_DELIVERY__'] = (isset($date_delivery) ?
dol_print_date($date_delivery,
'day',
false, $outputlangs) :
'');
10469 $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 :
'')) :
'');
10473 '@phan-var-force Adherent $object';
10477 $substitutionarray[
'__MEMBER_ID__'] = (isset(
$object->id) ?
$object->id :
'');
10478 if (method_exists(
$object,
'getCivilityLabel')) {
10479 $substitutionarray[
'__MEMBER_TITLE__'] =
$object->getCivilityLabel();
10481 $substitutionarray[
'__MEMBER_FIRSTNAME__'] = (isset(
$object->firstname) ?
$object->firstname :
'');
10482 $substitutionarray[
'__MEMBER_LASTNAME__'] = (isset(
$object->lastname) ?
$object->lastname :
'');
10483 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'';
10484 if (method_exists(
$object,
'getFullName')) {
10485 $substitutionarray[
'__MEMBER_FULLNAME__'] =
$object->getFullName($outputlangs);
10487 $substitutionarray[
'__MEMBER_COMPANY__'] = (isset(
$object->societe) ?
$object->societe :
'');
10488 $substitutionarray[
'__MEMBER_ADDRESS__'] = (isset(
$object->address) ?
$object->address :
'');
10489 $substitutionarray[
'__MEMBER_ZIP__'] = (isset(
$object->zip) ?
$object->zip :
'');
10490 $substitutionarray[
'__MEMBER_TOWN__'] = (isset(
$object->town) ?
$object->town :
'');
10491 $substitutionarray[
'__MEMBER_STATE__'] = (isset(
$object->state) ?
$object->state :
'');
10492 $substitutionarray[
'__MEMBER_COUNTRY__'] = (isset(
$object->country) ?
$object->country :
'');
10493 $substitutionarray[
'__MEMBER_EMAIL__'] = (isset(
$object->email) ?
$object->email :
'');
10494 $substitutionarray[
'__MEMBER_BIRTH__'] = (isset($birthday) ? $birthday :
'');
10495 $substitutionarray[
'__MEMBER_PHOTO__'] = (isset(
$object->photo) ?
$object->photo :
'');
10496 $substitutionarray[
'__MEMBER_LOGIN__'] = (isset(
$object->login) ?
$object->login :
'');
10497 $substitutionarray[
'__MEMBER_PASSWORD__'] = (isset(
$object->pass) ?
$object->pass :
'');
10501 $substitutionarray[
'__MEMBER_TYPE__'] = (isset(
$object->type) ?
$object->type :
'');
10502 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE__'] =
dol_print_date(
$object->first_subscription_date,
'day');
10504 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_RFC__'] =
dol_print_date(
$object->first_subscription_date,
'dayrfc');
10505 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START__'] = (isset(
$object->first_subscription_date_start) ?
dol_print_date(
$object->first_subscription_date_start,
'day') :
'');
10506 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START_RFC__'] = (isset(
$object->first_subscription_date_start) ?
dol_print_date(
$object->first_subscription_date_start,
'dayrfc') :
'');
10507 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END__'] = (isset(
$object->first_subscription_date_end) ?
dol_print_date(
$object->first_subscription_date_end,
'day') :
'');
10508 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END_RFC__'] = (isset(
$object->first_subscription_date_end) ?
dol_print_date(
$object->first_subscription_date_end,
'dayrfc') :
'');
10509 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE__'] =
dol_print_date(
$object->last_subscription_date,
'day');
10510 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_RFC__'] =
dol_print_date(
$object->last_subscription_date,
'dayrfc');
10511 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START__'] =
dol_print_date(
$object->last_subscription_date_start,
'day');
10512 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START_RFC__'] =
dol_print_date(
$object->last_subscription_date_start,
'dayrfc');
10513 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END__'] =
dol_print_date(
$object->last_subscription_date_end,
'day');
10514 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END_RFC__'] =
dol_print_date(
$object->last_subscription_date_end,
'dayrfc');
10519 '@phan-var-force Societe $object';
10520 $substitutionarray[
'__THIRDPARTY_ID__'] =
$object->id ??
'';
10521 $substitutionarray[
'__THIRDPARTY_NAME__'] =
$object->name ??
'';
10522 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
$object->name_alias ??
'';
10523 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
$object->code_client ??
'';
10524 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
$object->code_fournisseur ??
'';
10525 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
$object->email ??
'';
10526 $substitutionarray[
'__THIRDPARTY_EMAIL_URLENCODED__'] = urlencode(
$object->email ??
'');
10527 $substitutionarray[
'__THIRDPARTY_URL__'] =
$object->url ??
'';
10528 $substitutionarray[
'__THIRDPARTY_URL_URLENCODED__'] = urlencode(
$object->url ??
'');
10531 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
$object->address ??
'';
10532 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
$object->zip ??
'';
10533 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
$object->town ??
'';
10534 $substitutionarray[
'__THIRDPARTY_STATE__'] =
$object->state ??
'';
10535 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (
$object->country_id > 0 ?:
'');
10536 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] =
$object->country_code ??
'';
10537 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
$object->idprof1 ??
'';
10538 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
$object->idprof2 ??
'';
10539 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
$object->idprof3 ??
'';
10540 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
$object->idprof4 ??
'';
10541 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
$object->idprof5 ??
'';
10542 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
$object->idprof6 ??
'';
10543 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
$object->tva_intra ??
'';
10546 } elseif (is_object(
$object) && is_object(
$object->thirdparty)) {
10547 $substitutionarray[
'__THIRDPARTY_ID__'] =
$object->thirdparty->id ??
'';
10548 $substitutionarray[
'__THIRDPARTY_NAME__'] =
$object->thirdparty->name ??
'';
10549 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
$object->thirdparty->name_alias ??
'';
10550 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
$object->thirdparty->code_client ??
'';
10551 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
$object->thirdparty->code_fournisseur ??
'';
10552 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
$object->thirdparty->email ??
'';
10553 $substitutionarray[
'__THIRDPARTY_EMAIL_URLENCODED__'] = urlencode(
$object->thirdparty->email ??
'');
10556 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
$object->thirdparty->address ??
'';
10557 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
$object->thirdparty->zip ??
'';
10558 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
$object->thirdparty->town ??
'';
10559 $substitutionarray[
'__THIRDPARTY_STATE__'] =
$object->thirdparty->state ??
'';
10560 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (
$object->thirdparty->country_id > 0 ?:
'');
10561 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] =
$object->thirdparty->country_code ??
'';
10562 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
$object->thirdparty->idprof1 ??
'';
10563 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
$object->thirdparty->idprof2 ??
'';
10564 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
$object->thirdparty->idprof3 ??
'';
10565 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
$object->thirdparty->idprof4 ??
'';
10566 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
$object->thirdparty->idprof5 ??
'';
10567 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
$object->thirdparty->idprof6 ??
'';
10568 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
$object->thirdparty->tva_intra ??
'';
10573 if (is_object(
$object) &&
$object->element ==
'recruitmentcandidature') {
10574 '@phan-var-force RecruitmentCandidature $object';
10576 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
$object->getFullName($outputlangs);
10577 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] = isset(
$object->firstname) ?
$object->firstname :
'';
10578 $substitutionarray[
'__CANDIDATE_LASTNAME__'] = isset(
$object->lastname) ?
$object->lastname :
'';
10580 if (is_object(
$object) &&
$object->element ==
'conferenceorboothattendee') {
10581 '@phan-var-force ConferenceOrBoothAttendee $object';
10583 $substitutionarray[
'__ATTENDEE_FULLNAME__'] =
$object->getFullName($outputlangs);
10584 $substitutionarray[
'__ATTENDEE_FIRSTNAME__'] = isset(
$object->firstname) ?
$object->firstname :
'';
10585 $substitutionarray[
'__ATTENDEE_LASTNAME__'] = isset(
$object->lastname) ?
$object->lastname :
'';
10589 '@phan-var-force Project $object';
10591 $substitutionarray[
'__PROJECT_ID__'] =
$object->id;
10592 $substitutionarray[
'__PROJECT_REF__'] =
$object->ref;
10593 $substitutionarray[
'__PROJECT_NAME__'] =
$object->title;
10594 } elseif (is_object(
$object)) {
10596 if (!empty(
$object->project)) {
10599 if (!is_null($project) && is_object($project)) {
10600 $substitutionarray[
'__PROJECT_ID__'] = $project->id;
10601 $substitutionarray[
'__PROJECT_REF__'] = $project->ref;
10602 $substitutionarray[
'__PROJECT_NAME__'] = $project->title;
10607 $project_id =
$object->fk_project;
10608 } elseif (!empty(
$object->fk_projet) &&
$object->fk_projet > 0) {
10609 $project_id =
$object->fk_project;
10611 if ($project_id > 0) {
10613 $substitutionarray[
'__PROJECT_ID__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
10614 $substitutionarray[
'__PROJECT_REF__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
10615 $substitutionarray[
'__PROJECT_NAME__@lazyload'] =
'/projet/class/project.class.php:Project:fetchAndSetSubstitution:' . $project_id;
10621 '@phan-var-force Facture $object';
10623 $substitutionarray[
'__INVOICE_SITUATION_NUMBER__'] = isset(
$object->situation_counter) ?
$object->situation_counter :
'';
10626 '@phan-var-force Expedition $object';
10628 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
$object->tracking_number;
10629 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
$object->tracking_url;
10630 $substitutionarray[
'__SHIPPINGMETHOD__'] =
$object->shipping_method;
10633 '@phan-var-force Reception $object';
10635 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
$object->tracking_number;
10636 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
$object->tracking_url;
10640 '@phan-var-force Contrat $object';
10642 $dateplannedstart =
'';
10643 $datenextexpiration =
'';
10644 foreach (
$object->lines as $line) {
10645 if ($line->date_start > $dateplannedstart) {
10646 $dateplannedstart = $line->date_start;
10648 if ($line->statut == 4 && $line->date_end && (!$datenextexpiration || $line->date_end < $datenextexpiration)) {
10649 $datenextexpiration = $line->date_end;
10652 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
dol_print_date($dateplannedstart,
'day');
10653 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE_RFC__'] =
dol_print_date($dateplannedstart,
'dayrfc');
10654 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
dol_print_date($dateplannedstart,
'standard');
10656 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
dol_print_date($datenextexpiration,
'day');
10657 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE_RFC__'] =
dol_print_date($datenextexpiration,
'dayrfc');
10658 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
dol_print_date($datenextexpiration,
'standard');
10662 '@phan-var-force Ticket $object';
10664 $substitutionarray[
'__TICKET_TRACKID__'] =
$object->track_id;
10665 $substitutionarray[
'__TICKET_SUBJECT__'] =
$object->subject;
10666 $substitutionarray[
'__TICKET_TYPE__'] =
$object->type_code;
10667 $substitutionarray[
'__TICKET_SEVERITY__'] =
$object->severity_code;
10668 $substitutionarray[
'__TICKET_CATEGORY__'] =
$object->category_code;
10669 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
$object->category_code;
10670 $substitutionarray[
'__TICKET_MESSAGE__'] =
$object->message;
10671 $substitutionarray[
'__TICKET_PROGRESSION__'] =
$object->progress;
10673 if (
$object->fk_user_assign > 0) {
10674 $userstat->fetch(
$object->fk_user_assign);
10675 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
10678 if (
$object->fk_user_create > 0) {
10679 $userstat->fetch(
$object->fk_user_create);
10680 $substitutionarray[
'__USER_CREATE__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
10686 if (!is_object($extrafields)) {
10689 $extrafields->fetch_name_optionals_label(
$object->table_element,
true);
10691 if (
$object->fetch_optionals() > 0) {
10692 if (is_array($extrafields->attributes[
$object->table_element][
'label']) && count($extrafields->attributes[
$object->table_element][
'label']) > 0) {
10693 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $label) {
10694 if ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'date') {
10695 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'day');
10696 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_LOCALE__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'day',
'tzserver', $outputlangs);
10697 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_RFC__'] =
dol_print_date(
$object->array_options[
'options_' . $key],
'dayrfc');
10698 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'datetime') {
10699 $datetime =
$object->array_options[
'options_' . $key];
10700 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour') :
'');
10701 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour',
'tzserver', $outputlangs) :
'');
10702 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_DAY_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'day',
'tzserver', $outputlangs) :
'');
10703 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_RFC__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhourrfc') :
'');
10704 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'phone') {
10705 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
dol_print_phone(
$object->array_options[
'options_' . $key]);
10706 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'price') {
10707 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] =
$object->array_options[
'options_' . $key];
10708 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_FORMATED__'] =
price(
$object->array_options[
'options_' . $key]);
10709 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'_FORMATTED__'] =
price(
$object->array_options[
'options_' . $key]);
10710 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] ==
'select') {
10711 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = !empty(
$object->array_options[
'options_' . $key]) ?
$object->array_options[
'options_' . $key] :
'';
10712 $val = $extrafields->attributes[
$object->table_element][
'param'][$key][
'options'][
$object->array_options[
'options_'.$key]] ??
$object->array_options[
'options_'.$key];
10713 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_LABEL__'] = $val;
10714 } elseif ($extrafields->attributes[
$object->table_element][
'type'][$key] !=
'separator') {
10715 $substitutionarray[
'__EXTRAFIELD_' . strtoupper($key) .
'__'] = !empty(
$object->array_options[
'options_' . $key]) ?
$object->array_options[
'options_' . $key] :
'';
10723 if (empty($substitutionarray[
'__REF__'])) {
10727 require_once DOL_DOCUMENT_ROOT .
'/core/lib/payments.lib.php';
10728 $outputlangs->loadLangs(array(
'paypal',
'other'));
10731 $typeforonlinepayment =
'free';
10733 $typeforonlinepayment =
'order';
10736 $typeforonlinepayment =
'invoice';
10739 $typeforonlinepayment =
'member';
10740 if (!empty(
$object->last_subscription_amount)) {
10741 $amounttouse =
$object->last_subscription_amount;
10745 $typeforonlinepayment =
'contract';
10748 $typeforonlinepayment =
'ficheinter';
10751 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $substitutionarray[
'__REF__'], (
float) $amounttouse);
10752 $paymenturl = $url;
10756 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = ($paymenturl ? str_replace(
'\n',
"\n", $outputlangs->trans(
"PredefinedMailContentLink", $paymenturl)) :
'');
10757 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
10761 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions_be.lib.php';
10766 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
$object->getLastMainDocLink(
$object->element);
10768 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'';
10771 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
$object->getLastMainDocLink(
$object->element);
10773 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'';
10776 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
$object->getLastMainDocLink(
$object->element);
10778 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'';
10781 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
$object->getLastMainDocLink(
$object->element);
10783 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'';
10786 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
$object->getLastMainDocLink(
$object->element);
10788 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
'';
10791 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
$object->getLastMainDocLink(
$object->element);
10793 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'';
10796 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_ORDER__'] =
$object->getLastMainDocLink(
$object->element);
10798 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_ORDER__'] =
'';
10801 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_INVOICE__'] =
$object->getLastMainDocLink(
$object->element);
10803 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_INVOICE__'] =
'';
10807 '@phan-var-force Propal $object';
10809 $substitutionarray[
'__URL_PROPOSAL__'] = DOL_MAIN_URL_ROOT .
"/comm/propal/card.php?id=" .
$object->id;
10810 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
10811 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'proposal', (
string)
$object->ref, 1,
$object);
10814 '@phan-var-force Commande $object';
10816 $substitutionarray[
'__URL_ORDER__'] = DOL_MAIN_URL_ROOT .
"/commande/card.php?id=" .
$object->id;
10819 '@phan-var-force Facture $object';
10821 $substitutionarray[
'__URL_INVOICE__'] = DOL_MAIN_URL_ROOT .
"/compta/facture/card.php?id=" .
$object->id;
10824 '@phan-var-force Contrat $object';
10826 $substitutionarray[
'__URL_CONTRACT__'] = DOL_MAIN_URL_ROOT .
"/contrat/card.php?id=" .
$object->id;
10827 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
10828 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'contract', (
string)
$object->ref, 1,
$object);
10831 '@phan-var-force Fichinter $object';
10833 $substitutionarray[
'__URL_FICHINTER__'] = DOL_MAIN_URL_ROOT .
"/fichinter/card.php?id=" .
$object->id;
10834 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
10835 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] = getOnlineSignatureUrl(0,
'fichinter', (
string)
$object->ref, 1,
$object);
10837 if (is_object(
$object) &&
$object->element ==
'supplier_proposal') {
10838 '@phan-var-force SupplierProposal $object';
10840 $substitutionarray[
'__URL_SUPPLIER_PROPOSAL__'] = DOL_MAIN_URL_ROOT .
"/supplier_proposal/card.php?id=" .
$object->id;
10842 if (is_object(
$object) &&
$object->element ==
'invoice_supplier') {
10843 '@phan-var-force FactureFournisseur $object';
10845 $substitutionarray[
'__URL_SUPPLIER_INVOICE__'] = DOL_MAIN_URL_ROOT .
"/fourn/facture/card.php?id=" .
$object->id;
10847 if (is_object(
$object) &&
$object->element ==
'payment_supplier') {
10848 '@phan-var-force PaiementFourn $object';
10851 $liste_factures = [];
10855 $sql =
'SELECT f.ref,f.multicurrency_code as f_mccode, pf.*
10856 FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn as pf
10857 JOIN '.MAIN_DB_PREFIX.
'facture_fourn as f ON pf.fk_facturefourn = f.rowid
10858 WHERE pf.fk_paiementfourn = '.((int)
$object->id);
10860 $resql =
$db->query($sql);
10862 while ($objp =
$db->fetch_object($resql)) {
10863 $liste_factures[] =
' - '.$outputlangs->trans(
'Invoice').
' '. $objp->ref.
' '.$outputlangs->trans(
'AmountPayed').
' '.
price($objp->multicurrency_amount, 0, $outputlangs, 0, -1, -1, $objp->multicurrency_code);
10866 $substitutionarray[
'__SUPPLIER_PAYMENT_INVOICES_LIST__'] = implode(
"\n", $liste_factures);
10868 $substitutionarray[
'__SUPPLIER_PAYMENT_INVOICES_TOTAL__'] =
price(
$object->multicurrency_amount, 0, $outputlangs, 0, -1, -1,
$object->multicurrency_code ?
$object->multicurrency_code :
$conf->currency);
10871 '@phan-var-force Expedition $object';
10873 $substitutionarray[
'__URL_SHIPMENT__'] = DOL_MAIN_URL_ROOT .
"/expedition/card.php?id=" .
$object->id;
10875 require_once DOL_DOCUMENT_ROOT .
'/core/lib/signature.lib.php';
10876 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'expedition', (
string)
$object->ref, 1,
$object);
10882 '@phan-var-force ActionComm $object';
10884 $substitutionarray[
'__EVENT_LABEL__'] =
$object->label;
10885 $substitutionarray[
'__EVENT_DESCRIPTION__'] =
$object->note;
10886 $substitutionarray[
'__EVENT_TYPE__'] = $outputlangs->trans(
"Action" .
$object->type_code);
10887 $substitutionarray[
'__EVENT_DATE__'] =
dol_print_date(
$object->datep,
'day',
'auto', $outputlangs);
10888 $substitutionarray[
'__EVENT_TIME__'] =
dol_print_date(
$object->datep,
'hour',
'auto', $outputlangs);
10889 $substitutionarray[
'__EVENT_DATE_TZUSER__'] =
dol_print_date(
$object->datep,
'day',
'tzuserrel', $outputlangs);
10890 $substitutionarray[
'__EVENT_TIME_TZUSER__'] =
dol_print_date(
$object->datep,
'hour',
'tzuserrel', $outputlangs);
10895 if ((empty($exclude) || !in_array(
'objectamount', $exclude)) && (empty($include) || in_array(
'objectamount', $include))) {
10896 '@phan-var-force Facture|FactureRec $object';
10898 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functionsnumtoword.lib.php';
10901 $substitutionarray[
'__DATE_DUE_YMD__'] = is_object(
$object) ? (isset(
$object->date_lim_reglement) ?
dol_print_date(
$object->date_lim_reglement,
'day',
false, $outputlangs) : null) :
'';
10903 $substitutionarray[
'__DATE_DUE_YMD_TEXT__'] = is_object(
$object) ? (isset(
$object->date_lim_reglement) ?
dol_print_date(
$object->date_lim_reglement,
'daytext',
false, $outputlangs) : null) :
'';
10905 $already_payed_all = 0;
10911 $substitutionarray[
'__AMOUNT_EXCL_TAX__'] = is_object(
$object) ?
$object->total_ht :
'';
10915 $substitutionarray[
'__AMOUNT__'] = is_object(
$object) ?
$object->total_ttc :
'';
10919 $substitutionarray[
'__DEPOSIT_PERCENT__'] = is_object(
$object) ?
$object->deposit_percent :
'';
10922 $substitutionarray[
'__AMOUNT_REMAIN__'] = is_object(
$object) ?
price2num(
$object->total_ttc - $already_payed_all,
'MT') :
'';
10924 $substitutionarray[
'__AMOUNT_VAT__'] = is_object(
$object) ? (isset(
$object->total_vat) ?
$object->total_vat :
$object->total_tva) :
'';
10928 $mysocuselocaltax1 =
false;
10929 $mysocuselocaltax2 =
false;
10931 $tmparray =
$mysoc->useLocalTax(-1);
10932 $mysocuselocaltax1 = $tmparray[1];
10933 $mysocuselocaltax2 = $tmparray[2];
10937 if ($onlykey != 2 || $mysocuselocaltax1) {
10938 $substitutionarray[
'__AMOUNT_TAX2__'] = is_object(
$object) ?
$object->total_localtax1 :
'';
10940 if ($onlykey != 2 || $mysocuselocaltax2) {
10941 $substitutionarray[
'__AMOUNT_TAX3__'] = is_object(
$object) ?
$object->total_localtax2 :
'';
10945 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATTED__'] = is_object(
$object) ? (
$object->total_ht ?
price(
$object->total_ht, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
10946 $substitutionarray[
'__AMOUNT_FORMATTED__'] = is_object(
$object) ? (
$object->total_ttc ?
price(
$object->total_ttc, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
10947 $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) :
'';
10948 $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)) :
'';
10949 if ($onlykey != 2 || $mysocuselocaltax1) {
10950 $substitutionarray[
'__AMOUNT_TAX2_FORMATTED__'] = is_object(
$object) ? (
$object->total_localtax1 ?
price(
$object->total_localtax1, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
10952 if ($onlykey != 2 || $mysocuselocaltax2) {
10953 $substitutionarray[
'__AMOUNT_TAX3_FORMATTED__'] = is_object(
$object) ? (
$object->total_localtax2 ?
price(
$object->total_localtax2, 0, $outputlangs, 0, -1, -1,
$conf->currency) : null) :
'';
10956 if ($onlykey != 2) {
10957 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATED__'] = $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATTED__'];
10958 $substitutionarray[
'__AMOUNT_FORMATED__'] = $substitutionarray[
'__AMOUNT_FORMATTED__'];
10959 $substitutionarray[
'__AMOUNT_REMAIN_FORMATED__'] = $substitutionarray[
'__AMOUNT_REMAIN_FORMATTED__'];
10960 $substitutionarray[
'__AMOUNT_VAT_FORMATED__'] = $substitutionarray[
'__AMOUNT_VAT_FORMATTED__'];
10961 if ($mysocuselocaltax1) {
10962 $substitutionarray[
'__AMOUNT_TAX2_FORMATED__'] = $substitutionarray[
'__AMOUNT_TAX2_FORMATTED__'];
10964 if (
$mysoc->useLocalTax2) {
10965 $substitutionarray[
'__AMOUNT_TAX3_FORMATED__'] = $substitutionarray[
'__AMOUNT_TAX3_FORMATTED__'];
10969 $substitutionarray[
'__AMOUNT_MULTICURRENCY__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
$object->multicurrency_total_ttc :
'';
10970 $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) :
'';
10971 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXT__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
dol_convertToWord(
$object->multicurrency_total_ttc, $outputlangs,
'',
true) :
'';
10972 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXTCURRENCY__'] = (is_object(
$object) && isset(
$object->multicurrency_total_ttc)) ?
dol_convertToWord(
$object->multicurrency_total_ttc, $outputlangs,
$object->multicurrency_code,
true) :
'';
10973 $substitutionarray[
'__MULTICURRENCY_CODE__'] = (is_object(
$object) && isset(
$object->multicurrency_code)) ?
$object->multicurrency_code :
'';
10977 if ($onlykey != 2) {
10978 $substitutionarray[
'__TOTAL_TTC__'] = is_object(
$object) ?
$object->total_ttc :
'';
10979 $substitutionarray[
'__TOTAL_HT__'] = is_object(
$object) ?
$object->total_ht :
'';
10980 $substitutionarray[
'__TOTAL_VAT__'] = is_object(
$object) ? (isset(
$object->total_vat) ?
$object->total_vat :
$object->total_tva) :
'';
10985 if ((empty($exclude) || !in_array(
'date', $exclude)) && (empty($include) || in_array(
'date', $include))) {
10986 include_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
10996 $daytext = $outputlangs->trans(
'Day' . $tmp[
'wday']);
10998 $substitutionarray = array_merge($substitutionarray, array(
10999 '__NOW_TMS__' => (
string) $now,
11000 '__NOW_TMS_YMD__' =>
dol_print_date($now,
'day',
'auto', $outputlangs),
11001 '__DAY__' => (
string) $tmp[
'mday'],
11002 '__DAY_TEXT__' => $daytext,
11003 '__DAY_TEXT_SHORT__' =>
dol_trunc($daytext, 3,
'right',
'UTF-8', 1),
11004 '__DAY_TEXT_MIN__' =>
dol_trunc($daytext, 1,
'right',
'UTF-8', 1),
11005 '__MONTH__' => (
string) $tmp[
'mon'],
11006 '__MONTH_TEXT__' => $outputlangs->transnoentitiesnoconv(
'Month' . sprintf(
"%02d", $tmp[
'mon'])),
11007 '__MONTH_TEXT_SHORT__' => $outputlangs->transnoentitiesnoconv(
'MonthShort' . sprintf(
"%02d", $tmp[
'mon'])),
11008 '__MONTH_TEXT_MIN__' => $outputlangs->transnoentitiesnoconv(
'MonthVeryShort' . sprintf(
"%02d", $tmp[
'mon'])),
11009 '__YEAR__' => (
string) $tmp[
'year'],
11010 '__YEAR_PREVIOUS_MONTH__' => (
string) $tmp3[
'year'],
11011 '__YEAR_NEXT_MONTH__' => (
string) $tmp5[
'year'],
11012 '__PREVIOUS_DAY__' => (
string) $tmp2[
'day'],
11013 '__PREVIOUS_MONTH__' => (
string) $tmp3[
'month'],
11014 '__PREVIOUS_MONTH_TEXT__' => $outputlangs->transnoentitiesnoconv(
'Month' . sprintf(
"%02d", $tmp3[
'month'])),
11015 '__PREVIOUS_MONTH_TEXT_SHORT__' => $outputlangs->transnoentitiesnoconv(
'MonthShort' . sprintf(
"%02d", $tmp3[
'month'])),
11016 '__PREVIOUS_MONTH_TEXT_MIN__' => $outputlangs->transnoentitiesnoconv(
'MonthVeryShort' . sprintf(
"%02d", $tmp3[
'month'])),
11017 '__PREVIOUS_YEAR__' => (
string) ($tmp[
'year'] - 1),
11018 '__NEXT_DAY__' => (
string) $tmp4[
'day'],
11019 '__NEXT_MONTH__' => (
string) $tmp5[
'month'],
11020 '__NEXT_MONTH_TEXT__' => $outputlangs->transnoentitiesnoconv(
'Month' . sprintf(
"%02d", $tmp5[
'month'])),
11021 '__NEXT_MONTH_TEXT_SHORT__' => $outputlangs->transnoentitiesnoconv(
'MonthShort' . sprintf(
"%02d", $tmp5[
'month'])),
11022 '__NEXT_MONTH_TEXT_MIN__' => $outputlangs->transnoentitiesnoconv(
'MonthVeryShort' . sprintf(
"%02d", $tmp5[
'month'])),
11023 '__NEXT_YEAR__' => (
string) ($tmp[
'year'] + 1),
11028 $substitutionarray = array_merge($substitutionarray, array(
'__ENTITY_ID__' =>
$conf->entity));
11030 if ((empty($exclude) || !in_array(
'system', $exclude)) && (empty($include) || in_array(
'user', $include))) {
11031 $substitutionarray[
'__DOL_MAIN_URL_ROOT__'] = DOL_MAIN_URL_ROOT;
11032 $substitutionarray[
'__(AnyTranslationKey)__'] = $outputlangs->transnoentitiesnoconv(
'TranslationOfKey');
11033 $substitutionarray[
'__(AnyTranslationKey|langfile)__'] = $outputlangs->transnoentitiesnoconv(
'TranslationOfKey') .
' (load also language file before)';
11034 $substitutionarray[
'__[AnyConstantKey]__'] = $outputlangs->transnoentitiesnoconv(
'ValueOfConstantKey');
11039 return $substitutionarray;
11058function make_substitutions($text, $substitutionarray, $outputlangs =
null, $converttextinhtmlifnecessary = 0)
11060 global
$db, $langs;
11062 if (!is_array($substitutionarray)) {
11063 return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
11066 if (empty($outputlangs)) {
11067 $outputlangs = $langs;
11077 if (is_object($outputlangs)) {
11079 while (preg_match(
'/__\(([^\)]+)\)__/', $text, $reg)) {
11081 $tmp = explode(
'|', $reg[1]);
11082 if (!empty($tmp[1])) {
11083 $outputlangs->load($tmp[1]);
11086 $value = $outputlangs->transnoentitiesnoconv($reg[1]);
11088 if (empty($converttextinhtmlifnecessary)) {
11090 $text = preg_replace(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
11092 if (preg_match(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $text)) {
11093 if (! $msgishtml) {
11097 if ($valueishtml) {
11105 $text = preg_replace(
'/__\(' . preg_quote($reg[1],
'/') .
'\)__/', $value, $text);
11113 while (preg_match(
'/__\[([^\]]+)\]__/', $text, $reg)) {
11114 $originalkeyfound = $reg[1];
11115 $keyfound = preg_replace(
'/\|urlencode$/',
'', $originalkeyfound);
11118 $value =
'*****forbidden*****';
11122 if (preg_match(
'/\|urlencode$/', $originalkeyfound)) {
11123 $value = urlencode($value);
11127 if (empty($converttextinhtmlifnecessary)) {
11129 $text = preg_replace(
'/__\[' . preg_quote($originalkeyfound,
'/') .
'\]__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
11131 if (preg_match(
'/__\[' . preg_quote($reg[1],
'/') .
'\]__/', $text)) {
11132 if (! $msgishtml) {
11135 if ($valueishtml) {
11143 $text = preg_replace(
'/__\[' . preg_quote($originalkeyfound,
'/') .
'\]__/', $value, $text);
11148 foreach ($substitutionarray as $key => $value) {
11149 if (!isset($value)) {
11153 if (
getDolGlobalString(
'MAIN_MAIL_DO_NOT_USE_SIGN') && ($key ==
'__USER_SIGNATURE__' || $key ==
'__SENDEREMAIL_SIGNATURE__')) {
11156 if (empty($converttextinhtmlifnecessary)) {
11157 $text = str_replace((
string) $key, (
string) $value, $text);
11159 if (strpos($text, (
string) $key) !==
false) {
11160 if (! $msgishtml) {
11163 if ($valueishtml) {
11171 $text = str_replace((
string) $key, (
string) $value, $text);
11186 $memory_object_list = array();
11187 foreach ($substitutionarray as $key => $value) {
11188 $lazy_load_arr = array();
11189 if (preg_match(
'/(__[A-Z\_]+__)@lazyload$/', $key, $lazy_load_arr)) {
11190 if (isset($lazy_load_arr[1]) && !empty($lazy_load_arr[1])) {
11191 $key_to_substitute = $lazy_load_arr[1];
11192 if (preg_match(
'/' . preg_quote($key_to_substitute,
'/') .
'/', $text)) {
11193 $param_arr = explode(
':', (
string) $value);
11195 if (count($param_arr) >= 4) {
11196 $path = $param_arr[0];
11197 $class = $param_arr[1];
11198 $method = $param_arr[2];
11199 $id = (int) $param_arr[3];
11200 $keyinarrayresult = empty($param_arr[4]) ?
'' : $param_arr[4];
11203 if (!isset($memory_object_list[$class])) {
11205 require_once DOL_DOCUMENT_ROOT . $path;
11206 if (class_exists($class)) {
11207 $memory_object_list[$class] = array(
11215 if (isset($memory_object_list[$class]) && isset($memory_object_list[$class][
'list'])) {
11216 if (method_exists($class, $method)) {
11217 if (!isset($memory_object_list[$class][
'list'][
$id])) {
11218 $tmpobj =
new $class(
$db);
11220 $tmpvaluetouseforsubstitution = $tmpobj->$method(
$id, $key_to_substitute);
11221 $memory_object_list[$class][
'list'][
$id] = $tmpobj;
11224 $tmpobj = $memory_object_list[$class][
'list'][
$id];
11226 $tmpvaluetouseforsubstitution = $tmpobj->$method(
$id, $key_to_substitute,
true);
11229 if ($keyinarrayresult) {
11230 $valuetouseforsubstitution = (
string) $tmpvaluetouseforsubstitution[$keyinarrayresult];
11232 $valuetouseforsubstitution = (
string) $tmpvaluetouseforsubstitution;
11234 $text = str_replace((
string) $key_to_substitute, $valuetouseforsubstitution, $text);
11260 global
$conf, $user;
11262 require_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
11267 $dirsubstitutions = array_merge(array(), (array)
$conf->modules_parts[
'substitutions']);
11269 foreach ($dirsubstitutions as $reldir) {
11277 $substitfiles =
dol_dir_list($dir,
'files', 0,
'functions_');
11278 foreach ($substitfiles as $substitfile) {
11280 if (preg_match(
'/functions_(.*)\.lib\.php/i', $substitfile[
'name'], $reg)) {
11283 dol_syslog(
"Library " . $substitfile[
'name'] .
" found into " . $dir);
11285 require_once $dir . $substitfile[
'name'];
11287 $function_name = $module .
"_" . $callfunc;
11288 if (function_exists($function_name)) {
11289 $function_name($substitutionarray, $outputlangs,
$object, $parameters);
11297 foreach ($substitutionarray as $key => $value) {
11298 $tags .=
'{' . $key .
'} => ' . $value .
"\n";
11300 $substitutionarray = array_merge($substitutionarray, array(
'__ALL_TAGS__' => $tags));
11334 if (!is_object($outputlangs)) {
11335 $outputlangs = $langs;
11339 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateFromTo',
dol_print_date(
$date_start, $format, false, $outputlangs),
dol_print_date($date_end, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
11342 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateFrom',
dol_print_date(
$date_start, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
11345 $out .= ($withparenthesis ? ($withparenthesis == 1 ?
' ' :
'').
'(' :
'') . $outputlangs->transnoentitiesnoconv(
'DateUntil',
dol_print_date($date_end, $format, false, $outputlangs)) . ($withparenthesis ?
')' :
'');
11363 if ($nameorder < 0) {
11366 if ($nameorder == 1) {
11367 $ret .= $firstname;
11368 if ($firstname && $lastname) {
11372 } elseif ($nameorder == 2 || $nameorder == 3) {
11373 $ret .= $firstname;
11374 if (empty($ret) && $nameorder == 3) {
11379 if (empty($ret) && $nameorder == 5) {
11380 $ret .= $firstname;
11382 if ($nameorder == 0) {
11383 if ($firstname && $lastname) {
11386 $ret .= $firstname;
11405function setEventMessage($mesgs, $style =
'mesgs', $noduplicate = 0, $attop = 0)
11408 if (!is_array($mesgs)) {
11409 $mesgs = trim((
string) $mesgs);
11412 if (!empty($noduplicate) && isset($_SESSION[
'dol_events'][$style]) && in_array($mesgs, $_SESSION[
'dol_events'][$style])) {
11416 array_unshift($_SESSION[
'dol_events'][$style], $mesgs);
11418 $_SESSION[
'dol_events'][$style][] = $mesgs;
11423 foreach ($mesgs as $mesg) {
11424 $mesg = trim((
string) $mesg);
11426 if (!empty($noduplicate) && isset($_SESSION[
'dol_events'][$style]) && in_array($mesg, $_SESSION[
'dol_events'][$style])) {
11430 array_unshift($_SESSION[
'dol_events'][$style], $mesgs);
11432 $_SESSION[
'dol_events'][$style][] = $mesg;
11452function setEventMessages($mesg, $mesgs, $style =
'mesgs', $messagekey =
'', $noduplicate = 0, $attop = 0)
11454 if (empty($mesg) && empty($mesgs)) {
11462 if (empty($messagekey) || empty($_COOKIE[
"DOLUSER_HIDEMESSAGE" . $messagekey])) {
11463 if (!in_array((
string) $style, array(
'mesgs',
'warnings',
'errors'))) {
11464 dol_print_error(
null,
'Bad parameter style=' . $style .
' for setEventMessages');
11466 if (empty($mesgs)) {
11469 if (!empty($mesg) && !in_array($mesg, $mesgs)) {
11490 if (isset($_SESSION[
'dol_events'][
'mesgs'])) {
11491 if (empty($disabledoutputofmessages)) {
11494 unset($_SESSION[
'dol_events'][
'mesgs']);
11497 if (isset($_SESSION[
'dol_events'][
'errors'])) {
11498 if (empty($disabledoutputofmessages)) {
11501 unset($_SESSION[
'dol_events'][
'errors']);
11505 if (isset($_SESSION[
'dol_events'][
'warnings'])) {
11506 if (empty($disabledoutputofmessages)) {
11509 unset($_SESSION[
'dol_events'][
'warnings']);
11527function get_htmloutput_mesg($mesgstring =
'', $mesgarray = [], $style =
'ok', $keepembedded = 0)
11529 global
$conf, $langs;
11534 $divstart = $divend =
'';
11537 if ((empty(
$conf->use_javascript_ajax) ||
getDolGlobalString(
'MAIN_DISABLE_JQUERY_JNOTIFY') || $keepembedded) && !preg_match(
'/<div class=".*">/i', $out)) {
11538 $divstart =
'<div class="' . $style .
' clearboth">';
11539 $divend =
'</div>';
11542 if ((is_array($mesgarray) && count($mesgarray)) || $mesgstring) {
11543 $langs->load(
"errors");
11545 if (is_array($mesgarray) && count($mesgarray)) {
11546 foreach ($mesgarray as $message) {
11548 $out .= $langs->trans($message);
11549 if ($ret < count($mesgarray)) {
11556 $out .= $langs->trans($mesgstring);
11562 if (!empty(
$conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_DISABLE_JQUERY_JNOTIFY') && empty($keepembedded)) {
11563 $return =
'<script nonce="' .
getNonce() .
'">
11564 $(document).ready(function() {
11565 /* jnotify(message, preset of message type, keepmessage) */
11566 $.jnotify("' .
dol_escape_js($out) .
'", "' . ($style ==
"ok" ? 3000 : $style) .
'", ' . ($style ==
"ok" ?
"false" :
"true") .
',{ remove: function (){} } );
11606function dol_htmloutput_mesg($mesgstring =
'', $mesgarray = array(), $style =
'ok', $keepembedded = 0)
11608 if (empty($mesgstring) && (!is_array($mesgarray) || count($mesgarray) == 0)) {
11614 if (is_array($mesgarray)) {
11615 foreach ($mesgarray as $val) {
11616 if ($val && preg_match(
'/class="error"/i', $val)) {
11620 if ($val && preg_match(
'/class="warning"/i', $val)) {
11625 } elseif ($mesgstring && preg_match(
'/class="error"/i', $mesgstring)) {
11627 } elseif ($mesgstring && preg_match(
'/class="warning"/i', $mesgstring)) {
11630 if ($style ==
'error' || $style ==
'errors') {
11633 if ($style ==
'warning' || $style ==
'warnings') {
11637 if ($iserror || $iswarning) {
11639 $mesgstring = preg_replace(
'/<\/div><div class="(error|warning)">/',
'<br>', $mesgstring);
11640 $mesgstring = preg_replace(
'/<div class="(error|warning)">/',
'', $mesgstring);
11641 $mesgstring = preg_replace(
'/<\/div>/',
'', $mesgstring);
11643 if (is_array($mesgarray)) {
11644 $newmesgarray = array();
11645 foreach ($mesgarray as $val) {
11646 if (is_string($val)) {
11647 $tmpmesgstring = preg_replace(
'/<\/div><div class="(error|warning)">/',
'<br>', $val);
11648 $tmpmesgstring = preg_replace(
'/<div class="(error|warning)">/',
'', $tmpmesgstring);
11649 $tmpmesgstring = preg_replace(
'/<\/div>/',
'', $tmpmesgstring);
11650 $newmesgarray[] = $tmpmesgstring;
11652 dol_syslog(
"Error call of dol_htmloutput_mesg with an array with a value that is not a string", LOG_WARNING);
11655 $mesgarray = $newmesgarray;
11657 print
get_htmloutput_mesg($mesgstring, $mesgarray, ($iserror ?
'error' :
'warning'), $keepembedded);
11686function dolSort($arraytosort)
11688 sort($arraytosort);
11689 return $arraytosort;
11713function dol_sort_array(&$array, $index, $order =
'asc', $natsort = 0, $case_sensitive = 0, $keepindex = 0)
11716 $order = strtolower($order);
11718 if (is_array($array)) {
11719 $sizearray = count($array);
11720 if ($sizearray > 0) {
11723 foreach (array_keys($array) as $key) {
11724 $tmpmultikey = explode(
',', $index);
11725 $newindex = $tmpmultikey[0];
11726 if (is_object($array[$key])) {
11727 $temp[$key] = empty($array[$key]->$newindex) ? 0 : $array[$key]->$newindex;
11729 if (!empty($tmpmultikey[1])) {
11730 $newindex = $tmpmultikey[1];
11731 $temp[$key] .=
'__' . (empty($array[$key]->$newindex) ? 0 : $array[$key]->$newindex);
11735 $temp[$key] = empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex];
11737 if (!empty($tmpmultikey[1])) {
11738 $newindex = $tmpmultikey[1];
11740 $temp[$key] .=
'__' . (empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex]);
11743 if ($natsort == -1) {
11744 $temp[$key] =
'___' . $temp[$key];
11747 if (empty($natsort) || $natsort == -1) {
11748 if ($order ==
'asc') {
11754 if ($case_sensitive) {
11757 natcasesort($temp);
11759 if ($order !=
'asc') {
11760 $temp = array_reverse($temp,
true);
11766 foreach (array_keys($temp) as $key) {
11767 (is_numeric($key) && empty($keepindex)) ? $sorted[] = $array[$key] : $sorted[$key] = $array[$key];
11789 $strLength = strlen($str);
11790 for ($i = 0; $i < $strLength; $i++) {
11791 if (ord($str[$i]) < 0x80) {
11793 } elseif ((ord($str[$i]) & 0xE0) == 0xC0) {
11795 } elseif ((ord($str[$i]) & 0xF0) == 0xE0) {
11797 } elseif ((ord($str[$i]) & 0xF8) == 0xF0) {
11799 } elseif ((ord($str[$i]) & 0xFC) == 0xF8) {
11801 } elseif ((ord($str[$i]) & 0xFE) == 0xFC) {
11806 for ($j = 0; $j < $n; $j++) {
11807 if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80)) {
11828 return preg_match(
'//u', $str) ? true :
false;
11840 if (function_exists(
'mb_check_encoding')) {
11842 if (!mb_check_encoding($str,
'ASCII')) {
11846 if (preg_match(
'/[^\x00-\x7f]/', $str)) {
11864 $tmp = ini_get(
"unicode.filesystem_encoding");
11865 if (empty($tmp) && !empty($_SERVER[
"WINDIR"])) {
11866 $tmp =
'iso-8859-1';
11875 if ($tmp ==
'iso-8859-1') {
11876 return mb_convert_encoding($str,
'ISO-8859-1',
'UTF-8');
11897function dol_getIdFromCode(
$db, $key, $tablename, $fieldkey =
'code', $fieldid =
'id', $entityfilter = 0, $filters =
'', $useCache =
true)
11907 if ($useCache && isset(
$conf->cache[
'codeid'][$tablename][$key][$fieldid])) {
11908 return $conf->cache[
'codeid'][$tablename][$key][$fieldid];
11911 dol_syslog(
'dol_getIdFromCode (value for field ' . $fieldid .
' from key ' . $key .
' not found into cache)', LOG_DEBUG);
11913 $sql =
"SELECT " .
$db->sanitize($fieldid) .
" as valuetoget";
11914 $sql .=
" FROM " . MAIN_DB_PREFIX .
$db->sanitize($tablename);
11915 if ($fieldkey ==
'id' || $fieldkey ==
'rowid') {
11916 $sql .=
" WHERE " .
$db->sanitize($fieldkey) .
" = " . ((int) $key);
11918 $sql .=
" WHERE " .
$db->sanitize($fieldkey) .
" = '" .
$db->escape($key) .
"'";
11920 if (!empty($entityfilter)) {
11921 $sql .=
" AND entity IN (" .
getEntity($tablename) .
")";
11927 $resql =
$db->query($sql);
11929 $obj =
$db->fetch_object($resql);
11932 $valuetoget = $obj->valuetoget;
11933 $conf->cache[
'codeid'][$tablename][$key][$fieldid] = $valuetoget;
11935 $conf->cache[
'codeid'][$tablename][$key][$fieldid] =
'';
11939 return $valuetoget;
11959 $regextext = preg_replace(
'#^/\^?#',
'', (
string) $regextext);
11960 $regextext = preg_replace(
'#\$?/[imsxuADSUXJ]*$#',
'', $regextext);
11962 if ($matchrule == 1) {
11963 if ($var ==
'mainmenu') {
11965 return (preg_match(
'/^' . $regextext .
'/', $mainmenu));
11966 } elseif ($var ==
'leftmenu') {
11968 return (preg_match(
'/^' . $regextext .
'/', $leftmenu));
11970 return 'This variable is not accessible with dol_eval';
11973 return 'This value '.$matchrule.
' for param $matchrule is not yet implemented';
11987function verifCond($strToEvaluate, $onlysimplestring =
'1')
11991 if (isset($strToEvaluate) && $strToEvaluate !==
'') {
11994 $rep =
dol_eval($strToEvaluate, 1, 1, $onlysimplestring);
11998 $rights = (bool) $rep && (!is_string($rep) || (strpos($rep,
'Exception during') ===
false && strpos($rep,
'Bad call of') ===
false && strpos($rep,
'Bad string syntax to evaluate') ===
false));
12019function dol_eval($s, $returnvalue = 1, $hideerrors = 1, $onlysimplestring =
'1')
12021 if ($returnvalue != 1) {
12022 dol_syslog(
"Use of dol_eval with parameter returnvalue = 0 is now forbidden. Please fix this", LOG_ERR);
12025 global $dolibarr_main_use_dol_eval_new;
12026 if (!empty($dolibarr_main_use_dol_eval_new)) {
12047 $db, $langs, $user, $website, $websitepage,
12048 $action, $mainmenu, $leftmenu,
12060 defined(
'T_COALESCE_EQUAL') || define(
'T_COALESCE_EQUAL', PHP_INT_MAX);
12061 defined(
'T_FN') || define(
'T_FN', PHP_INT_MAX);
12064 defined(
'T_ATTRIBUTE') || define(
'T_ATTRIBUTE', PHP_INT_MAX);
12065 defined(
'T_MATCH') || define(
'T_MATCH', PHP_INT_MAX);
12066 defined(
'T_NAME_FULLY_QUALIFIED') || define(
'T_NAME_FULLY_QUALIFIED', PHP_INT_MAX);
12067 defined(
'T_NAME_QUALIFIED') || define(
'T_NAME_QUALIFIED', PHP_INT_MAX);
12068 defined(
'T_NAME_RELATIVE') || define(
'T_NAME_RELATIVE', PHP_INT_MAX);
12071 defined(
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG') || define(
'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG', PHP_INT_MAX);
12072 defined(
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG') || define(
'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG', PHP_INT_MAX);
12073 defined(
'T_ENUM') || define(
'T_ENUM', PHP_INT_MAX);
12074 defined(
'T_READONLY') || define(
'T_READONLY', PHP_INT_MAX);
12077 defined(
'T_PRIVATE_SET') || define(
'T_PRIVATE_SET', PHP_INT_MAX);
12078 defined(
'T_PROTECTED_SET') || define(
'T_PROTECTED_SET', PHP_INT_MAX);
12079 defined(
'T_PUBLIC_SET') || define(
'T_PUBLIC_SET', PHP_INT_MAX);
12081 $prohibited_token_ids = [
12088 'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG',
12089 'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG',
12139 'T_OPEN_TAG_WITH_ECHO',
12173 $prohibited_variables = [
12185 $forbiddenphpfunctions = array();
12186 $forbiddenphpmethods = array();
12189 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"override_function",
"session_id",
"session_create_id",
"session_regenerate_id"));
12190 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"get_defined_functions",
"get_defined_vars",
"get_defined_constants",
"get_declared_classes"));
12191 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"function"));
12193 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"GETPOST"));
12195 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"ob_start"));
12198 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"call_user_func",
"call_user_func_array"));
12199 $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"));
12200 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"usort",
"uasort",
"uksort"));
12201 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"preg_replace_callback",
"preg_replace_callback_array",
"header_register_callback"));
12202 $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"));
12203 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"spl_autoload_register",
"spl_autoload_unregister",
"iterator_apply",
"session_set_save_handler"));
12204 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"forward_static_call",
"forward_static_call_array",
"register_postsend_function"));
12205 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"readline_completion_function",
"readline_callback_handler_install"));
12208 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"exec",
"passthru",
"shell_exec",
"system",
"proc_open",
"popen"));
12209 $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"));
12210 $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", ));
12211 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"putenv",
"dl",
"apache_child_terminate",
"apache_setenv"));
12212 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_eval",
"dol_eval_new",
"dol_eval_standard",
"executeCLI",
"verifCond",
"dolEncrypt",
"dolDecrypt"));
12213 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"eval",
"create_function",
"assert",
"mb_ereg_replace"));
12216 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include",
"require_once",
"include_once"));
12218 $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"));
12219 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"chdir",
"dir",
"fopen",
"file",
"file_exists",
"file_get_contents",
"file_put_contents",
"fget",
"fgetc",
"fgetcsv",
"flock",
"fputs",
"fputscsv",
"fpassthru",
"fscanf",
"fseek",
"fwrite",
"is_file",
"is_dir",
"is_link",
"mkdir",
"opendir",
"rmdir",
"scandir",
"symlink",
"touch",
"unlink",
"umask"));
12223 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"base64" .
"_" .
"decode",
"rawurl" .
"decode",
"url" .
"decode",
"str" .
"_rot13",
"hex" .
"2bin",
"printf",
"sprintf"));
12224 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_concat",
"dol_concatdesc"));
12227 $forbiddenphpmethods = array_merge($forbiddenphpmethods, array(
'invoke',
'invokeArgs'));
12229 $prohibited_functions = array_merge($forbiddenphpfunctions, $forbiddenphpmethods);
12231 $prohibited_token_arrangements = [
12236 ' T_CONSTANT_ENCAPSED_STRING ( ',
12240 $tokens = token_get_all(
"<?php return {$s};", TOKEN_PARSE);
12242 $tokens_arrangement =
' ';
12244 for ($i = 2,
$c = count($tokens) - 1; $i <
$c; ++$i) {
12245 if (is_array($tokens[$i])) {
12246 $token_id = $tokens[$i][0];
12247 $token_value = $tokens[$i][1];
12248 $token_name = token_name($tokens[$i][0]);
12250 $token_id = $tokens[$i];
12251 $token_value = $tokens[$i];
12252 $token_name = $tokens[$i];
12256 if (T_WHITESPACE === $token_id) {
12261 $tokens_arrangement .=
"{$token_name} ";
12265 T_VARIABLE === $token_id
12266 && in_array($token_value, $prohibited_variables,
true)
12268 return "Bad string syntax to evaluate. « {$token_value} » is prohibited in « {$s} »";
12273 T_STRING === $token_id
12274 && in_array($token_value, $prohibited_functions,
true)
12276 return "Bad string syntax to evaluate. « {$token_value} » is prohibited in « {$s} »";
12281 $maxi = count($prohibited_token_ids);
12282 for ($i = 0; $i < $maxi; ++$i) {
12283 if (
false !== strpos($tokens_arrangement,
" {$prohibited_token_ids[$i]} ")) {
12284 return "Bad string syntax to evaluate. « {$prohibited_token_ids[$i]} » is prohibited in « {$s} »";
12289 $maxi = count($prohibited_token_arrangements);
12290 for ($i = 0; $i < $maxi; ++$i) {
12291 if (
false !== strpos($tokens_arrangement, $prohibited_token_arrangements[$i])) {
12292 return "Bad string syntax to evaluate. « {$prohibited_token_arrangements[$i]} » is prohibited in « {$s} »";
12298 return @eval(
"return {$s};") ??
'';
12299 }
catch (Throwable $ex) {
12300 return "Bad string syntax to evaluate. Exception during evaluation: " . $s .
" - " . $ex->getMessage();
12324 global
$db, $langs, $user, $website, $websitepage;
12325 global $action, $mainmenu, $leftmenu;
12327 global $objectoffield;
12335 $isObBufferActive =
false;
12336 if ($onlysimplestring ==
'0') {
12337 $onlysimplestring =
'1';
12339 if (!in_array($onlysimplestring, array(
'1',
'2'))) {
12340 return "Bad call of dol_eval. Parameter onlysimplestring must be '1' or '2'.";
12342 if (!is_scalar($s)) {
12343 return "Bad call of dol_eval. First parameter must be a string, found ".var_export($s,
true);
12347 global $dolibarr_main_restrict_eval_methods;
12350 if (!isset($dolibarr_main_restrict_eval_methods)) {
12351 $dolibarr_main_restrict_eval_methods =
'getDolGlobalString, getDolGlobalInt, getDolCurrency, getDolEntity, getDolDBType, fetchNoCompute, hasRight, isAdmin, isExternalUser, isModEnabled, isStringVarMatching, abs, min, max, round, dol_now, preg_match';
12354 $dolibarr_main_restrict_eval_methods_array = explode(
',', str_replace(
" ",
"", $dolibarr_main_restrict_eval_methods));
12362 $specialcharsallowed =
'^$_+-.*>&|=!?():"\',/@';
12363 if ($onlysimplestring ==
'2') {
12364 $specialcharsallowed .=
'<[]';
12366 global $dolibarr_main_allow_unsecured_special_chars_in_dol_eval;
12367 if (!empty($dolibarr_main_allow_unsecured_special_chars_in_dol_eval)) {
12368 $specialcharsallowed .= (
string) $dolibarr_main_allow_unsecured_special_chars_in_dol_eval;
12370 if (preg_match(
'/[^a-z0-9\s' . preg_quote($specialcharsallowed,
'/') .
']/i', $s)) {
12371 return 'Bad string syntax to evaluate (found chars that are not chars for a simple one line clean eval string): ' . $s;
12383 if (strpos($s,
'/*') !==
false || strpos($s,
'//') !==
false) {
12384 return 'Bad string syntax to evaluate (The comment string /* and // are not allowed): ' . $s;
12388 $tmps = str_replace(
' ? ',
'__XXX__', $s);
12389 if (strpos($tmps,
'?') !==
false) {
12390 return 'Bad string syntax to evaluate (The char ? can be used only with a space before and after): ' . $s;
12394 if (preg_match(
'/<=?[^\s]/', $s)) {
12395 return 'Bad string syntax to evaluate (mode ' . $onlysimplestring .
', found a < or <= without space after): ' . $s;
12399 if (preg_match(
'/(include|include_once|require|require_once)/', $s)) {
12400 return 'Bad string syntax to evaluate (found not allowed key include|include_once|require|require_once): ' . $s;
12404 if (preg_match(
'/\$[\w]*\s*\(/', $s)) {
12405 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;
12408 if (empty($dolibarr_main_restrict_eval_methods)) {
12414 while ($scheck && $savescheck != $scheck) {
12415 $savescheck = $scheck;
12416 $scheck = preg_replace(
'/->[a-zA-Z0-9_]+\(/',
'->__METHOD__', $scheck);
12417 $scheck = preg_replace(
'/::[a-zA-Z0-9_]+\(/',
'->__METHOD__', $scheck);
12418 $scheck = preg_replace(
'/^\(+/',
'__PARENTHESIS__ ', $scheck);
12419 $scheck = preg_replace(
'/\&\&\s+\(/',
'__ANDPARENTHESIS__ ', $scheck);
12420 $scheck = preg_replace(
'/\|\|\s+\(/',
'__ORPARENTHESIS__ ', $scheck);
12421 $scheck = preg_replace(
'/^!?[a-zA-Z0-9_]+\(/',
'__FUNCTION__', $scheck);
12422 $scheck = preg_replace(
'/\s!?[a-zA-Z0-9_]+\(/',
'__FUNCTION__', $scheck);
12423 $scheck = preg_replace(
'/^!\(/',
'__NOTANDPARENTHESIS__', $scheck);
12424 $scheck = preg_replace(
'/\s!\(/',
' __NOTANDPARENTHESIS__', $scheck);
12425 $scheck = preg_replace(
'/(\^|\')\(/',
'__REGEXSTART__', $scheck);
12430 if (strpos($scheck,
'(') !==
false) {
12431 return 'Bad string syntax to evaluate (mode ' . $onlysimplestring .
', found call of a function or method without using the direct name of the function): ' . $s;
12435 if (strpos($s,
'`') !==
false) {
12436 return 'Bad string syntax to evaluate (backtick char is forbidden): ' . $s;
12441 if (preg_match(
'/[^0-9]+\.[^0-9]+/', $s)) {
12442 return 'Bad string syntax to evaluate (dot char is forbidden if not strictly between 2 numbers): ' . $s;
12450 while ($scheck && $savescheck != $scheck) {
12451 $savescheck = $scheck;
12452 $scheck = preg_replace(
'/\$conf->[a-z\_]+->enabled/',
'__VARCONFENABLED__', $scheck);
12453 $scheck = preg_replace(
'/\$user->id/',
'__VARUSERID__', $scheck);
12454 $scheck = preg_replace(
'/\$user->hasRight/',
'__VARUSERHASRIGHT__', $scheck);
12455 $scheck = preg_replace(
'/\$user->rights/',
'__VARUSERHASRIGHT__', $scheck);
12456 $scheck = preg_replace(
'/\$user->isAdmin/',
'__VARUSERHASRIGHT__', $scheck);
12457 $scheck = preg_replace(
'/\$user->admin/',
'__VARUSERISADMIN__', $scheck);
12458 $scheck = preg_replace(
'/\$user->isExternalUser/',
'__VARUSERSOCID__', $scheck);
12459 $scheck = preg_replace(
'/\$user->socid/',
'__VARUSERSOCID__', $scheck);
12460 $scheck = preg_replace(
'/\(\$db\)/',
'__VARDB__', $scheck);
12461 $scheck = preg_replace(
'/\$langs/',
'__VARLANGSTRANS__', $scheck);
12462 $scheck = preg_replace(
'/\$mysoc/',
'__VARMYSOC__', $scheck);
12463 $scheck = preg_replace(
'/\$action/',
'__VARACTION__', $scheck);
12464 $scheck = preg_replace(
'/\$mainmenu/',
'__VARMAINMENU__', $scheck);
12465 $scheck = preg_replace(
'/\$leftmenu/',
'__VARLEFTMENU__', $scheck);
12466 $scheck = preg_replace(
'/\$websitepage/',
'__VARWEBSITEPAGE__', $scheck);
12467 $scheck = preg_replace(
'/\$website/',
'__VARWEBSITE__', $scheck);
12468 $scheck = preg_replace(
'/\$objectoffield/',
'__VAROBJECTOFFIELD__', $scheck);
12469 $scheck = preg_replace(
'/\$object/',
'__VAROBJECT__', $scheck);
12470 $scheck = preg_replace(
'/\$var/',
'__VARVAR__', $scheck);
12473 $scheck = preg_replace(
'/\$soc->canvas/',
'__VARSOCCANVAS__', $scheck);
12474 $scheck = preg_replace(
'/\$obj->canvas/',
'__VAROBJCANVAS__', $scheck);
12477 if (strpos($scheck,
'$') !==
false) {
12478 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);
12479 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;
12484 $forbiddenphpstrings = array(
'_ENV',
'_SESSION',
'_COOKIE',
'_GET',
'_GLOBAL',
'_POST',
'_REQUEST',
'ReflectionFunction',
'SplFileObject',
'SplTempFileObject');
12486 if (empty($dolibarr_main_restrict_eval_methods)) {
12490 $forbiddenphpfunctions = array();
12491 $forbiddenphpmethods = array();
12493 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"override_function",
"session_id",
"session_create_id",
"session_regenerate_id"));
12494 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"get_defined_functions",
"get_defined_vars",
"get_defined_constants",
"get_declared_classes"));
12495 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"function"));
12497 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"GETPOST"));
12499 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"ob_start"));
12502 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"call_user_func",
"call_user_func_array"));
12503 $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"));
12504 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"usort",
"uasort",
"uksort"));
12505 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"preg_replace_callback",
"preg_replace_callback_array",
"header_register_callback"));
12506 $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"));
12507 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"spl_autoload_register",
"spl_autoload_unregister",
"iterator_apply",
"session_set_save_handler"));
12508 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"forward_static_call",
"forward_static_call_array",
"register_postsend_function"));
12509 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"readline_completion_function",
"readline_callback_handler_install"));
12512 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"exec",
"passthru",
"shell_exec",
"system",
"proc_open",
"popen"));
12513 $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"));
12514 $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", ));
12515 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"putenv",
"dl",
"apache_child_terminate",
"apache_setenv"));
12516 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_eval",
"dol_eval_new",
"dol_eval_standard",
"executeCLI",
"verifCond",
"dolEncrypt",
"dolDecrypt"));
12517 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"eval",
"create_function",
"assert",
"mb_ereg_replace"));
12520 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include",
"require_once",
"include_once"));
12522 $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"));
12523 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"chdir",
"dir",
"fopen",
"file",
"file_exists",
"file_get_contents",
"file_put_contents",
"fget",
"fgetc",
"fgetcsv",
"flock",
"fputs",
"fputscsv",
"fpassthru",
"fscanf",
"fseek",
"fwrite",
"is_file",
"is_dir",
"is_link",
"mkdir",
"opendir",
"rmdir",
"scandir",
"symlink",
"touch",
"unlink",
"umask"));
12527 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"base64" .
"_" .
"decode",
"rawurl" .
"decode",
"url" .
"decode",
"str" .
"_rot13",
"hex" .
"2bin",
"printf",
"sprintf"));
12528 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_concat",
"dol_concatdesc"));
12537 $forbiddenphpmethods = array_merge($forbiddenphpmethods, array(
'invoke',
'invokeArgs'));
12545 $forbiddenphpregex =
'global\s*\$';
12546 $forbiddenphpregex .=
'|posix_[a-zA-Z0-9_]*|';
12547 $forbiddenphpregex .=
'\b(' . implode(
'|', $forbiddenphpfunctions) .
')\b';
12549 $forbiddenphpmethodsregex =
'->(' . implode(
'|', $forbiddenphpmethods) .
')';
12553 $oldstringtoclean = $s;
12554 $s = str_ireplace($forbiddenphpstrings,
'__forbiddenstring__', $s);
12555 $s = preg_replace(
'/' . $forbiddenphpregex .
'/i',
'__forbiddenstring__', $s);
12556 $s = preg_replace(
'/' . $forbiddenphpmethodsregex .
'/i',
'__forbiddenstring__', $s);
12558 }
while ($oldstringtoclean != $s);
12560 if (strpos($s,
'__forbiddenstring__') !==
false) {
12561 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
12562 return 'Bad string syntax to evaluate: ' . $s;
12566 if (!empty($dolibarr_main_restrict_eval_methods)) {
12569 $pattern =
'/([\s\w\'\]\"]+)\(/';
12571 $matches = array();
12572 preg_match_all($pattern, $s, $matches);
12574 if (count($matches)) {
12575 foreach ($matches[1] as $m) {
12581 if (!preg_match(
'/new ([A-Z][\w]+)/i', $m, $reg)) {
12582 if (!in_array($m, $dolibarr_main_restrict_eval_methods_array)) {
12583 if ($m !=
"'" && $m !=
'"') {
12584 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
12585 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;
12589 if (!class_exists($reg[1])) {
12590 dol_syslog(
'Bad string syntax to evaluate: Class "'.$reg[1].
'" does not exist. ' . $s, LOG_WARNING);
12591 return 'Bad string syntax to evaluate. Class "'.$reg[1].
'" does not exist. ' . $s;
12593 $parents = class_parents($reg[1]);
12594 if (!in_array(
'CommonObject', $parents)) {
12595 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);
12596 return 'Bad string syntax to evaluate. Class "'.$reg[1].
'" is not allowed because only classes extended CommonObject can be used in dynamic evaluation. ' . $s;
12602 $forbiddenphpregex =
'global\s*\$';
12603 $forbiddenphpregex .=
'|';
12604 $forbiddenphpregex .=
'}\s*\[';
12605 $forbiddenphpregex .=
'|';
12606 $forbiddenphpregex .=
'\)\s*\(';
12610 $oldstringtoclean = $s;
12611 $s = str_ireplace($forbiddenphpstrings,
'__forbiddenstring__', $s);
12612 $s = preg_replace(
'/' . $forbiddenphpregex .
'/i',
'__forbiddenstring__', $s);
12615 }
while ($oldstringtoclean != $s);
12617 if (strpos($s,
'__forbiddenstring__') !==
false) {
12618 dol_syslog(
'Bad string syntax to evaluate: ' . $s, LOG_WARNING);
12619 return 'Bad string syntax to evaluate: ' . $s;
12625 $isObBufferActive =
true;
12626 $tmps = $hideerrors ? @eval(
'return ' . $s .
';') : eval(
'return ' . $s .
';');
12627 $tmpo = ob_get_clean();
12628 $isObBufferActive =
false;
12630 print
'Bad string syntax to evaluate. Some data were output when it should not when evaluating: ' . $s;
12634 if ($isObBufferActive) {
12636 $tmpo = ob_get_clean();
12637 $isObBufferActive =
false;
12639 $error =
'dol_eval try/catch error for string: ' . $s .
' - Error: ';
12640 $error .= $e->getMessage();
12642 return 'Exception during evaluation: ' . $s;
12643 }
catch (Error $e) {
12644 if ($isObBufferActive) {
12646 $tmpo = ob_get_clean();
12647 $isObBufferActive =
false;
12649 $error =
'dol_eval try/catch error for string: ' . $s .
' - Error: ';
12650 $error .= $e->getMessage();
12652 return 'Exception during evaluation: ' . $s;
12665 return (trim($element) !=
'');
12678 if (empty($codelang)) {
12682 if ($codelang ==
'auto') {
12683 return '<span class="fa fa-language"></span>';
12686 $langtocountryflag = array(
12688 'ca_ES' =>
'catalonia',
12692 'sw_SW' =>
'unknown',
12702 if (isset($langtocountryflag[$codelang])) {
12703 $flagImage = $langtocountryflag[$codelang];
12705 $tmparray = explode(
'_', $codelang);
12706 $flagImage = empty($tmparray[1]) ? $tmparray[0] : $tmparray[1];
12711 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
12712 $morecss = $reg[1];
12717 return '<span class="flag-sprite ' . strtolower($flagImage) . ($morecss ?
' ' . $morecss :
'') .
'"' . ($moreatt ?
' ' . $moreatt :
'') . (!$notitlealt ?
' title="' . $codelang .
'"' :
'') .
'></span>';
12731 if (empty($countrycode)) {
12735 if (strtoupper($countrycode) ==
'MQ') {
12738 if (strtoupper($countrycode) ==
'SE') {
12741 if (strtoupper($countrycode) ==
'CH') {
12742 if (
$mysoc->country_code ==
'FR') {
12745 if (
$mysoc->country_code ==
'DE') {
12748 if (
$mysoc->country_code ==
'IT') {
12930 $buildprimarykeytotest = strtolower($countrycode) .
'-' . strtoupper($countrycode);
12931 if (in_array($buildprimarykeytotest, $locales)) {
12932 return strtolower($countrycode) .
'_' . strtoupper($countrycode);
12935 if (function_exists(
'locale_get_primary_language') && function_exists(
'locale_get_region')) {
12936 foreach ($locales as $locale) {
12937 $locale_language = locale_get_primary_language($locale);
12938 $locale_region = locale_get_region($locale);
12939 if (strtoupper($countrycode) == $locale_region) {
12941 return strtolower($locale_language) .
'_' . strtoupper($locale_region);
12945 dol_syslog(
"Warning Extension php-intl is not available", LOG_WARNING);
12983 global $hookmanager,
$db;
12985 if (isset(
$conf->modules_parts[
'tabs'][$type]) && is_array(
$conf->modules_parts[
'tabs'][$type])) {
12986 foreach (
$conf->modules_parts[
'tabs'][$type] as $value) {
12987 $values = explode(
':', $value);
12990 if ($mode ==
'add' && !preg_match(
'/^\-/', $values[1])) {
12991 if (count($values) !== 6) {
12992 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);
12999 if ($values[0] != $type) {
13007 $posstart = strpos($str,
'(');
13008 if ($posstart > 0) {
13009 $posend = strpos($str,
')');
13010 if ($posstart > 0) {
13011 $res1 = substr($str, $posstart + 1, $posend - $posstart - 1);
13012 if (is_numeric($res1)) {
13013 $postab = (int) $res1;
13014 $values[1] =
'+' . substr($str, $posend + 1);
13019 global $objectoffield;
13027 if ($filterorigmodule) {
13028 if (strpos($values[3],
'@')) {
13029 if ($filterorigmodule !=
'external') {
13033 if ($filterorigmodule !=
'core') {
13038 $langs->load($values[3]);
13041 if (preg_match(
'/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
13043 $substitutionarray = array();
13048 $labeltemp = explode(
',', $values[2]);
13049 $label = $langs->trans($labeltemp[0]);
13051 if (!empty($labeltemp[1]) && is_object(
$object) && !empty(
$object->id)) {
13053 $classtoload = $labeltemp[1];
13054 if (class_exists($classtoload)) {
13055 $obj =
new $classtoload(
$db);
13056 $function = $labeltemp[3];
13057 if ($obj && $function && method_exists($obj, $function)) {
13059 $nbrec = $obj->$function(
$object->id, $obj);
13060 if (!empty($nbrec)) {
13061 $label .=
'<span class="badge marginleftonlyshort">' . $nbrec .
'</span>';
13067 $url = preg_replace(
'/__ID__/i', ((is_object(
$object) && !empty(
$object->id)) ?
$object->id :
''), $values[5]);
13068 $link = parse_url($url);
13070 if (isset($link[
'query'])) {
13071 parse_str($link[
'query'], $query);
13074 $newtab[1] = $label;
13075 $newtab[2] = str_replace(
'+',
'', $values[1]);
13079 $head = array_merge(array_slice($head, 0, $postab), array($newtab), array_slice($head, $postab));
13080 } elseif ($mode ==
'remove' && preg_match(
'/^\-/', $values[1])) {
13081 if ($values[0] != $type) {
13084 $tabname = str_replace(
'-',
'', $values[1]);
13085 foreach ($head as $key => $val) {
13086 $condition = (!empty($values[3]) ?
verifCond($values[3],
'2') : 1);
13088 if ($head[$key][2] == $tabname && $condition) {
13089 unset($head[$key]);
13098 if (!empty($hookmanager)) {
13099 $parameters = array(
'object' =>
$object,
'mode' => $mode,
'head' => &$head,
'filterorigmodule' => $filterorigmodule,
'type' => $type);
13101 $reshook = $hookmanager->executeHooks(
'completeTabsHead', $parameters,
$object);
13102 if ($reshook > 0) {
13103 $head = $hookmanager->resArray;
13105 $head = array_merge($head, $hookmanager->resArray);
13124 global
$conf, $hookmanager, $user, $langs;
13126 global $micro_start_time;
13128 if ($zone ==
'private') {
13129 print
"\n" .
'<!-- Common footer for private page -->' .
"\n";
13131 print
"\n" .
'<!-- Common footer for public page -->' .
"\n";
13135 print
"\n<!-- A div to store page_y POST parameter -->\n";
13136 print
'<div id="page_y" style="display: none;">' . (
GETPOST(
'page_y') ?
GETPOST(
'page_y') :
'') .
'</div>' .
"\n";
13138 $parameters = array(
'zone' => $zone);
13141 $reshook = $hookmanager->executeHooks(
'printCommonFooter', $parameters, $tmpobject, $action);
13142 if (empty($reshook)) {
13148 if (!empty(
$conf->use_javascript_ajax)) {
13149 print
"\n<!-- A script section to add menuhider handler on backoffice, manage focus and mandatory fields, tuning info, ... -->\n";
13150 print
'<script>' .
"\n";
13151 print
'jQuery(document).ready(function() {' .
"\n";
13153 if ($zone ==
'private' && empty(
$conf->dol_use_jmobile)) {
13155 print
'/* JS CODE TO ENABLE to manage handler to switch left menu page (menuhider) */' .
"\n";
13156 print
'jQuery("li.menuhider").click(function(event) {';
13157 print
' if (!$( "body" ).hasClass( "sidebar-collapse" )){ event.preventDefault(); }' .
"\n";
13158 print
' console.log("We click on .menuhider");' .
"\n";
13159 print
' $("body").toggleClass("sidebar-collapse")' .
"\n";
13160 print
'});' .
"\n";
13164 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"])))) {
13165 print
'/* JS CODE TO ENABLE to manage focus and mandatory form fields */' .
"\n";
13166 $relativepathstring = $_SERVER[
"PHP_SELF"];
13168 if (constant(
'DOL_URL_ROOT')) {
13169 $relativepathstring = preg_replace(
'/^' . preg_quote(constant(
'DOL_URL_ROOT'),
'/') .
'/',
'', $relativepathstring);
13171 $relativepathstring = preg_replace(
'/^\//',
'', $relativepathstring);
13172 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
13175 if (!empty($user->default_values[$relativepathstring][
'focus'])) {
13176 foreach ($user->default_values[$relativepathstring][
'focus'] as $defkey => $defval) {
13178 if ($defkey !=
'_noquery_') {
13179 $tmpqueryarraytohave = explode(
'&', $defkey);
13181 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
13182 $tmpquerytohaveparam = explode(
'=', $tmpquerytohave);
13184 if (!
GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] !=
GETPOST($tmpquerytohaveparam[0]))) {
13188 if (!$foundintru) {
13197 print
'console.log("set the focus by executing jQuery(...).focus();")' .
"\n";
13198 foreach ($defval as $paramkey => $paramval) {
13200 print
'jQuery("input[name=\'' . $paramkey .
'\']
").focus();' . "\n
";
13201 print 'jQuery("textarea[
name=\
'' . $paramkey .
'\']
").focus();' . "\n
"; // TODO KO with ckeditor
13202 print 'jQuery("select[
name=\
'' . $paramkey .
'\']
").focus();' . "\n
"; // Not really useful, but we keep it in case of.
13207 if (!empty($user->default_values[$relativepathstring]['mandatory'])) {
13208 foreach ($user->default_values[$relativepathstring]['mandatory'] as $defkey => $defval) {
13210 if ($defkey != '_noquery_') {
13211 $tmpqueryarraytohave = explode('&', $defkey);
13213 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
13214 $tmpquerytohaveparam = explode('=', $tmpquerytohave);
13215 //print "console.log(
'".$tmpquerytohaveparam[0]." ".$tmpquerytohaveparam[1]." ".GETPOST($tmpquerytohaveparam[0])."');
";
13216 if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] != GETPOST($tmpquerytohaveparam[0]))) {
13220 if (!$foundintru) {
13223 //var_dump($defkey.'-'.$qualified);
13229 print 'console.log("set the js code to manage fields that are
set as mandatory
");' . "\n
";
13231 foreach ($defval as $paramkey => $paramval) {
13232 // Solution 1: Add handler on submit to check if mandatory fields are empty
13233 print 'var form = $(\'[name="'.dol_escape_js($paramkey).'"]\').closest("form
");'."\n
";
13234 print "form.on(
'submit',
function(event) {
13235 var submitter = \$(
this).find(
':submit:focus').get(0);
13236 var buttonName = submitter ? \$(submitter).attr(
'name') :
'save';
13238 if (buttonName ==
'cancel') {
13239 console.log(
'We click on cancel button so we accept submit with no need to check mandatory fields');
13243 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');
13245 var tmpvalue = jQuery(
'[name=\"".dol_escape_js($paramkey)."\"]').val();
13246 let tmptypefield = jQuery(
'[name=\"".dol_escape_js($paramkey)."\"]').prop(
'nodeName').toLowerCase();
13248 if (tmptypefield ==
'textarea') {
13250 var tmpeditor = (typeof CKEDITOR !==
'undefined') ? CKEDITOR.instances[
'".dol_escape_js($paramkey)."'] : null;
13252 tmpvalue = tmpeditor.getData();
13253 console.log(
'For textarea tmpvalue is '+tmpvalue);
13257 let tmpvalueisempty =
false;
13258 if (tmpvalue ===
null || tmpvalue === undefined || tmpvalue ===
'' || tmpvalue === -1 || tmpvalue ===
'-1') {
13259 tmpvalueisempty =
true;
13261 if (tmpvalue ===
'0' && (tmptypefield ==
'select' || tmptypefield ==
'input')) {
13262 tmpvalueisempty =
true;
13264 if (tmpvalueisempty && buttonName !==
'cancel') {
13265 console.log(
'field has type '+tmptypefield+
' and is empty, we cancel the submit');
13266 event.preventDefault();
13267 event.stopPropagation();
13269 alert(
'".dol_escape_js($langs->transnoentitiesnoconv("ErrorFieldRequired", $paramkey).' (
'.$langs->transnoentitiesnoconv("CustomMandatoryFieldRule").')
')."');
13273 console.log(
'field has type '+tmptypefield+
' and is defined to '+tmpvalue);
13278 // Solution 2: Add property 'required' on input
13279 // so browser will check value and try to focus on it when submitting the form.
13280 //print 'setTimeout(function() {'; // If we want to wait that ckeditor beuatifier has finished its job.
13281 //print 'jQuery("input[
name=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";
13282 //print 'jQuery("textarea[
id=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";
13283 //print 'jQuery("select[
name=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";*/
13284 //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
";
13285 //print 'jQuery("select[
name=\
''.$paramkey.
'\'] option[value=\
'-1\']").prop(\'value\', \'\');'.
"\n";
13291 print
'jQuery(\':input[name="' .
dol_escape_js($paramkey) .
'"]\').closest("tr").find("td:first").addClass("fieldrequired");' .
"\n";
13295 print
'jQuery("input[name=\'cancel\']").click(function() {
13296 console.log("We click on cancel button so removed all required attribute");
13297 jQuery("input, textarea, select").each(function(){this.removeAttribute(\'required\');});
13304 print
'});' .
"\n";
13307 if (!empty($_SERVER[
'MAIN_SHOW_TUNING_INFO']) ||
getDolGlobalString(
'MAIN_SHOW_TUNING_INFO')) {
13309 print
"/* JS CODE TO ENABLE to add memory info */\n";
13310 print
'window.console && console.log("';
13315 if (!empty($micro_start_time)) {
13316 $micro_end_time = microtime(
true);
13317 print
' - Build time: ' . ceil(1000 * ($micro_end_time - $micro_start_time)) .
' ms';
13320 if (function_exists(
"memory_get_usage")) {
13321 print
' - Mem: ' . memory_get_usage();
13323 if (function_exists(
"memory_get_peak_usage")) {
13324 print
' - Real mem peak: ' . memory_get_peak_usage(
true);
13326 if (function_exists(
"zend_loader_file_encoded")) {
13327 print
' - Zend encoded file: ' . (zend_loader_file_encoded() ?
'yes' :
'no');
13329 print
'");' .
"\n";
13332 print
"\n" .
'</script>' .
"\n";
13338 foreach ($tmptagarray as $tmptag) {
13340 print
"<!-- JS CODE TO ENABLE for google analtics tag -->\n";
13342 <!-- Global site tag (gtag.js) - Google Analytics -->
13343 <script nonce="' .
getNonce() .
'" async src="https://www.googletagmanager.com/gtag/js?id=' . trim($tmptag) .
'"></script>
13345 window.dataLayer = window.dataLayer || [];
13346 function gtag(){dataLayer.push(arguments);}
13347 gtag(\'js\', new Date());
13349 gtag(\'config\', \'' . trim($tmptag) .
'\');
13356 // Add Xdebug coverage of code
13357 if (defined('XDEBUGCOVERAGE
')) {
13358 print_r(xdebug_get_code_coverage());
13361 // Output string from hooks
13362 if (!empty($hookmanager->resPrint)) {
13363 print $hookmanager->resPrint;
13366 // Add DebugBar data
13367 if ($user->hasRight('debugbar
', 'read
')) {
13369 if ($debugbar instanceof DebugBar\DebugBar) {
13370 if (isset($debugbar['time
'])) {
13371 // @phan-suppress-next-line PhanPluginUnknownObjectMethodCall
13372 $debugbar['time
']->stopMeasure('pageaftermaster
');
13374 print '<!-- Output debugbar data -->
' . "\n";
13375 $renderer = $debugbar->getJavascriptRenderer();
13376 print $renderer->render();
13378 } elseif (count($conf->logbuffer)) { // If there is some logs in buffer to show
13380 print "<!-- Start of log output\n";
13381 //print '<div
class=
"hidden">
'."\n";
13382 foreach ($conf->logbuffer as $logline) {
13383 print $logline . "<br>\n";
13385 //print '</div>
'."\n";
13386 print "End of log output -->\n";
13400function dolExplodeIntoArray($string, $delimiter = ';
', $kv = '=
')
13402 if (is_null($string)) {
13406 if (preg_match('/^\[.*\]$/sm
', $delimiter) || preg_match('/^\(.*\)$/sm
', $delimiter)) {
13407 // This is a regex string
13408 $newdelimiter = $delimiter;
13410 // This is a simple string
13411 // @phan-suppress-next-line PhanPluginSuspiciousParamPositionInternal
13412 $newdelimiter = preg_quote($delimiter, '/
');
13415 if ($a = preg_split('/
' . $newdelimiter . '/
', $string)) {
13417 foreach ($a as $s) { // each part
13419 if ($pos = strpos($s, $kv)) { // key/value delimiter
13420 $ka[trim(substr($s, 0, $pos))] = trim(substr($s, $pos + strlen($kv)));
13421 } else { // key delimiter not found
13439function dolExplodeKeepIfQuotes($input)
13441 // Use regexp to capture words and section in quotes
13442 $matches = array();
13443 preg_match_all('/
"([^"]*)
"|\'([^\']*)\'|(\S+)/', $input, $matches);
13445 // Merge result and delete empty values
13447 $result = array_map(
13454 static function ($a, $b, $c) {
13470 return array_values(array_filter(
13478 static function ($val) {
13479 return $val !== '';
13491function dol_set_focus($selector)
13493 print "\n
" . '<!-- Set focus onto a specific field -->' . "\n
";
13494 print '<script nonce="' . getNonce() . '">jQuery(document).ready(function() { console.log("Force focus by
dol_set_focus"); jQuery("' . dol_escape_js($selector) . '").focus(); });</script>' . "\n
";
13505function dol_getmypid()
13507 if (!function_exists('getmypid')) {
13508 return mt_rand(99900000, 99965535);
13510 return getmypid(); // May be a number on 64 bits (depending on OS)
13536function natural_search($fields, $value, $mode = 0, $nofirstand = 0, $sqltoadd = '')
13538 global $db, $langs;
13540 $value = trim($value);
13543 $value = preg_replace('/\*/', '%', $value); // Replace * with %
13546 $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
13549 $value = preg_replace('/\s*\|\s*/', '|', $value);
13551 // Split criteria on ' ' but not if we are inside quotes.
13552 // For mode 3, the split is done later on the , only and not on the ' '.
13553 if ($mode != -3 && $mode != 3) {
13554 $crits = dolExplodeKeepIfQuotes($value);
13556 $crits = array($value);
13560 if (!is_array($fields)) {
13561 $fields = array($fields);
13563 $i1 = 0; // count the nb of "and
" criteria added (all fields / criteria)
13564 foreach ($crits as $crit) { // Loop on each AND criteria
13565 $crit = trim($crit);
13566 $i2 = 0; // count the nb of valid criteria added for this this first criteria
13569 foreach ($fields as $field) {
13571 $tmpcrits = explode('|', $crit);
13572 $i3 = 0; // count the nb of valid criteria added for this current field
13573 foreach ($tmpcrits as $tmpcrit) {
13574 if ($tmpcrit !== '0' && empty($tmpcrit)) {
13577 $tmpcrit = trim($tmpcrit);
13579 $newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
13582 $newcrit = preg_replace('/([!<>=]+)/', '', $tmpcrit);
13585 preg_match('/([!<>=]+)/', $tmpcrit, $reg);
13586 if (!empty($reg[1])) {
13587 $operator = $reg[1];
13589 if ($newcrit != '') {
13590 $numnewcrit = price2num($newcrit);
13591 if (is_numeric($numnewcrit)) {
13592 $newres .= $db->sanitize($field) . ' ' . $operator . ' ' . ((float) $numnewcrit); // should be a numeric
13594 $newres .= '1 = 2'; // force false, we received a corrupted data
13596 $i3++; // a criteria was added to string
13599 $i2++; // a criteria for 1 more field was added to string
13600 } elseif ($mode == 2 || $mode == -2) {
13601 $crit = preg_replace('/[^\-0-9,]/', '', $crit); // ID are always integer
13602 $newres .= ($i2 > 0 ? ' OR ' : '') . $db->sanitize($field) . " " . ($mode == -2 ? 'NOT ' : '');
13603 $newres .= $crit ? "IN (
" . $db->sanitize($db->escape($crit)) . ")
" : "IN (0)
";
13605 $newres .= ' OR ' . $db->sanitize($field) . ' IS NULL';
13607 $i2++; // a criteria for 1 more field was added to string
13608 } elseif ($mode == 3 || $mode == -3) {
13609 $tmparray = explode(',', $crit);
13610 if (count($tmparray)) {
13612 $listofcodesnot = '';
13613 foreach ($tmparray as $val) {
13616 if (preg_match('/^!/', $val)) {
13617 $listofcodesnot .= ($listofcodesnot ? ',' : '');
13618 $listofcodesnot .= "'" . $db->escape(preg_replace('/^!=?/
', '', $val)) . "'";
13620 $listofcodes .= ($listofcodes ? ',' : '');
13621 $listofcodes .= "'" . $db->escape($val) . "'";
13625 $newres .= ($i2 > 0 ? ' OR ' : '');
13626 if ($listofcodes && $listofcodesnot) {
13629 if ($listofcodes) {
13630 $newres .= $db->sanitize($field) . " " . ($mode == -3 ? 'NOT IN' : 'IN') . " (
" . $db->sanitize($listofcodes, 1, 0, 1) . ")
";
13632 if ($listofcodes && $listofcodesnot) {
13633 $newres .= ' AND ';
13635 if ($listofcodesnot) {
13636 $newres .= $db->sanitize($field) . " " . ($mode == -3 ? 'IN ' : 'NOT IN') . " (
" . $db->sanitize($listofcodesnot, 1, 0, 1) . ")
";
13638 if ($listofcodes && $listofcodesnot) {
13641 $i2++; // a criteria for 1 more field was added to string
13644 $newres .= ' OR ' . $db->sanitize($field) . ' IS NULL';
13646 } elseif ($mode == 4) {
13647 $tmparray = explode(',', $crit);
13648 if (count($tmparray)) {
13650 foreach ($tmparray as $val) {
13653 $newres .= ($i2 > 0 ? " OR (
" : "(
") . $db->sanitize($field) . " LIKE
'" . $db->escape($val) . ",%'";
13654 $newres .= ' OR ' . $db->sanitize($field) . " =
'" . $db->escape($val) . "'";
13655 $newres .= ' OR ' . $db->sanitize($field) . " LIKE
'%," . $db->escape($val) . "'";
13656 $newres .= ' OR ' . $db->sanitize($field) . " LIKE
'%," . $db->escape($val) . ",%'";
13658 $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)
13662 } else { // $mode=0
13663 $tmpcrits = explode('|', $crit);
13664 $i3 = 0; // count the nb of valid criteria added for the current couple criteria/field
13665 foreach ($tmpcrits as $tmpcrit) { // loop on each OR criteria
13666 if ($tmpcrit !== '0' && empty($tmpcrit)) {
13669 $tmpcrit = trim($tmpcrit);
13671 if ($tmpcrit == '^$' || strpos($crit, '!') === 0) { // If we search empty, we must combined different OR fields with AND
13672 $newres .= (($i2 > 0 || $i3 > 0) ? ' AND ' : '');
13674 $newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
13677 $isSellist = false;
13678 $table = $label = $key = null;
13680 if (strpos($field, 'ef.') === 0) {
13681 $extrafieldName = substr($field, 3);
13682 $extrafields = new ExtraFields($db);
13683 $extrafields->fetch_name_optionals_label('product');
13685 if (isset($extrafields->attributes['product']['type'][$extrafieldName]) && $extrafields->attributes['product']['type'][$extrafieldName] === 'sellist') {
13687 $paramArray = $extrafields->attributes['product']['param'][$extrafieldName]['options'] ?? [];
13688 $param = array_key_first($paramArray);
13689 list($table, $label, $key) = explode(':', $param);
13693 if (preg_match('/\.(id|rowid)$/', $field)) { // Special case for rowid that is sometimes a ref so used as a search field
13694 $newres .= $db->sanitize($field) . " =
" . (is_numeric($tmpcrit) ? ((float) $tmpcrit) : '0');
13696 $tmpcrit2 = $tmpcrit;
13701 if ($isSellist && $key && $table && $label) {
13702 $newres .= $field . " IN (SELECT t.
" . $db->sanitize((string) $key) . " FROM
" . $db->prefix() . $db->sanitize((string) $table) . " AS t WHERE t.
" . $db->sanitize((string) $label) . " LIKE
'%" . $db->escape($tmpcrit2) . "%')
";
13704 if (preg_match('/^!/', $tmpcrit)) {
13705 $tmps .= $db->sanitize($field) . " NOT LIKE
"; // ! as exclude character
13706 $tmpcrit2 = preg_replace('/^!/', '', $tmpcrit2);
13708 $tmps .= $db->sanitize($field) . " LIKE
";
13712 if (preg_match('/^[\^\$]/
', $tmpcrit)) {
13714 $tmpcrit2 = preg_replace('/^[\^\$]/
', '', $tmpcrit2);
13716 if (preg_match('/[\^\$]$/
', $tmpcrit)) {
13718 $tmpcrit2 = preg_replace('/[\^\$]$/
', '', $tmpcrit2);
13721 if ($tmpcrit2 == '' || preg_match('/^!/
', $tmpcrit)) {
13722 $tmps = "(" . $tmps;
13725 $newres .= $tmpbefore;
13726 $newres .= $db->escape($tmpcrit2);
13727 $newres .= $tmpafter;
13729 if ($tmpcrit2 == '' || preg_match('/^!/', $tmpcrit)) {
13730 $newres .= " OR
" . $db->sanitize($field) . " IS NULL)
";
13738 $i2++; // a criteria for 1 more field was added to string
13743 $newres .= ($newres ? '' : ' OR ').str_replace('__KEYTOSEARCH__', $db->escape($crit), $sqltoadd);
13747 $res = $res . ($res ? ' AND ' : '') . ($i2 > 1 ? '(' : '') . $newres . ($i2 > 1 ? ')' : '');
13751 $res = ($nofirstand ? "" : " AND
") . "(
" . $res . ")
";
13763function showSimpleHTMLTable($outputlangs, $object)
13767 $discountIsAvailable = false;
13768 $orderPositionHasNoPrice = false;
13770 if (!property_exists($object->lines[0], "remise_percent
") ||
13771 !property_exists($object->lines[0], "fk_unit
") ||
13772 !property_exists($object->lines[0], "multicurrency_total_ttc
") ||
13773 !property_exists($object->lines[0], "description") ||
13774 !property_exists($object->lines[0], "qty
")) {
13778 foreach ($object->lines as $order_position) {
13779 if (!property_exists($order_position, "price")) {
13780 $orderPositionHasNoPrice = true;
13784 if (!empty($order_position->remise_percent)) {
13785 $discountIsAvailable = true;
13790 if ($orderPositionHasNoPrice) {
13794 $discountHeader = $discountIsAvailable ? '<th style="width:120px
">'.$outputlangs->trans("Discount
").'</th>' : '';
13796 $table = '<table border="0
" cellpadding="1
" cellspacing="1
">';
13800 <th style="width:50px; text-align:left
">#</th>
13801 <th style="text-align:left
">'.$outputlangs->trans("Description
").'</th>
13802 <th style="width:120px; text-align:right;
">'.$outputlangs->trans("Price
").'</th>
13803 <th style="width:100px; text-align:right;
">'.$outputlangs->trans("Quantity
").'</th>
13804 <th style="width:120px; text-align:right;
">'.$outputlangs->trans("Unit
").'</th>'.
13806 <th style="width:120px; text-align:right;
">'.$outputlangs->trans("Sum
").'</th>
13811 foreach ($object->lines as $index => $order_position) {
13812 $position = $index + 1;
13813 $price = price($order_position->price, 0, $outputlangs, 0, -1, -1, $conf->currency);
13814 $unit = measuringUnitString($order_position->fk_unit, '', null, 1);
13815 $total = price($order_position->multicurrency_total_ttc, 0, $outputlangs, 0, -1, -1, $conf->currency);
13816 $discount = $discountIsAvailable ? '<td style="text-align:center
">'.$order_position->remise_percent.'%</td>' : "";
13820 <td>'.$position.'</td>
13821 <td>'.$order_position->description.'</td>
13822 <td style="text-align:right
">'.$price.'</td>
13823 <td style="text-align:right
">'.$order_position->qty.'</td>
13824 <td style="text-align:right
">'.$unit.'</td>'.
13826 <td style="text-align:right
">'.$total.'</td>
13829 $table .= '</tbody></table>';
13840function showDirectDownloadLink($object)
13845 $url = $object->getLastMainDocLink($object->element);
13847 $out .= img_picto($langs->trans("PublicDownloadLinkDesc
"), 'globe') . ' <span class="opacitymedium
">' . $langs->trans("DirectDownloadLink
") . '</span><br>';
13849 $out .= '<div class="urllink
"><input type="text
" id="directdownloadlink
" class="quatrevingtpercent
" value="' . $url . '"></div>';
13850 $out .= ajax_autoselect("directdownloadlink
", '');
13852 $out .= '<div class="urllink
">' . $langs->trans("FileNotShared
") . '</div>';
13866function getImageFileNameForSize($file, $extName, $extImgTarget = '')
13868 $dirName = dirname($file);
13869 if ($dirName == '.') {
13873 if (!in_array($extName, array('', '_small', '_mini'))) {
13874 return 'Bad parameter extName';
13877 $fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp|\.webp|\.avif)$/i', '', $file); // We remove image extension, whatever is its case
13878 $fileName = basename($fileName);
13880 if (empty($extImgTarget)) {
13881 $extImgTarget = (preg_match('/\.jpg$/i', $file) ? '.jpg' : '');
13883 if (empty($extImgTarget)) {
13884 $extImgTarget = (preg_match('/\.jpeg$/i', $file) ? '.jpeg' : '');
13886 if (empty($extImgTarget)) {
13887 $extImgTarget = (preg_match('/\.gif$/i', $file) ? '.gif' : '');
13889 if (empty($extImgTarget)) {
13890 $extImgTarget = (preg_match('/\.png$/i', $file) ? '.png' : '');
13892 if (empty($extImgTarget)) {
13893 $extImgTarget = (preg_match('/\.bmp$/i', $file) ? '.bmp' : '');
13895 if (empty($extImgTarget)) {
13896 $extImgTarget = (preg_match('/\.webp$/i', $file) ? '.webp' : '');
13898 if (empty($extImgTarget)) {
13899 $extImgTarget = (preg_match('/\.avif$/i', $file) ? '.avif' : '');
13902 if (!$extImgTarget) {
13908 $subdir = 'thumbs/';
13911 return ($dirName ? $dirName . '/' : '') . $subdir . $fileName . $extName . $extImgTarget; // New filename for thumb
13924function getAdvancedPreviewUrl($modulepart, $relativepath, $alldata = 0, $param = '')
13926 global $conf, $langs;
13928 if (empty($conf->use_javascript_ajax)) {
13932 $isAllowedForPreview = dolIsAllowedForPreview($relativepath);
13934 if ($alldata == 1) {
13935 if ($isAllowedForPreview) {
13936 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));
13942 // old behavior, return a string
13943 if ($isAllowedForPreview) {
13944 $tmpurl = DOL_URL_ROOT . '/document.php?modulepart=' . urlencode($modulepart) . '&attachment=0&file=' . urlencode($relativepath) . ($param ? '&' . $param : '');
13945 $title = $langs->transnoentities("Preview
");
13946 //$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().
13947 //$tmpurl = 'file='.urlencode("'-alert(document.domain)-'_small.jpg
"); // An example of tmpurl that should be blocked by the dol_escape_uri()
13949 // 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,
13950 // 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.
13951 // Using the dol_escape_uri guarantee that we encode for URI so decode retrieve original expected value.
13952 return 'javascript:' . dol_escape_uri('document_preview(\'' . dol_escape_js($tmpurl) . '\', \'' . dol_escape_js(dol_mimetype($relativepath)) . '\', \'' . dol_escape_js($title) . '\')');
13964function getLabelSpecialCode($idcode)
13968 $arrayspecialines = array(1 => 'Transport', 2 => 'EcoTax', 3 => 'Option');
13969 if ($idcode > 10) {
13970 return 'Module ID ' . $idcode;
13972 if (!empty($arrayspecialines[$idcode])) {
13973 return $langs->trans($arrayspecialines[$idcode]);
13987function ajax_autoselect($htmlname, $addlink = '', $textonlink = 'Link')
13990 $out = '<script nonce="
' . getNonce() . '">
13991 jQuery(document).ready(function () {
13992 jQuery("' . ((strpos($htmlname, '.
') === 0 ? '' : '#
') . $htmlname) . '").click(function() { jQuery(this).select(); } );
13996 if ($textonlink === 'image') {
13997 $out .= ' <a href="' . $addlink . '" target="_blank
" rel="noopener noreferrer
">' . img_picto('', 'globe') . '</a>';
13999 $out .= ' <a href="' . $addlink . '" target="_blank
" rel="noopener noreferrer
">' . $langs->trans("Link") . '</a>';
14012function dolIsAllowedForPreview($file)
14014 // Check .noexe extension in filename
14015 if (preg_match('/\.noexe$/i', $file)) {
14019 // Check mime types
14020 $mime_preview = array('avif', 'bmp', 'jpeg', 'png', 'gif', 'tiff', 'pdf', 'plain', 'css', 'webp', 'webm', 'mp4');
14021 if (getDolGlobalString('MAIN_ALLOW_SVG_FILES_AS_IMAGES')) {
14022 $mime_preview[] = 'svg+xml';
14024 if (getDolGlobalString('MAIN_ALLOW_XML_FILES_AS_PREVIEW')) {
14025 $mime_preview[] = 'xml';
14028 //$mime_preview[]='vnd.oasis.opendocument.presentation';
14029 //$mime_preview[]='archive';
14030 $num_mime = array_search(dol_mimetype($file, '', 1), $mime_preview);
14031 if ($num_mime !== false) {
14035 // By default, not allowed for preview
14049function dol_mimetype($file, $default = 'application/octet-stream', $mode = 0)
14052 $imgmime = 'other.png';
14053 $famime = 'file-o';
14056 $tmpfile = preg_replace('/\.noexe$/', '', $file);
14058 // Plain text files
14059 if (preg_match('/\.txt$/i', $tmpfile)) {
14060 $mime = 'text/plain';
14061 $imgmime = 'text.png';
14062 $famime = 'file-alt';
14063 } elseif (preg_match('/\.rtx$/i', $tmpfile)) {
14064 $mime = 'text/richtext';
14065 $imgmime = 'text.png';
14066 $famime = 'file-alt';
14067 } elseif (preg_match('/\.csv$/i', $tmpfile)) {
14068 $mime = 'text/csv';
14069 $imgmime = 'text.png';
14070 $famime = 'file-csv';
14071 } elseif (preg_match('/\.tsv$/i', $tmpfile)) {
14072 $mime = 'text/tab-separated-values';
14073 $imgmime = 'text.png';
14074 $famime = 'file-alt';
14075 } elseif (preg_match('/\.(cf|conf|log)$/i', $tmpfile)) {
14076 $mime = 'text/plain';
14077 $imgmime = 'text.png';
14078 $famime = 'file-alt';
14079 } elseif (preg_match('/\.ini$/i', $tmpfile)) {
14080 $mime = 'text/plain';
14081 $imgmime = 'text.png';
14083 $famime = 'file-alt';
14084 } elseif (preg_match('/\.md$/i', $tmpfile)) {
14085 $mime = 'text/plain';
14086 $imgmime = 'text.png';
14088 $famime = 'file-alt';
14089 } elseif (preg_match('/\.css$/i', $tmpfile)) {
14090 $mime = 'text/css';
14091 $imgmime = 'css.png';
14093 $famime = 'file-alt';
14094 } elseif (preg_match('/\.lang$/i', $tmpfile)) {
14095 $mime = 'text/plain';
14096 $imgmime = 'text.png';
14098 $famime = 'file-alt';
14099 } elseif (preg_match('/\.(crt|cer|key|pub)$/i', $tmpfile)) { // Certificate files
14100 $mime = 'text/plain';
14101 $imgmime = 'text.png';
14102 $famime = 'file-alt';
14103 } elseif (preg_match('/\.(html|htm|shtml)$/i', $tmpfile)) { // XML based (HTML/XML/XAML)
14104 $mime = 'text/html';
14105 $imgmime = 'html.png';
14107 $famime = 'file-alt';
14108 } elseif (preg_match('/\.(xml|xhtml)$/i', $tmpfile)) {
14109 $mime = 'text/xml';
14110 $imgmime = 'other.png';
14112 $famime = 'file-alt';
14113 } elseif (preg_match('/\.xaml$/i', $tmpfile)) {
14114 $mime = 'text/xml';
14115 $imgmime = 'other.png';
14117 $famime = 'file-alt';
14118 } elseif (preg_match('/\.bas$/i', $tmpfile)) { // Languages
14119 $mime = 'text/plain';
14120 $imgmime = 'text.png';
14122 $famime = 'file-code';
14123 } elseif (preg_match('/\.(c)$/i', $tmpfile)) {
14124 $mime = 'text/plain';
14125 $imgmime = 'text.png';
14127 $famime = 'file-code';
14128 } elseif (preg_match('/\.(cpp)$/i', $tmpfile)) {
14129 $mime = 'text/plain';
14130 $imgmime = 'text.png';
14132 $famime = 'file-code';
14133 } elseif (preg_match('/\.cs$/i', $tmpfile)) {
14134 $mime = 'text/plain';
14135 $imgmime = 'text.png';
14137 $famime = 'file-code';
14138 } elseif (preg_match('/\.(h)$/i', $tmpfile)) {
14139 $mime = 'text/plain';
14140 $imgmime = 'text.png';
14142 $famime = 'file-code';
14143 } elseif (preg_match('/\.(java|jsp)$/i', $tmpfile)) {
14144 $mime = 'text/plain';
14145 $imgmime = 'text.png';
14147 $famime = 'file-code';
14148 } elseif (preg_match('/\.php([0-9]{1})?$/i', $tmpfile)) {
14149 $mime = 'text/plain';
14150 $imgmime = 'php.png';
14152 $famime = 'file-code';
14153 } elseif (preg_match('/\.phtml$/i', $tmpfile)) {
14154 $mime = 'text/plain';
14155 $imgmime = 'php.png';
14157 $famime = 'file-code';
14158 } elseif (preg_match('/\.(pl|pm)$/i', $tmpfile)) {
14159 $mime = 'text/plain';
14160 $imgmime = 'pl.png';
14162 $famime = 'file-code';
14163 } elseif (preg_match('/\.sql$/i', $tmpfile)) {
14164 $mime = 'text/plain';
14165 $imgmime = 'text.png';
14167 $famime = 'file-code';
14168 } elseif (preg_match('/\.js$/i', $tmpfile)) {
14169 $mime = 'text/x-javascript';
14170 $imgmime = 'jscript.png';
14172 $famime = 'file-code';
14173 } elseif (preg_match('/\.odp$/i', $tmpfile)) { // Open office
14174 $mime = 'application/vnd.oasis.opendocument.presentation';
14175 $imgmime = 'ooffice.png';
14176 $famime = 'file-powerpoint';
14177 } elseif (preg_match('/\.ods$/i', $tmpfile)) {
14178 $mime = 'application/vnd.oasis.opendocument.spreadsheet';
14179 $imgmime = 'ooffice.png';
14180 $famime = 'file-excel';
14181 } elseif (preg_match('/\.odt$/i', $tmpfile)) {
14182 $mime = 'application/vnd.oasis.opendocument.text';
14183 $imgmime = 'ooffice.png';
14184 $famime = 'file-word';
14185 } elseif (preg_match('/\.mdb$/i', $tmpfile)) { // MS Office
14186 $mime = 'application/msaccess';
14187 $imgmime = 'mdb.png';
14189 } elseif (preg_match('/\.doc[xm]?$/i', $tmpfile)) {
14190 $mime = 'application/msword';
14191 $imgmime = 'doc.png';
14192 $famime = 'file-word';
14193 } elseif (preg_match('/\.dot[xm]?$/i', $tmpfile)) {
14194 $mime = 'application/msword';
14195 $imgmime = 'doc.png';
14196 $famime = 'file-word';
14197 } elseif (preg_match('/\.xlt(x)?$/i', $tmpfile)) {
14198 $mime = 'application/vnd.ms-excel';
14199 $imgmime = 'xls.png';
14200 $famime = 'file-excel';
14201 } elseif (preg_match('/\.xla(m)?$/i', $tmpfile)) {
14202 $mime = 'application/vnd.ms-excel';
14203 $imgmime = 'xls.png';
14204 $famime = 'file-excel';
14205 } elseif (preg_match('/\.xls$/i', $tmpfile)) {
14206 $mime = 'application/vnd.ms-excel';
14207 $imgmime = 'xls.png';
14208 $famime = 'file-excel';
14209 } elseif (preg_match('/\.xls[bmx]$/i', $tmpfile)) {
14210 $mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
14211 $imgmime = 'xls.png';
14212 $famime = 'file-excel';
14213 } elseif (preg_match('/\.pps[mx]?$/i', $tmpfile)) {
14214 $mime = 'application/vnd.ms-powerpoint';
14215 $imgmime = 'ppt.png';
14216 $famime = 'file-powerpoint';
14217 } elseif (preg_match('/\.ppt[mx]?$/i', $tmpfile)) {
14218 $mime = 'application/x-mspowerpoint';
14219 $imgmime = 'ppt.png';
14220 $famime = 'file-powerpoint';
14221 } elseif (preg_match('/\.pdf$/i', $tmpfile)) { // Other
14222 $mime = 'application/pdf';
14223 $imgmime = 'pdf.png';
14224 $famime = 'file-pdf';
14225 } elseif (preg_match('/\.bat$/i', $tmpfile)) { // Scripts
14226 $mime = 'text/x-bat';
14227 $imgmime = 'script.png';
14229 $famime = 'file-code';
14230 } elseif (preg_match('/\.sh$/i', $tmpfile)) {
14231 $mime = 'text/x-sh';
14232 $imgmime = 'script.png';
14234 $famime = 'file-code';
14235 } elseif (preg_match('/\.ksh$/i', $tmpfile)) {
14236 $mime = 'text/x-ksh';
14237 $imgmime = 'script.png';
14239 $famime = 'file-code';
14240 } elseif (preg_match('/\.bash$/i', $tmpfile)) {
14241 $mime = 'text/x-bash';
14242 $imgmime = 'script.png';
14244 $famime = 'file-code';
14245 } elseif (preg_match('/\.ico$/i', $tmpfile)) { // Images
14246 $mime = 'image/x-icon';
14247 $imgmime = 'image.png';
14248 $famime = 'file-image';
14249 } elseif (preg_match('/\.(jpg|jpeg)$/i', $tmpfile)) {
14250 $mime = 'image/jpeg';
14251 $imgmime = 'image.png';
14252 $famime = 'file-image';
14253 } elseif (preg_match('/\.png$/i', $tmpfile)) {
14254 $mime = 'image/png';
14255 $imgmime = 'image.png';
14256 $famime = 'file-image';
14257 } elseif (preg_match('/\.gif$/i', $tmpfile)) {
14258 $mime = 'image/gif';
14259 $imgmime = 'image.png';
14260 $famime = 'file-image';
14261 } elseif (preg_match('/\.bmp$/i', $tmpfile)) {
14262 $mime = 'image/bmp';
14263 $imgmime = 'image.png';
14264 $famime = 'file-image';
14265 } elseif (preg_match('/\.(tif|tiff)$/i', $tmpfile)) {
14266 $mime = 'image/tiff';
14267 $imgmime = 'image.png';
14268 $famime = 'file-image';
14269 } elseif (preg_match('/\.svg$/i', $tmpfile)) {
14270 $mime = 'image/svg+xml';
14271 $imgmime = 'image.png';
14272 $famime = 'file-image';
14273 } elseif (preg_match('/\.webp$/i', $tmpfile)) {
14274 $mime = 'image/webp';
14275 $imgmime = 'image.png';
14276 $famime = 'file-image';
14277 } elseif (preg_match('/\.vcs$/i', $tmpfile)) { // Calendar
14278 $mime = 'text/calendar';
14279 $imgmime = 'other.png';
14280 $famime = 'file-alt';
14281 } elseif (preg_match('/\.ics$/i', $tmpfile)) {
14282 $mime = 'text/calendar';
14283 $imgmime = 'other.png';
14284 $famime = 'file-alt';
14285 } elseif (preg_match('/\.torrent$/i', $tmpfile)) { // Other
14286 $mime = 'application/x-bittorrent';
14287 $imgmime = 'other.png';
14288 $famime = 'file-o';
14289 } elseif (preg_match('/\.(mp3|ogg|au|wav|wma|mid)$/i', $tmpfile)) { // Audio
14291 $imgmime = 'audio.png';
14292 $famime = 'file-audio';
14293 } elseif (preg_match('/\.mp4$/i', $tmpfile)) { // Video
14294 $mime = 'video/mp4';
14295 $imgmime = 'video.png';
14296 $famime = 'file-video';
14297 } elseif (preg_match('/\.ogv$/i', $tmpfile)) {
14298 $mime = 'video/ogg';
14299 $imgmime = 'video.png';
14300 $famime = 'file-video';
14301 } elseif (preg_match('/\.webm$/i', $tmpfile)) {
14302 $mime = 'video/webm';
14303 $imgmime = 'video.png';
14304 $famime = 'file-video';
14305 } elseif (preg_match('/\.avif$/i', $tmpfile)) {
14306 $mime = 'image/avif';
14307 $imgmime = 'image.png';
14308 $famime = 'file-image';
14309 } elseif (preg_match('/\.avi$/i', $tmpfile)) {
14310 $mime = 'video/x-msvideo';
14311 $imgmime = 'video.png';
14312 $famime = 'file-video';
14313 } elseif (preg_match('/\.divx$/i', $tmpfile)) {
14314 $mime = 'video/divx';
14315 $imgmime = 'video.png';
14316 $famime = 'file-video';
14317 } elseif (preg_match('/\.xvid$/i', $tmpfile)) {
14318 $mime = 'video/xvid';
14319 $imgmime = 'video.png';
14320 $famime = 'file-video';
14321 } elseif (preg_match('/\.(wmv|mpg|mpeg)$/i', $tmpfile)) {
14323 $imgmime = 'video.png';
14324 $famime = 'file-video';
14325 } elseif (preg_match('/\.(zip|rar|gz|tgz|xz|z|cab|bz2|7z|tar|lzh|zst)$/i', $tmpfile)) { // Archive
14326 // application/xxx where zzz is zip, ...
14328 $imgmime = 'archive.png';
14329 $famime = 'file-archive';
14330 } elseif (preg_match('/\.(exe|com)$/i', $tmpfile)) { // Exe
14331 $mime = 'application/octet-stream';
14332 $imgmime = 'other.png';
14333 $famime = 'file-o';
14334 } elseif (preg_match('/\.(dll|lib|o|so|a)$/i', $tmpfile)) { // Lib
14336 $imgmime = 'library.png';
14337 $famime = 'file-o';
14338 } elseif (preg_match('/\.err$/i', $tmpfile)) { // phpcs:ignore
14340 $imgmime = 'error.png';
14341 $famime = 'file-alt';
14344 if ($famime == 'file-o') {
14345 // file-o seems to not work in fontawesome 5
14349 // Return mimetype string
14350 switch ((int) $mode) {
14352 $tmp = explode('/', $mime);
14353 return (!empty($tmp[1]) ? $tmp[1] : $tmp[0]);
14375function getDictionaryValue($tablename, $field, $id, $checkentity = false, $rowidfield = 'rowid')
14379 $tablename = preg_replace('/^' . preg_quote(MAIN_DB_PREFIX, '/') . '/', '', $tablename); // Clean name of table for backward compatibility.
14381 $dictvalues = (isset($conf->cache['dictvalues_' . $tablename]) ? $conf->cache['dictvalues_' . $tablename] : null);
14383 if (is_null($dictvalues)) {
14384 $dictvalues = array();
14386 $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
14387 if ($checkentity) {
14388 $sql .= ' AND entity IN (0,' . getEntity($tablename) . ')';
14391 $resql = $db->query($sql);
14393 while ($obj = $db->fetch_object($resql)) {
14394 $dictvalues[$obj->$rowidfield] = $obj; // $obj is stdClass
14397 dol_print_error($db);
14400 $conf->cache['dictvalues_' . $tablename] = $dictvalues;
14403 if (!empty($dictvalues[$id])) {
14405 $tmp = $dictvalues[$id];
14406 return (property_exists($tmp, $field) ? $tmp->$field : '');
14419function colorIsLight($stringcolor)
14421 $stringcolor = str_replace('#', '', $stringcolor);
14423 if (!empty($stringcolor)) {
14425 $tmp = explode(',', $stringcolor);
14426 if (count($tmp) > 1) { // This is a comma RGB ('255','255','255')
14431 $hexr = $stringcolor[0] . $stringcolor[1];
14432 $hexg = $stringcolor[2] . $stringcolor[3];
14433 $hexb = $stringcolor[4] . $stringcolor[5];
14434 $r = hexdec($hexr);
14435 $g = hexdec($hexg);
14436 $b = hexdec($hexb);
14438 $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0; // HSL algorithm
14439 if ($bright > 0.6) {
14454function isVisibleToUserType($type_user, &$menuentry, &$listofmodulesforexternal)
14456 //print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
14457 //print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
14458 if (empty($menuentry['enabled'])) {
14459 return 0; // Entry disabled by condition
14461 if ($type_user && array_key_exists('module', $menuentry) && $menuentry['module']) {
14462 $tmploops = explode('|', $menuentry['module']);
14464 foreach ($tmploops as $tmploop) {
14465 if (in_array($tmploop, $listofmodulesforexternal)) {
14471 return 0; // Entry is for menus all excluded to external users
14474 if (!$menuentry['perms'] && $type_user) {
14475 return 0; // No permissions and user is external
14477 if (!$menuentry['perms'] && getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED')) {
14478 return 0; // No permissions and option to hide when not allowed, even for internal user, is on
14480 if (!$menuentry['perms']) {
14481 return 2; // No permissions and user is external
14493function roundUpToNextMultiple($n, $x = 5)
14495 $result = (ceil($n) % $x === 0) ? ceil($n) : (round(($n + $x / 2) / $x) * $x);
14496 return (int) $result;
14510function dolGetBadge($label, $html = '', $type = 'primary', $mode = '', $url = '', $params = array())
14512 $csstouse = 'badge';
14513 $csstouse .= (!empty($mode) ? ' badge-' . $mode : '');
14514 $csstouse .= (!empty($type) ? ' badge-' . $type : '');
14515 $csstouse .= (empty($params['css']) ? '' : ' ' . $params['css']);
14518 'class' => $csstouse
14521 if (empty($html)) {
14525 if (!empty($url)) {
14526 $attr['href'] = $url;
14529 if ($mode === 'dot') {
14530 $attr['class'] .= ' classfortooltip';
14531 $attr['title'] = $html;
14532 $attr['aria-label'] = $label;
14537 if (!empty($params['attr']) && is_array($params['attr'])) {
14538 foreach ($params['attr'] as $key => $value) {
14539 if ($key == 'class') {
14540 $attr['class'] .= ' ' . $value;
14541 } elseif ($key == 'classOverride') {
14542 $attr['class'] = $value;
14544 $attr[$key] = $value;
14551 // escape all attribute
14552 $attr = array_map('dolPrintHTMLForAttribute', $attr);
14554 $TCompiledAttr = array();
14555 foreach ($attr as $key => $value) {
14556 $TCompiledAttr[] = $key . '="
' . $value . '"';
14559 $compiledAttributes = !empty($TCompiledAttr) ? implode(' ', $TCompiledAttr) : '';
14561 $tag = !empty($url) ? 'a' : 'span';
14563 return '<' . $tag . ' ' . $compiledAttributes . '>' . $html . '</' . $tag . '>';
14579function dolGetStatus($statusLabel = '', $statusLabelShort = '', $html = '', $statusType = 'status0', $displayMode = 0, $url = '', $params = array())
14584 $dolGetBadgeParams = array();
14586 if (!empty($params['badgeParams'])) {
14587 $dolGetBadgeParams = $params['badgeParams'];
14590 // TODO : add a hook
14591 if ($displayMode == 0) {
14592 $return = !empty($html) ? $html : (empty($conf->dol_optimize_smallscreen) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort));
14593 } elseif ($displayMode == 1) {
14594 $return = !empty($html) ? $html : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort);
14595 } elseif (getDolGlobalString('MAIN_STATUS_USES_IMAGES')) {
14596 // Use status with images (for backward compatibility)
14598 $htmlLabel = (in_array($displayMode, array(1, 2, 5)) ? '<span class="hideonsmartphone
">' : '') . (!empty($html) ? $html : $statusLabel) . (in_array($displayMode, array(1, 2, 5)) ? '</span>' : '');
14599 $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>' : '');
14601 // For small screen, we always use the short label instead of long label.
14602 if (!empty($conf->dol_optimize_smallscreen)) {
14603 if ($displayMode == 0) {
14605 } elseif ($displayMode == 4) {
14607 } elseif ($displayMode == 6) {
14612 // For backward compatibility. Image's filename are still in French, so we use this array to convert
14613 $statusImg = array(
14614 'status0' => 'statut0',
14615 'status1' => 'statut1',
14616 'status2' => 'statut2',
14617 'status3' => 'statut3',
14618 'status4' => 'statut4',
14619 'status5' => 'statut5',
14620 'status6' => 'statut6',
14621 'status7' => 'statut7',
14622 'status8' => 'statut8',
14623 'status9' => 'statut9'
14626 if (!empty($statusImg[$statusType])) {
14627 $htmlImg = img_picto($statusLabel, $statusImg[$statusType]);
14629 $htmlImg = img_picto($statusLabel, $statusType);
14632 if ($displayMode === 2) {
14633 $return = $htmlImg . ' ' . $htmlLabelShort;
14634 } elseif ($displayMode === 3) {
14635 $return = $htmlImg;
14636 } elseif ($displayMode === 4) {
14637 $return = $htmlImg . ' ' . $htmlLabel;
14638 } elseif ($displayMode === 5) {
14639 $return = $htmlLabelShort . ' ' . $htmlImg;
14640 } else { // $displayMode >= 6
14641 $return = $htmlLabel . ' ' . $htmlImg;
14643 } elseif (!getDolGlobalString('MAIN_STATUS_USES_IMAGES') && !empty($displayMode)) {
14645 $statusLabelShort = (empty($statusLabelShort) ? $statusLabel : $statusLabelShort);
14647 $dolGetBadgeParams['attr']['class'] = 'badge-status';
14648 if (empty($dolGetBadgeParams['attr']['title'])) {
14649 $dolGetBadgeParams['attr']['title'] = empty($params['tooltip']) ? $statusLabel : ($params['tooltip'] != 'no' ? $params['tooltip'] : '');
14650 } else { // If a title was forced from $params['badgeParams']['attr']['title'], we set the class to get it as a tooltip.
14651 $dolGetBadgeParams['attr']['class'] .= ' classfortooltip';
14652 // And if we use tooltip, we can output title in HTML @phan-suppress-next-line PhanTypeInvalidDimOffset
14653 $dolGetBadgeParams['attr']['title'] = dol_htmlentitiesbr((string) $dolGetBadgeParams['attr']['title'], 1);
14656 if ($displayMode == 3) {
14657 $return = dolGetBadge((empty($conf->dol_optimize_smallscreen) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort)), '', $statusType, 'dot', $url, $dolGetBadgeParams);
14658 } elseif ($displayMode === 5) {
14659 $return = dolGetBadge($statusLabelShort, $html, $statusType, '', $url, $dolGetBadgeParams);
14661 $return = dolGetBadge(((empty($conf->dol_optimize_smallscreen) && $displayMode != 2) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort)), $html, $statusType, '', $url, $dolGetBadgeParams);
14704function dolGetButtonAction($label, $text = '', $actionType = 'default', $url = '', $id = '', $userRight = 1, $params = array())
14706 global $hookmanager, $action, $object, $langs;
14708 // If $url is an array, we must build a dropdown button or recursively iterate over each value
14709 if (is_array($url)) {
14710 // Loop on $url array to remove entries of disabled modules
14711 foreach ($url as $key => $subbutton) {
14712 if (isset($subbutton['enabled']) && empty($subbutton['enabled'])) {
14719 if (array_key_exists('areDropdownButtons', $params) && $params["areDropdownButtons
"] === false) { // @phan-suppress-current-line PhanTypeInvalidDimOffset
14720 foreach ($url as $button) {
14721 if (!empty($button['lang'])) {
14722 $langs->load($button['lang']);
14724 $label = $langs->trans($button['label']);
14725 $text = $button['text'] ?? '';
14726 $actionType = $button['actionType'] ?? '';
14727 $tmpUrl = DOL_URL_ROOT . $button['url'] . (empty($params['backtopage']) ? '' : '&backtopage=' . urlencode($params['backtopage']));
14728 $id = $button['id'] ?? '';
14729 $userRight = $button['perm'] ?? 1;
14730 $button['params'] = $button['params'] ?? []; // @phan-suppress-current-line PhanPluginDuplicateExpressionAssignmentOperation
14732 $out .= dolGetButtonAction($label, $text, $actionType, $tmpUrl, $id, $userRight, $button['params']);
14737 if (count($url) > 1 || !empty($params["forceDropdownButtons
"])) {
14738 $out .= '<div class="dropdown
inline-block dropdown-holder
">';
14739 $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>';
14740 $out .= '<div class="dropdown-content
">';
14741 foreach ($url as $subbutton) {
14742 if (!empty($subbutton['lang'])) {
14743 $langs->load($subbutton['lang']);
14746 if (!empty($subbutton['urlraw'])) {
14747 $tmpurl = $subbutton['urlraw']; // Use raw url, no url completion, use only what developer send
14749 $tmpurl = !empty($subbutton['urlroot']) ? $subbutton['urlroot'] : $subbutton['url'];
14750 $tmpurl = dolCompletUrlForDropdownButton($tmpurl, $params, empty($subbutton['urlroot']));
14753 $subbuttonparam = array();
14754 if (!empty($subbutton['attr'])) {
14755 $subbuttonparam['attr'] = $subbutton['attr'];
14757 $subbuttonparam['isDropDown'] = (empty($params['isDropDown']) ? ($subbutton['isDropDown'] ?? false) : $params['isDropDown']);
14759 $out .= dolGetButtonAction($subbutton['text'] ?? '', $langs->trans($subbutton['label']), 'default', $tmpurl, $subbutton['id'] ?? '', $subbutton['perm'], $subbuttonparam);
14764 foreach ($url as $subbutton) { // Should loop on 1 record only
14765 if (!empty($subbutton['lang'])) {
14766 $langs->load($subbutton['lang']);
14769 if (!empty($subbutton['urlraw'])) {
14770 $tmpurl = $subbutton['urlraw']; // Use raw url, no url completion, use only what developer send
14772 $tmpurl = !empty($subbutton['urlroot']) ? $subbutton['urlroot'] : $subbutton['url'];
14773 $tmpurl = dolCompletUrlForDropdownButton($tmpurl, $params, empty($subbutton['urlroot']));
14776 $label = $langs->trans($subbutton['label']);
14777 $text = $subbutton['text'] ?? '';
14778 if (empty($text)) {
14783 $out .= dolGetButtonAction($label, $text, 'default', $tmpurl, '', $subbutton['perm'], $params);
14790 // Here, $url is a simple link
14791 if (!empty($params['isDropdown']) || !empty($params['isDropDown'])) { // Use the dropdown-item style (not for action button)
14792 $class = "dropdown-item
";
14794 $class = 'butAction';
14795 if ($actionType == 'edit') {
14796 $class = 'butAction butActionEdit';
14797 } elseif ($actionType == 'email') {
14798 $class = 'butAction butActionEmail';
14799 } elseif ($actionType == 'clone') {
14800 $class = 'butAction butActionClone';
14801 } elseif ($actionType == 'cancel') {
14802 $class = 'butAction butActionDelete';
14803 } elseif ($actionType == 'danger' || $actionType == 'delete') {
14804 $class = 'butAction butActionDelete';
14805 if (!empty($url) && strpos($url, 'token=') === false) {
14806 $url .= '&token=' . newToken();
14812 'href' => empty($url) ? '' : $url,
14816 if (empty($text)) {
14818 $attr['title'] = ''; // if html not set, using label on title is redundant
14820 $attr['title'] = $label;
14821 $attr['aria-label'] = $label;
14824 if (empty($userRight) || $userRight < 0) {
14825 $attr['class'] = 'butActionRefused';
14826 $attr['href'] = '';
14827 $attr['title'] = (($label && $text && $label != $text) ? $label : '');
14828 $attr['title'] = ($attr['title'] ? $attr['title'] . (empty($userRight) ? '<br>' : '') : '');
14829 $attr['title'] .= ((empty($userRight) && empty($label)) ? $langs->trans('NotEnoughPermissions') : '');
14837 if (!empty($params['attr']) && is_array($params['attr'])) {
14838 foreach ($params['attr'] as $key => $value) {
14839 if ($key == 'class') {
14840 $attr['class'] .= ' ' . $value;
14841 } elseif ($key == 'classOverride') {
14842 $attr['class'] = $value;
14844 $attr[$key] = $value;
14849 // automatic add tooltip when title is detected
14850 if (!empty($attr['title']) && !empty($attr['class']) && strpos($attr['class'], 'classfortooltip') === false) {
14851 $attr['class'] .= ' classfortooltip';
14854 // Js Confirm button
14855 if ($userRight && !empty($params['confirm'])) {
14856 if (!is_array($params['confirm'])) {
14857 $params['confirm'] = array();
14860 if (empty($params['confirm']['url'])) {
14861 $params['confirm']['url'] = $url . (strpos($url, '?') > 0 ? '&' : '?') . 'confirm=yes';
14864 // for js disabled compatibility set $url as call to confirm action and $params['confirm']['url'] to confirmed action
14865 $attr['data-confirm-url'] = $params['confirm']['url'];
14866 $attr['data-confirm-title'] = !empty($params['confirm']['title']) ? $params['confirm']['title'] : $langs->trans('ConfirmBtnCommonTitle', $label);
14867 $attr['data-confirm-content'] = !empty($params['confirm']['content']) ? $params['confirm']['content'] : $langs->trans('ConfirmBtnCommonContent', $label);
14868 $attr['data-confirm-content'] = preg_replace("/\r|\n/
", "", $attr['data-confirm-content']);
14869 $attr['data-confirm-action-btn-label'] = !empty($params['confirm']['action-btn-label']) ? $params['confirm']['action-btn-label'] : $langs->trans('Confirm');
14870 $attr['data-confirm-cancel-btn-label'] = !empty($params['confirm']['cancel-btn-label']) ? $params['confirm']['cancel-btn-label'] : $langs->trans('CloseDialog');
14871 $attr['data-confirm-modal'] = !empty($params['confirm']['modal']) ? $params['confirm']['modal'] : true;
14873 $attr['class'] .= ' butActionConfirm';
14876 if (isset($attr['href']) && empty($attr['href'])) {
14877 unset($attr['href']);
14880 // TODO replace this $TCompiledAttr generation block by commonHtmlAttributeBuilder like line below
14881 // $TCompiledAttr = commonHtmlAttributeBuilder($attr, $params['use_unsecured_unescapedattr'] ?? []);
14882 $TCompiledAttr = array();
14883 foreach ($attr as $key => $value) {
14884 if (!empty($params['use_unsecured_unescapedattr']) && is_array($params['use_unsecured_unescapedattr']) && in_array($key, $params['use_unsecured_unescapedattr'])) {
14885 // Deprecated, forbidden.
14886 $value = dol_htmlentities($value, ENT_QUOTES | ENT_SUBSTITUTE);
14887 } elseif (in_array($key, ['href', 'data-confirm-url'])) {
14888 $value = dolPrintHTMLForAttributeUrl($value);
14890 $value = dolPrintHTMLForAttribute($value);
14893 $TCompiledAttr[] = $key . '="' . $value . '"'; // $value has been escaped by the dolPrintHTMLForAttribute... just before
14895 $compiledAttributes = empty($TCompiledAttr) ? '' : implode(' ', $TCompiledAttr);
14897 $tag = !empty($attr['href']) ? 'a' : 'span';
14899 $parameters = array(
14900 'TCompiledAttr' => $TCompiledAttr, // array
14901 'compiledAttributes' => $compiledAttributes, // string
14906 'actionType' => $actionType,
14909 'userRight' => $userRight,
14910 'params' => $params
14913 $reshook = $hookmanager->executeHooks('dolGetButtonAction', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
14914 if ($reshook < 0) {
14915 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
14918 if (empty($reshook)) {
14919 if (dol_textishtml($text)) { // If content already HTML encoded
14920 return '<' . $tag . ' ' . $compiledAttributes . '><span class="textbutton
">' . $text . '</span></' . $tag . '>';
14922 return '<' . $tag . ' ' . $compiledAttributes . '><span class="textbutton
">' . dol_escape_htmltag($text) . '</span></' . $tag . '>';
14925 return $hookmanager->resPrint;
14959function commonHtmlAttributeBuilder($attr, array $unescapedAttr = [])
14961 $TCompiledAttr = array();
14962 if (empty($attr)) {
14966 foreach ($attr as $key => $value) {
14967 // special boolean attributes case
14968 if (in_array($key, getListOfHtmlBooleanAttributes())) {
14970 $TCompiledAttr[$key] = $key;
14975 if (!empty($unescapedAttr) && in_array($key, $unescapedAttr)) {
14977 $value = dol_htmlentities((string) $value, ENT_QUOTES | ENT_SUBSTITUTE);
14978 } elseif ($key == 'href') {
14979 $value = dolPrintHTMLForAttributeUrl((string) $value);
14981 $value = dolPrintHTMLForAttribute((string) $value);
14984 $TCompiledAttr[$key] = $key . '="
' . $value . '"'; // $value has been escaped by the dolPrintHTMLForAttribute... just before
14987 return $TCompiledAttr;
15004function getListOfHtmlBooleanAttributes(): array
15053function dolCompletUrlForDropdownButton(string $url, array $params, bool $addDolUrlRoot = true)
15059 $parsedUrl = parse_url($url);
15060 if ((isset($parsedUrl['scheme']) && in_array($parsedUrl['scheme'], ['javascript', 'mailto', 'tel'])) || strpos($url, '#') === 0) {
15064 if (!empty($parsedUrl['query'])) {
15065 // Use parse_str() function to parse the string passed via URL
15067 parse_str($parsedUrl['query'], $urlQuery);
15068 if (!isset($urlQuery['backtopage']) && isset($params['backtopage'])) {
15069 $url .= '&backtopage=' . urlencode($params['backtopage']);
15073 if (!isset($parsedUrl['scheme']) && $addDolUrlRoot) {
15074 $url = DOL_URL_ROOT . $url;
15087function dolGetButtonTitleSeparator($moreClass = "
")
15089 return '<span class="button-title-separator
' . $moreClass . '" ></span>';
15098function getFieldErrorIcon($fieldValidationErrorMsg)
15101 if (!empty($fieldValidationErrorMsg)) {
15102 $out .= '<span class="field-error-icon classfortooltip
" title="' . dol_escape_htmltag($fieldValidationErrorMsg, 1) . '" role="alert
" >'; // role alert is used for accessibility
15103 $out .= '<span class="fa fa-exclamation-circle
" aria-hidden="true" ></span>'; // For accessibility icon is separated and aria-hidden
15122function dolGetButtonTitle($label, $helpText = '', $iconClass = 'fa fa-file', $url = '', $id = '', $status = 1, $params = array())
15124 global $langs, $user;
15126 // Actually this conf is used in css too for external module compatibility and smooth transition to this function
15127 if (getDolGlobalString('MAIN_BUTTON_HIDE_UNAUTHORIZED') && (!$user->admin) && $status <= 0) {
15130 // Fix old picto fa-th-list to use fa-grid-vertical instead
15131 if ($iconClass == 'fa fa-th-list imgforviewmode') {
15132 $iconClass = ' fa fa-grip-horizontal imgforviewmode';
15135 $class = 'btnTitle';
15136 if (in_array($iconClass, array('fa fa-plus-circle', 'fa fa-plus-circle size15x', 'fa fa-comment-dots', 'fa fa-paper-plane'))) {
15137 $class .= ' btnTitlePlus';
15139 $useclassfortooltip = 1;
15141 if (!empty($params['morecss'])) {
15142 $class .= ' ' . $params['morecss'];
15147 'href' => empty($url) ? '' : $url
15150 if (!empty($helpText)) {
15151 $attr['title'] = $helpText;
15152 } elseif ($label) { // empty($attr['title']) &&
15153 $attr['title'] = $label;
15154 $useclassfortooltip = 0;
15157 if ($status == 2) {
15158 $attr['class'] .= ' btnTitleSelected';
15159 } elseif ($status <= 0) {
15160 $attr['class'] .= ' refused';
15162 $attr['href'] = '';
15164 if ($status == -1) { // disable
15165 $attr['title'] = $langs->transnoentitiesnoconv("FeatureDisabled
");
15166 } elseif ($status == 0) { // Not enough permissions
15167 $attr['title'] = $langs->transnoentitiesnoconv("NotEnoughPermissions
");
15171 if (!empty($attr['title']) && $useclassfortooltip) {
15172 $attr['class'] .= ' classfortooltip';
15180 if (!empty($params['attr']) && is_array($params['attr'])) {
15181 foreach ($params['attr'] as $key => $value) {
15182 if ($key == 'class') {
15183 $attr['class'] .= ' ' . $value;
15184 } elseif ($key == 'classOverride') {
15185 $attr['class'] = $value;
15187 $attr[$key] = $value;
15192 if (isset($attr['href']) && empty($attr['href'])) {
15193 unset($attr['href']);
15196 // TODO : add a hook
15198 // Generate attributes with escapement
15199 $TCompiledAttr = array();
15200 foreach ($attr as $key => $value) {
15201 $TCompiledAttr[] = $key . '="' . dol_escape_htmltag($value) . '"'; // Do not use dolPrintHTMLForAttribute() here, we must accept "javascript:
string"
15204 $compiledAttributes = (empty($TCompiledAttr) ? '' : implode(' ', $TCompiledAttr));
15206 $tag = (empty($attr['href']) ? 'span' : 'a');
15208 $button = '<' . $tag . ' ' . $compiledAttributes . '>';
15209 $button .= '<span class="' . $iconClass . ' valignmiddle btnTitle-icon
"></span>';
15210 if (!empty($params['forcenohideoftext'])) {
15211 $button .= '<span class="valignmiddle text-plus-circle btnTitle-label
' . (empty($params['forcenohideoftext
']) ? ' hideonsmartphone
' : '') . '">' . $label . '</span>';
15213 $button .= '</' . $tag . '>';
15228function getElementProperties($elementType)
15230 global $conf, $db, $hookmanager;
15234 //$element_type='facture';
15236 $classfile = $classname = $classpath = $subdir = $dir_output = $dir_temp = $parent_element = '';
15238 // Parse element/subelement
15239 $module = $elementType;
15240 $element = $elementType;
15241 $subelement = $elementType;
15242 $table_element = $elementType;
15244 // If we ask a resource form external module (instead of default path)
15245 if (preg_match('/^([^@]+)@([^@]+)$/i', $elementType, $regs)) { // 'myobject@mymodule'
15246 $element = $subelement = $regs[1];
15247 $module = $regs[2];
15250 // If we ask a resource for a string with an element and a subelement
15251 // Example 'project_task'
15252 if (preg_match('/^([^_]+)_([^_]+)/i', $element, $regs)) { // 'myobject_mysubobject' with myobject=mymodule
15253 $module = $element = $regs[1];
15254 $subelement = $regs[2];
15257 // Object lines will use parent classpath and module ref
15258 if (substr($elementType, -3) == 'det') {
15259 $module = preg_replace('/det$/', '', $element);
15260 $subelement = preg_replace('/det$/', '', $subelement);
15261 $classpath = $module . '/class';
15262 $classfile = $module;
15263 $classname = preg_replace('/det$/', 'Line', $element);
15264 if (in_array($module, array('expedition', 'propale', 'facture', 'contrat', 'fichinter', 'supplier_order', 'commandefournisseur'))) {
15265 $classname = preg_replace('/det$/', 'Ligne', $element);
15268 // For compatibility and to work with non standard path
15269 if ($elementType == "action
" || $elementType == "actioncomm
") {
15270 $classpath = 'comm/action/class';
15271 $subelement = 'Actioncomm';
15272 $module = 'agenda';
15273 $table_element = 'actioncomm';
15274 } elseif ($elementType == 'cronjob') {
15275 $classpath = 'cron/class';
15277 $table_element = 'cron';
15278 } elseif ($elementType == 'adherent_type') {
15279 $classpath = 'adherents/class';
15280 $classfile = 'adherent_type';
15281 $module = 'adherent';
15282 $subelement = 'adherent_type';
15283 $classname = 'AdherentType';
15284 $table_element = 'adherent_type';
15285 } elseif ($elementType == 'bank_account') {
15286 $classpath = 'compta/bank/class';
15287 $module = 'bank'; // We need $conf->bank->dir_output and not $conf->banque->dir_output
15288 $classfile = 'account';
15289 $classname = 'Account';
15290 } elseif ($elementType == 'bank_line') {
15291 $classpath = 'compta/bank/class';
15292 $module = 'bank'; // We need $conf->bank->dir_output and not $conf->banque->dir_output
15293 $classfile = 'account';
15294 $classname = 'AccountLine';
15295 } elseif ($elementType == 'category') {
15296 $classpath = 'categories/class';
15297 $module = 'categorie';
15298 $subelement = 'categorie';
15299 $table_element = 'categorie';
15300 } elseif ($elementType == 'contact') {
15301 $classpath = 'contact/class';
15302 $classfile = 'contact';
15303 $module = 'societe';
15304 $subelement = 'contact';
15305 $table_element = 'socpeople';
15306 } elseif ($elementType == 'inventory') {
15307 $module = 'product';
15308 $classpath = 'product/inventory/class';
15309 } elseif ($elementType == 'inventoryline') {
15310 $module = 'product';
15311 $classpath = 'product/inventory/class';
15312 $table_element = 'inventorydet';
15313 $parent_element = 'inventory';
15314 } elseif ($elementType == 'stock' || $elementType == 'entrepot' || $elementType == 'warehouse') {
15316 $classpath = 'product/stock/class';
15317 $classfile = 'entrepot';
15318 $classname = 'Entrepot';
15319 $table_element = 'entrepot';
15320 } elseif ($elementType == 'project') {
15321 $classpath = 'projet/class';
15322 $module = 'projet';
15323 $table_element = 'projet';
15324 } elseif ($elementType == 'project_task') {
15325 $classpath = 'projet/class';
15326 $module = 'projet';
15327 $subelement = 'task';
15328 $table_element = 'projet_task';
15329 } elseif ($elementType == 'mo') {
15330 $classpath = 'mrp/class';
15334 $table_element = 'mrp_mo';
15335 } elseif ($elementType == 'facture' || $elementType == 'invoice') {
15336 $classpath = 'compta/facture/class';
15337 $module = 'facture';
15338 $subelement = 'facture';
15339 $table_element = 'facture';
15340 } elseif ($elementType == 'facturedet') {
15341 $classpath = 'compta/facture/class';
15342 $classfile = 'facture';
15343 $classname = 'FactureLigne';
15344 $module = 'facture';
15345 $table_element = 'facturedet';
15346 $parent_element = 'facture';
15347 } elseif ($elementType == 'facturerec' || $elementType == 'facture_rec') {
15348 $classpath = 'compta/facture/class';
15349 $classfile = 'facture-rec';
15350 $module = 'facture';
15351 $classname = 'FactureRec';
15352 } elseif ($elementType == 'commande' || $elementType == 'order') {
15353 $classpath = 'commande/class';
15354 $module = 'commande';
15355 $subelement = 'commande';
15356 $table_element = 'commande';
15357 } elseif ($elementType == 'commandedet') {
15358 $classpath = 'commande/class';
15359 $classfile = 'commande';
15360 $classname = 'OrderLine';
15361 $module = 'commande';
15362 $table_element = 'commandedet';
15363 $parent_element = 'commande';
15364 } elseif ($elementType == 'propal') {
15365 $classpath = 'comm/propal/class';
15366 $table_element = 'propal';
15367 } elseif ($elementType == 'propaldet') {
15368 $classpath = 'comm/propal/class';
15369 $classfile = 'propal';
15370 $subelement = 'propaleligne';
15371 $module = 'propal';
15372 $table_element = 'propaldet';
15373 $parent_element = 'propal';
15374 } elseif ($elementType == 'shipping' || $elementType == 'shipment') {
15375 $classpath = 'expedition/class';
15376 $classfile = 'expedition';
15377 $classname = 'Expedition';
15378 $module = 'expedition';
15379 $table_element = 'expedition';
15380 } elseif ($elementType == 'expeditiondet' || $elementType == 'shippingdet') {
15381 $classpath = 'expedition/class';
15382 $classfile = 'expedition';
15383 $classname = 'ExpeditionLigne';
15384 $module = 'expedition';
15385 $table_element = 'expeditiondet';
15386 $parent_element = 'expedition';
15387 } elseif ($elementType == 'delivery_note') {
15388 $classpath = 'delivery/class';
15389 $subelement = 'delivery';
15390 $module = 'expedition';
15391 } elseif ($elementType == 'delivery') {
15392 $classpath = 'delivery/class';
15393 $subelement = 'delivery';
15394 $module = 'expedition';
15395 } elseif ($elementType == 'deliverydet') {
15397 } elseif ($elementType == 'supplier_proposal') {
15398 $classpath = 'supplier_proposal/class';
15399 $module = 'supplier_proposal';
15400 $element = 'supplierproposal';
15401 $classfile = 'supplier_proposal';
15402 $subelement = 'supplierproposal';
15403 } elseif ($elementType == 'supplier_proposaldet') {
15404 $classpath = 'supplier_proposal/class';
15405 $module = 'supplier_proposal';
15406 $classfile = 'supplier_proposal';
15407 $classname = 'SupplierProposalLine';
15408 $table_element = 'supplier_proposaldet';
15409 $parent_element = 'supplier_proposal';
15410 } elseif ($elementType == 'contract') {
15411 $classpath = 'contrat/class';
15412 $module = 'contrat';
15413 $subelement = 'contrat';
15414 $table_element = 'contract';
15415 } elseif ($elementType == 'contratdet') {
15416 $classpath = 'contrat/class';
15417 $module = 'contrat';
15418 $table_element = 'contratdet';
15419 $parent_element = 'contrat';
15420 } elseif ($elementType == 'mailing') {
15421 $classpath = 'comm/mailing/class';
15422 $module = 'mailing';
15423 $classfile = 'mailing';
15424 $classname = 'Mailing';
15426 } elseif ($elementType == 'member' || $elementType == 'adherent') {
15427 $classpath = 'adherents/class';
15428 $module = 'adherent';
15429 $subelement = 'adherent';
15430 $table_element = 'adherent';
15431 } elseif ($elementType == 'subscription') {
15432 $classpath = 'adherents/class';
15433 $classfile = 'subscription';
15434 $module = 'adherent';
15435 $subelement = 'subscription';
15436 $classname = 'Subscription';
15437 $table_element = 'subscription';
15438 } elseif ($elementType == 'usergroup') {
15439 $classpath = 'user/class';
15441 } elseif ($elementType == 'mo' || $elementType == 'mrp') {
15442 $classpath = 'mrp/class';
15447 $table_element = 'mrp_mo';
15448 } elseif ($elementType == 'mrp_production') {
15449 $classpath = 'mrp/class';
15451 $classname = 'MoLine';
15454 $table_element = 'mrp_production';
15455 $parent_element = 'mo';
15456 } elseif ($elementType == 'cabinetmed_cons') {
15457 $classpath = 'cabinetmed/class';
15458 $module = 'cabinetmed';
15459 $subelement = 'cabinetmedcons';
15460 $table_element = 'cabinetmedcons';
15461 } elseif ($elementType == 'fichinter') {
15462 $classpath = 'fichinter/class';
15463 $module = 'ficheinter';
15464 $subelement = 'fichinter';
15465 $table_element = 'fichinter';
15466 } elseif ($elementType == 'dolresource' || $elementType == 'resource') {
15467 $classpath = 'resource/class';
15468 $module = 'resource';
15469 $subelement = 'dolresource';
15470 $table_element = 'resource';
15471 } elseif ($elementType == 'opensurvey_sondage') {
15472 $classpath = 'opensurvey/class';
15473 $module = 'opensurvey';
15474 $subelement = 'opensurveysondage';
15475 } elseif ($elementType == 'order_supplier' || $elementType == 'supplier_order' || $elementType == 'commande_fournisseur' || $elementType == 'commandefournisseur') {
15476 $classpath = 'fourn/class';
15477 $module = 'fournisseur';
15478 $classfile = 'fournisseur.commande';
15479 $element = 'order_supplier';
15481 $classname = 'CommandeFournisseur';
15482 $table_element = 'commande_fournisseur';
15483 } elseif ($elementType == 'commande_fournisseurdet') {
15484 $classpath = 'fourn/class';
15485 $module = 'fournisseur';
15486 $classfile = 'fournisseur.commande';
15487 $element = 'commande_fournisseurdet';
15489 $classname = 'CommandeFournisseurLigne';
15490 $table_element = 'commande_fournisseurdet';
15491 $parent_element = 'commande_fournisseur';
15492 } elseif ($elementType == 'invoice_supplier' || $elementType == 'supplier_invoice' || $elementType == 'facture_fourn') {
15493 $classpath = 'fourn/class';
15494 $module = 'fournisseur';
15495 $classfile = 'fournisseur.facture';
15496 $element = 'invoice_supplier';
15498 $classname = 'FactureFournisseur';
15499 $table_element = 'facture_fourn';
15500 } elseif ($elementType == 'facture_fourn_det') {
15501 $classpath = 'fourn/class';
15502 $module = 'fournisseur';
15503 $classfile = 'fournisseur.facture';
15504 $element = 'facture_fourn_det';
15506 $classname = 'SupplierInvoiceLine';
15507 $table_element = 'facture_fourn_det';
15508 $parent_element = 'invoice_supplier';
15509 } elseif ($elementType == "service
") {
15510 $classpath = 'product/class';
15511 $subelement = 'product';
15512 $table_element = 'product';
15513 } elseif ($elementType == 'product_attribute') {
15514 $module = 'variants';
15515 $element = 'product_attribute';
15516 $subelement = 'product_attribute';
15517 $classpath = 'variants/class';
15518 $classfile = 'ProductAttribute';
15519 $classname = 'ProductAttribute';
15520 $table_element = 'product_attribute';
15521 } elseif ($elementType == 'product_attribute_value') {
15522 $module = 'variants';
15523 $element = 'product_attribute_value';
15524 $subelement = 'product_attribute_value';
15525 $classpath = 'variants/class';
15526 $classfile = 'ProductAttributeValue';
15527 $classname = 'ProductAttributeValue';
15528 $table_element = 'product_attribute_value';
15529 $parent_element = 'product_attribute';
15530 } elseif ($elementType == 'salary') {
15531 $classpath = 'salaries/class';
15532 $module = 'salaries';
15533 } elseif ($elementType == 'payment_salary') {
15534 $classpath = 'salaries/class';
15535 $classfile = 'paymentsalary';
15536 $classname = 'PaymentSalary';
15537 $module = 'salaries';
15538 } elseif ($elementType == 'productlot') {
15539 $module = 'productbatch';
15540 $classpath = 'product/stock/class';
15541 $classfile = 'productlot';
15542 $classname = 'Productlot';
15543 $element = 'productlot';
15545 $table_element = 'product_lot';
15546 } elseif ($elementType == 'societeaccount') {
15547 $classpath = 'societe/class';
15548 $classfile = 'societeaccount';
15549 $classname = 'SocieteAccount';
15550 $module = 'societe';
15551 } elseif ($elementType == 'websitepage' || $elementType == 'website_page') {
15552 $classpath = 'website/class';
15553 $classfile = 'websitepage';
15554 $classname = 'Websitepage';
15555 $module = 'website';
15556 $subelement = 'websitepage';
15557 $table_element = 'website_page';
15558 } elseif ($elementType == 'fiscalyear') {
15559 $classpath = 'core/class';
15560 $module = 'accounting';
15561 $subelement = 'fiscalyear';
15562 } elseif ($elementType == 'chargesociales') {
15563 $classpath = 'compta/sociales/class';
15565 $table_element = 'chargesociales';
15566 } elseif ($elementType == 'tva') {
15567 $classpath = 'compta/tva/class';
15570 $table_element = 'tva';
15571 } elseif ($elementType == 'emailsenderprofile') {
15573 $classpath = 'core/class';
15574 $classfile = 'emailsenderprofile';
15575 $classname = 'EmailSenderProfile';
15576 $table_element = 'c_email_senderprofile';
15578 } elseif ($elementType == 'conferenceorboothattendee') {
15579 $classpath = 'eventorganization/class';
15580 $classfile = 'conferenceorboothattendee';
15581 $classname = 'ConferenceOrBoothAttendee';
15582 $module = 'eventorganization';
15583 } elseif ($elementType == 'conferenceorbooth') {
15584 $classpath = 'eventorganization/class';
15585 $classfile = 'conferenceorbooth';
15586 $classname = 'ConferenceOrBooth';
15587 $module = 'eventorganization';
15588 } elseif ($elementType == 'ccountry') {
15590 $classpath = 'core/class';
15591 $classfile = 'ccountry';
15592 $classname = 'Ccountry';
15593 $table_element = 'c_country';
15595 } elseif ($elementType == 'ecmfiles') {
15597 $classpath = 'ecm/class';
15598 $classfile = 'ecmfiles';
15599 $classname = 'Ecmfiles';
15600 $table_element = 'ecmfiles';
15602 } elseif ($elementType == 'knowledgerecord' || $elementType == 'knowledgemanagement') {
15603 $module = 'knowledgemanagement';
15604 $classpath = 'knowledgemanagement/class';
15605 $classfile = 'knowledgerecord';
15606 $classname = 'KnowledgeRecord';
15607 $table_element = 'knowledgemanagement_knowledgerecord';
15609 } elseif ($elementType == 'customer') {
15610 $module = 'societe';
15611 $classpath = 'societe/class';
15612 $classfile = 'client';
15613 $classname = 'Client';
15614 $table_element = 'societe';
15616 } elseif ($elementType == 'fournisseur' || $elementType == 'supplier') {
15617 $module = 'societe';
15618 $classpath = 'fourn/class';
15619 $classfile = 'fournisseur';
15620 $classname = 'Fournisseur';
15621 $table_element = 'societe';
15623 } elseif ($elementType == 'recruitmentcandidature') {
15624 $module = 'recruitment';
15625 $classfile = 'recruitmentcandidature';
15626 $classpath = 'recruitment/class';
15627 $classname = 'RecruitmentCandidature';
15628 $subelement = 'recruitmentcandidature';
15629 $subdir = '/recruitmentcandidature';
15630 } elseif ($elementType == 'recruitmentjobposition') {
15631 $module = 'recruitment';
15632 $classfile = 'recruitmentjobposition';
15633 $classpath = 'recruitment/class';
15634 $classname = 'RecruitmentJobPosition';
15635 $subelement = 'recruitmentjobposition';
15636 $subdir = '/recruitmentjobposition';
15640 if (empty($classfile)) {
15641 $classfile = strtolower($subelement);
15643 if (empty($classname)) {
15644 $classname = ucfirst($subelement);
15646 if (empty($classpath)) {
15647 $classpath = $module . '/class';
15650 //print 'getElementProperties subdir='.$subdir;
15653 if ($module && isset($conf->$module)) { // The generic case
15654 if (!empty($conf->$module->multidir_output[$conf->entity])) {
15655 $dir_output = $conf->$module->multidir_output[$conf->entity];
15656 } elseif (!empty($conf->$module->output[$conf->entity])) {
15657 $dir_output = $conf->$module->output[$conf->entity];
15658 } elseif (!empty($conf->$module->dir_output)) {
15659 $dir_output = $conf->$module->dir_output;
15661 if (!empty($conf->$module->multidir_temp[$conf->entity])) {
15662 $dir_temp = $conf->$module->multidir_temp[$conf->entity];
15663 } elseif (!empty($conf->$module->temp[$conf->entity])) {
15664 $dir_temp = $conf->$module->temp[$conf->entity];
15665 } elseif (!empty($conf->$module->dir_temp)) {
15666 $dir_temp = $conf->$module->dir_temp;
15670 // Overwrite value for special cases
15671 if ($element == 'order_supplier' && isModEnabled('fournisseur')) {
15672 $dir_output = $conf->fournisseur->commande->dir_output;
15673 $dir_temp = $conf->fournisseur->commande->dir_temp;
15674 } elseif ($element == 'invoice_supplier' && isModEnabled('fournisseur')) {
15675 $dir_output = $conf->fournisseur->facture->dir_output;
15676 $dir_temp = $conf->fournisseur->facture->dir_temp;
15678 $dir_output .= $subdir;
15679 $dir_temp .= $subdir;
15681 $elementProperties = array(
15682 'module' => $module,
15683 'element' => $element,
15684 'table_element' => $table_element,
15685 'subelement' => $subelement,
15686 'classpath' => $classpath,
15687 'classfile' => $classfile,
15688 'classname' => $classname,
15689 'dir_output' => $dir_output,
15690 'dir_temp' => $dir_temp,
15691 'parent_element' => $parent_element,
15696 if (!is_object($hookmanager)) {
15697 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
15698 $hookmanager = new HookManager($db);
15700 $hookmanager->initHooks(array('elementproperties'));
15704 $parameters = array(
15705 'elementType' => $elementType,
15706 'elementProperties' => $elementProperties
15709 $reshook = $hookmanager->executeHooks('getElementProperties', $parameters);
15712 $elementProperties = $hookmanager->resArray;
15713 } elseif (!empty($hookmanager->resArray) && is_array($hookmanager->resArray)) { // resArray is always an array but for security against misconfigured external modules
15714 $elementProperties = array_replace($elementProperties, $hookmanager->resArray);
15717 // context of elementproperties doesn't need to exist out of this function so delete it to avoid elementproperties context is equal to all
15718 if (($key = array_search('elementproperties', $hookmanager->contextarray)) !== false) {
15719 unset($hookmanager->contextarray[$key]);
15722 return $elementProperties;
15738function fetchObjectByElement($element_id, $element_type, $element_ref = '', $useCache = 0, $maxCacheByType = 10)
15744 $element_prop = getElementProperties($element_type);
15745 //var_dump($element_prop); exit;
15747 if ($element_prop['module'] == 'product' || $element_prop['module'] == 'service') {
15748 // For example, for an extrafield 'product' (shared for both product and service) that is a link to an object,
15749 // this is called with $element_type = 'product' when we need element properties of a service, we must return a product. If we create the
15750 // extrafield for a service, it is not supported and not found when editing the product/service card. So we must keep 'product' for extrafields
15751 // of service and we will return properties of a product.
15752 $ismodenabled = (isModEnabled('product') || isModEnabled('service'));
15753 } elseif ($element_prop['module'] == 'societeaccount') {
15754 $ismodenabled = isModEnabled('website') || isModEnabled('webportal');
15756 $ismodenabled = isModEnabled($element_prop['module']);
15758 //var_dump('element_type='.$element_type);
15759 //var_dump($element_prop);
15760 //var_dump($element_prop['module'].' '.$ismodenabled);
15761 if (is_array($element_prop) && (empty($element_prop['module']) || $ismodenabled)) {
15762 if ($useCache === 1 && $element_id > 0
15763 && !empty($conf->cache['fetchObjectByElement'][$element_type])
15764 && !empty($conf->cache['fetchObjectByElement'][$element_type][$element_id])
15765 && is_object($conf->cache['fetchObjectByElement'][$element_type][$element_id])
15767 return $conf->cache['fetchObjectByElement'][$element_type][$element_id];
15770 dol_include_once('/' . $element_prop['classpath'] . '/' . $element_prop['classfile'] . '.class.php');
15772 if (class_exists($element_prop['classname'])) {
15773 $className = $element_prop['classname'];
15774 $objecttmp = new $className($db);
15775 '@phan-var-force CommonObject $objecttmp';
15778 if ($element_id > 0 || !empty($element_ref)) {
15779 $ret = $objecttmp->fetch($element_id, $element_ref);
15781 if (empty($objecttmp->module)) {
15782 $objecttmp->module = $element_prop['module'];
15785 if ($useCache > 0) {
15786 if (!isset($conf->cache['fetchObjectByElement'][$element_type])) {
15787 $conf->cache['fetchObjectByElement'][$element_type] = [];
15790 // Manage cache limit
15791 if (! empty($conf->cache['fetchObjectByElement'][$element_type]) && is_array($conf->cache['fetchObjectByElement'][$element_type]) && count($conf->cache['fetchObjectByElement'][$element_type]) >= $maxCacheByType) {
15792 array_shift($conf->cache['fetchObjectByElement'][$element_type]);
15795 $conf->cache['fetchObjectByElement'][$element_type][$element_id] = $objecttmp;
15801 return $objecttmp; // returned an object without fetch
15804 dol_syslog($element_prop['classname'] . ' doesn\'t exists in /' . $element_prop['classpath'] . '/' . $element_prop['classfile'] . '.class.php');
15817function getExecutableContent()
15819 $arrayofregexextension = array(
15846 return $arrayofregexextension;
15855function isAFileWithExecutableContent($filename)
15857 $arrayofregexextension = getExecutableContent();
15859 foreach ($arrayofregexextension as $fileextension) {
15860 if (preg_match('/\.' . preg_quote($fileextension, '/') . '$/i', $filename)) {
15877 return empty($_SESSION['newtoken']) ? '' : $_SESSION['newtoken'];
15887function currentToken()
15889 return isset($_SESSION['token']) ? $_SESSION['token'] : '';
15901 if (empty($conf->cache['nonce'])) {
15902 include_once DOL_DOCUMENT_ROOT . '/core/lib/security.lib.php';
15903 $conf->cache['nonce'] = dolGetRandomBytes(8);
15906 return $conf->cache['nonce'];
15923function startSimpleTable($header, $link = "
", $arguments = "", $emptyColumns = 0, $number = -1, $pictofulllist = '')
15927 print '<div class="div-
table-responsive-no-min
">';
15928 print '<table class="noborder centpercent
">';
15929 print '<tr class="liste_titre
">';
15931 print ($emptyColumns < 1) ? '<th>' : '<th colspan="' . ($emptyColumns + 1) . '">';
15933 print '<span class="valignmiddle
">' . $langs->trans($header) . '</span>';
15935 if (!empty($link)) {
15936 if (!empty($arguments)) {
15937 print '<a href="' . DOL_URL_ROOT . '/
' . $link . '?
' . $arguments . '">';
15939 print '<a href="' . DOL_URL_ROOT . '/
' . $link . '">';
15943 if ($number > -1) {
15944 print '<span class="badge marginleftonlyshort
">' . $number . '</span>';
15945 } elseif (!empty($link)) {
15946 print '<span class="badge marginleftonlyshort
">...</span>';
15949 if (!empty($link)) {
15955 if ($number < 0 && !empty($link)) {
15956 print '<th class="right
">';
15971function finishSimpleTable($addLineBreak = false)
15976 if ($addLineBreak) {
15992function addSummaryTableLine($tableColumnCount, $num, $nbofloop = 0, $total = 0, $noneWord = "None
", $extraRightColumn = false)
15997 print '<tr class="oddeven
">';
15998 print '<td colspan="' . $tableColumnCount . '"><span class="opacitymedium
">' . $langs->trans($noneWord) . '</span></td>';
16003 if ($nbofloop === 0) {
16004 // don't show a summary line
16008 /* Case already handled above, commented to satisfy phpstan.
16010 $colspan = $tableColumnCount;
16013 if ($num > $nbofloop) {
16014 $colspan = $tableColumnCount;
16016 $colspan = $tableColumnCount - 1;
16019 if ($extraRightColumn) {
16023 print '<tr class="liste_total
">';
16025 if ($nbofloop > 0 && $num > $nbofloop) {
16026 print '<td colspan="' . $colspan . '" class="right
">' . $langs->trans("XMoreLines
", ($num - $nbofloop)) . '</td>';
16028 print '<td colspan="' . $colspan . '" class="right
"> ' . $langs->trans("Total
") . '</td>';
16029 print '<td class="right centpercent
">' . price($total) . '</td>';
16032 if ($extraRightColumn) {
16047function readfileLowMemory($fullpath_original_file_osencoded, $method = -1)
16049 if ($method == -1) {
16051 if (getDolGlobalString('MAIN_FORCE_READFILE_WITH_FREAD')) {
16054 if (getDolGlobalString('MAIN_FORCE_READFILE_WITH_STREAM_COPY')) {
16059 // Be sure we don't have output buffering enabled to have readfile working correctly
16060 $level = ob_get_level();
16062 while (ob_get_level() > $level) {
16067 if ($method == 0) {
16068 readfile($fullpath_original_file_osencoded);
16069 } elseif ($method == 1) {
16071 $handle = fopen($fullpath_original_file_osencoded, "rb
");
16072 while (!feof($handle)) {
16073 print fread($handle, 8192);
16076 } elseif ($method == 2) {
16078 $handle1 = fopen($fullpath_original_file_osencoded, "rb
");
16079 $handle2 = fopen("php:
16080 stream_copy_to_stream($handle1, $handle2);
16101 $result =
'<span class="clipboardCP' . ($showonlyonhover ?
' clipboardCPShowOnHover valignmiddle' :
'') .
'">';
16102 if ($texttoshow ===
'none') {
16103 $result .=
'<' . $tag .
' class="clipboardCPValue hidewithsize">' .
dol_escape_htmltag($valuetocopy, 1, 1) .
'</' . $tag .
'>';
16104 $result .=
'<span class="clipboardCPValueToPrint"></span>';
16105 } elseif ($texttoshow) {
16106 $result .=
'<' . $tag .
' class="clipboardCPValue hidewithsize">' .
dol_escape_htmltag($valuetocopy, 1, 1) .
'</' . $tag .
'>';
16107 $result .=
'<span class="clipboardCPValueToPrint">' .
dol_escape_htmltag($texttoshow, 1, 1) .
'</span>';
16109 $result .=
'<' . $tag .
' class="clipboardCPValue">' .
dol_escape_htmltag($valuetocopy, 1, 1) .
'</' . $tag .
'>';
16111 $result .=
'<span class="clipboardCPButton far fa-clipboard opacitymedium paddingleft pictomodule" title="' .
dolPrintHTML($langs->trans(
"ClickToCopyToClipboard")) .
'"></span>';
16112 $result .=
img_picto(
'',
'tick',
'class="clipboardCPTick hidden paddingleft pictomodule"');
16113 $result .=
'<span class="clipboardCPText"></span>';
16114 $result .=
'</span>';
16129 $result = json_decode($stringtodecode, $assoc);
16130 if ($result ===
null) {
16131 $result = unserialize($stringtodecode, [
'allowed_classes' =>
false]);
16159 if (is_null($filter) || !is_string($filter) || $filter ===
'') {
16162 if (!preg_match(
'/^\(.*\)$/', $filter)) {
16163 $filter =
'(' . $filter .
')';
16166 $regexstring =
'\(([a-zA-Z0-9_\.]+:[<>!=insotlke]+:[^\(\)]+)\)';
16167 $firstandlastparenthesis = 0;
16169 if (!
dolCheckFilters($filter, $errorstr, $firstandlastparenthesis)) {
16173 return 'Filter syntax error - ' . $errorstr;
16178 $t = preg_replace_callback(
'/' . $regexstring .
'/i',
'dolForgeDummyCriteriaCallback', $filter);
16179 $t = str_ireplace(array(
'and',
'or',
' '),
'', $t);
16182 if (preg_match(
'/[^\(\)]/', $t)) {
16183 $tmperrorstr =
'Bad syntax of the search string';
16184 $errorstr =
'Bad syntax of the search string: ' . $filter;
16188 dol_syslog(
"forgeSQLFromUniversalSearchCriteria Filter error - " . $errorstr, LOG_WARNING);
16189 return 'Filter error - ' . $tmperrorstr;
16193 global $globalforbiddenfields;
16194 $globalforbiddenfields = $forbiddenfields;
16196 $ret = ($noand ?
"" :
" AND ") . ($nopar ?
"" :
'(');
16197 $ret .= preg_replace_callback(
'/' . $regexstring .
'/i',
'dolForgeSQLCriteriaCallback', $filter);
16198 $ret .= ($nopar ?
"" :
')');
16200 if (is_object(
$db)) {
16201 $ret = str_replace(
'__NOW__',
"'" .
$db->idate(
dol_now()) .
"'", $ret);
16203 if (is_object($user)) {
16204 $ret = str_replace(
'__USER_ID__', (
string) $user->id, $ret);
16219 $arrayofandtags = array();
16223 $parenthesislevel = 0;
16228 if ($parenthesislevel >= 1) {
16229 $sqlfilters = preg_replace(
'/^\(/',
'', preg_replace(
'/\)$/',
'', $sqlfilters));
16234 $countparenthesis = 0;
16235 while ($i < $nbofchars) {
16238 if ($char ==
'(') {
16239 $countparenthesis++;
16240 } elseif ($char ==
')') {
16241 $countparenthesis--;
16244 if ($countparenthesis == 0) {
16245 $char2 =
dol_substr($sqlfilters, $i + 1, 1);
16246 $char3 =
dol_substr($sqlfilters, $i + 2, 1);
16247 if ($char ==
'A' && $char2 ==
'N' && $char3 ==
'D') {
16250 if (!preg_match(
'/^\(.*\)$/', $s)) {
16251 $s =
'(' . $s .
')';
16253 $arrayofandtags[] = $s;
16266 if (!preg_match(
'/^\(.*\)$/', $s)) {
16267 $s =
'(' . $s .
')';
16269 $arrayofandtags[] = $s;
16272 return $arrayofandtags;
16284function dolCheckFilters($sqlfilters, &$error =
'', &$parenthesislevel = 0)
16288 $tmp = $sqlfilters;
16292 $parenthesislevel = 0;
16300 if ($char ==
'(') {
16301 if ($i == $parenthesislevel && $parenthesislevel == $counter) {
16303 $parenthesislevel++;
16306 } elseif ($char ==
')') {
16307 $nbcharremaining = ($nb - $i - 1);
16308 if ($nbcharremaining >= $counter) {
16309 $parenthesislevel = min($parenthesislevel, $counter - 1);
16311 if ($parenthesislevel > $counter && $nbcharremaining >= $counter) {
16312 $parenthesislevel = $counter;
16317 if ($counter < 0) {
16318 $error =
"Wrong balance of parenthesis in sqlfilters=" . $sqlfilters;
16319 $parenthesislevel = 0;
16327 if ($counter > 0) {
16328 $error =
"Wrong balance of parenthesis in sqlfilters=" . $sqlfilters;
16329 $parenthesislevel = 0;
16347 if (empty($matches[1])) {
16350 $tmp = explode(
':', $matches[1]);
16351 if (count($tmp) < 3) {
16370 global $globalforbiddenfields;
16373 if (empty($matches[1])) {
16376 $tmp = explode(
':', $matches[1], 3);
16377 if (count($tmp) < 3) {
16383 $newforbiddenfields = $globalforbiddenfields;
16384 if (!is_array($newforbiddenfields)) {
16385 $newforbiddenfields = array();
16388 $newforbiddenfields[] =
'pass';
16389 $newforbiddenfields[] =
'pass_crypted';
16390 $newforbiddenfields[] =
'api_key';
16392 $operand = preg_replace(
'/[^a-z0-9\._]/i',
'', trim($tmp[0]));
16395 if (!empty($newforbiddenfields)) {
16396 $operandwithoutprefix = preg_replace(
'/^[a-z0-9_]+\./i',
'', $operand);
16397 if (in_array(strtolower($operandwithoutprefix), $newforbiddenfields)) {
16402 $operator = strtoupper(preg_replace(
'/[^a-z<>!=]/i',
'', trim($tmp[1])));
16405 'NOTLIKE' =>
'NOT LIKE',
16406 'ISNOT' =>
'IS NOT',
16407 'NOTIN' =>
'NOT IN',
16411 if (array_key_exists($operator, $realOperator)) {
16412 $operator = $realOperator[$operator];
16415 $tmpescaped = $tmp[2];
16421 if ($operator ==
'IN' || $operator ==
'NOT IN') {
16422 global $dolibarr_allow_unsecured_select_in_extrafields_filter;
16425 $tmpescaped2 =
'(';
16427 $tmpelemarray = explode(
',', $tmpescaped);
16428 foreach ($tmpelemarray as $tmpkey => $tmpelem) {
16430 $tmpelem = trim($tmpelem);
16431 if (preg_match(
'/^\'(.*)\'$/', $tmpelem, $reg)) {
16432 $tmpelemarray[$tmpkey] =
"'" .
$db->escape(
$db->sanitize($reg[1], 2, 1, 1, 1)) .
"'";
16433 $tmpelemarray[$tmpkey] =
"'".$db->escape(
$db->sanitize($reg[1], 2, 1, 1, 1)).
"'";
16434 } elseif (preg_match(
'/^[0-9]+$/', (
string) $tmpelem)) {
16435 $tmpelemarray[$tmpkey] = (int) $tmpelem;
16436 } elseif (is_numeric((
string) $tmpelem)) {
16437 $tmpelemarray[$tmpkey] = (float) $tmpelem;
16438 } elseif (!empty($dolibarr_allow_unsecured_select_in_extrafields_filter)) {
16439 $tmpelemarray[$tmpkey] = preg_replace(
'/[^a-z0-9_<>=!\s]/i',
'', $tmpelem);
16441 $tmpelemarray[$tmpkey] = preg_replace(
'/[^a-z0-9_]/i',
'', $tmpelem);
16444 $tmpescaped2 .= implode(
',', $tmpelemarray);
16445 $tmpescaped2 .=
')';
16447 $tmpescaped = $tmpescaped2;
16448 } elseif ($operator ==
'LIKE' || $operator ==
'NOT LIKE') {
16449 if (preg_match(
'/^\'([^\']*)\'$/', $tmpescaped, $regbis)) {
16450 $tmpescaped = $regbis[1];
16453 $tmpescaped =
"'" .
$db->escape($tmpescaped) .
"'";
16454 } elseif (preg_match(
'/^\'(.*)\'$/', $tmpescaped, $regbis)) {
16457 $tmpescaped =
"'" .
$db->escape($regbis[1]) .
"'";
16459 if (strtoupper($tmpescaped) ==
'NULL') {
16460 $tmpescaped =
'NULL';
16461 } elseif (preg_match(
'/^[0-9]+$/', (
string) $tmpescaped)) {
16462 $tmpescaped = (int) $tmpescaped;
16463 } elseif (is_numeric((
string) $tmpescaped)) {
16464 $tmpescaped = (float) $tmpescaped;
16466 $tmpescaped = preg_replace(
'/[^a-z0-9_]/i',
'', $tmpescaped);
16470 return '(' .
$db->escape($operand) .
' ' . strtoupper($operator) .
' ' . $tmpescaped .
')';
16485 dol_syslog(
'getTimelineIcon::begin', LOG_DEBUG);
16488 $out =
'<!-- timeline icon -->' .
"\n";
16489 $iconClass =
'fa fa-comments';
16494 if ($histo[$key][
'percent'] == -1) {
16495 $colorClass =
'timeline-icon-not-applicble';
16496 $pictoTitle = $langs->trans(
'StatusNotApplicable');
16497 } elseif ($histo[$key][
'percent'] == 0) {
16498 $colorClass =
'timeline-icon-todo';
16499 $pictoTitle = $langs->trans(
'StatusActionToDo') .
' (0%)';
16500 } elseif ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100) {
16501 $colorClass =
'timeline-icon-in-progress';
16502 $pictoTitle = $langs->trans(
'StatusActionInProcess') .
' (' . $histo[$key][
'percent'] .
'%)';
16503 } elseif ($histo[$key][
'percent'] >= 100) {
16504 $colorClass =
'timeline-icon-done';
16505 $pictoTitle = $langs->trans(
'StatusActionDone') .
' (100%)';
16508 if ($actionstatic->code ==
'AC_TICKET_CREATE') {
16509 $iconClass =
'fa fa-ticket';
16510 } elseif ($actionstatic->code ==
'AC_TICKET_MODIFY') {
16511 $iconClass =
'fa fa-pencilxxx';
16512 } elseif (preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
16513 $iconClass =
'fa fa-comments';
16514 } elseif (preg_match(
'/^TICKET_MSG_PRIVATE/', $actionstatic->code)) {
16515 $iconClass =
'fa fa-mask';
16517 if ($actionstatic->type_picto) {
16518 $img_picto =
img_picto(
'', $actionstatic->type_picto);
16520 if ($actionstatic->type_code ==
'AC_RDV') {
16521 $iconClass =
'fa fa-handshake';
16522 } elseif ($actionstatic->type_code ==
'AC_TEL') {
16523 $iconClass =
'fa fa-phone';
16524 } elseif ($actionstatic->type_code ==
'AC_FAX') {
16525 $iconClass =
'fa fa-fax';
16526 } elseif ($actionstatic->type_code ==
'AC_EMAIL') {
16527 $iconClass =
'fa fa-envelope';
16528 } elseif ($actionstatic->type_code ==
'AC_INT') {
16529 $iconClass =
'fa fa-shipping-fast';
16530 } elseif ($actionstatic->type_code ==
'AC_OTH_AUTO') {
16531 $iconClass =
'fa fa-robot';
16532 } elseif (!preg_match(
'/_AUTO/', $actionstatic->type_code)) {
16533 $iconClass =
'fa fa-robot';
16538 $out .=
'<i class="' . $iconClass .
' ' . $colorClass .
'" title="' . $pictoTitle .
'">' . $img_picto .
'</i>' .
"\n";
16552 $documents = array();
16554 $sql =
'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.filepath, ecm.filename, ecm.agenda_id';
16555 $sql .=
' FROM ' . MAIN_DB_PREFIX .
'ecm_files ecm';
16556 $sql .=
" WHERE ecm.filepath = 'agenda/" . ((int)
$object->id) .
"'";
16558 $sql .=
' OR ecm.agenda_id = ' . (int)
$object->id;
16559 $sql .=
' ORDER BY ecm.position ASC';
16561 $resql =
$db->query($sql);
16563 if (
$db->num_rows($resql)) {
16564 while ($obj =
$db->fetch_object($resql)) {
16565 $documents[$obj->id] = $obj;
16591function show_actions_messaging(
$conf, $langs,
$db, $filterobj, $objcon =
null, $noprint = 0, $actioncode =
'', $donetodo =
'done', $filters = array(), $sortfield =
'a.datep,a.id', $sortorder =
'DESC')
16593 dol_syslog(
'show_actions_messaging::begin', LOG_DEBUG);
16594 global $user,
$conf;
16597 global $param, $massactionbutton;
16599 require_once DOL_DOCUMENT_ROOT .
'/comm/action/class/actioncomm.class.php';
16602 if (!is_object($filterobj) && !is_object($objcon)) {
16607 '@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';
16612 $sortfield_list = explode(
',', $sortfield);
16613 $sortfield_label_list = array(
'a.id' =>
'id',
'a.datep' =>
'dp',
'a.percent' =>
'percent');
16614 $sanitized_sortfield_new_list = array();
16615 foreach ($sortfield_list as $sortfield_value) {
16616 $sanitized_sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
16618 $sanitized_sortfield_new = implode(
',', $sanitized_sortfield_new_list);
16625 if (is_object($objcon) && $objcon->id > 0) {
16626 $sql =
"SELECT DISTINCT a.id, a.label as label,";
16628 $sql =
"SELECT a.id, a.label as label,";
16630 $sql .=
" a.datep as dp,";
16631 $sql .=
" a.note as message,";
16632 $sql .=
" a.datep2 as dp2,";
16633 $sql .=
" a.percent as percent, 'action' as type,";
16634 $sql .=
" a.fk_element, a.elementtype,";
16635 $sql .=
" a.fk_contact, a.fulldayevent,";
16636 $sql .=
" a.email_from as msg_from,";
16637 $sql .=
" c.code as acode, c.libelle as alabel, c.picto as apicto,";
16638 $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";
16639 if (is_object($filterobj) && get_class($filterobj) ==
'Societe') {
16640 $sql .=
", sp.lastname, sp.firstname";
16641 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
16642 $sql .=
", m.lastname, m.firstname";
16643 } elseif (is_object($filterobj) && in_array(get_class($filterobj), array(
'Commande',
'CommandeFournisseur',
'Product',
'Ticket',
'BOM',
'Contrat',
'Facture',
'FactureFournisseur',
'Propal',
'Expedition'))) {
16646 if (is_object($filterobj) && !empty($filterobj->table_element) && !empty($filterobj->element) && !empty($filterobj->id) && array_key_exists(
'ref', $filterobj->fields)) {
16650 $sql .=
" FROM " . MAIN_DB_PREFIX .
"actioncomm as a";
16651 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"user as u on u.rowid = a.fk_user_action";
16652 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_actioncomm as c ON a.fk_action = c.id";
16654 $force_filter_contact = $filterobj instanceof
User;
16656 if (is_object($objcon) && $objcon->id > 0) {
16657 $force_filter_contact =
true;
16658 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"actioncomm_resources as r ON a.id = r.fk_actioncomm";
16659 $sql .=
" AND r.element_type = '" .
$db->escape($objcon->table_element) .
"' AND r.fk_element = " . ((int) $objcon->id);
16662 if ((is_object($filterobj) && get_class($filterobj) ==
'Societe') || (is_object($filterobj) && get_class($filterobj) ==
'Contact')) {
16663 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"socpeople as sp ON a.fk_contact = sp.rowid";
16664 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Dolresource') {
16665 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"element_resources as er";
16666 $sql .=
" ON er.resource_type = 'dolresource'";
16667 $sql .=
" AND er.element_id = a.id";
16668 $sql .=
" AND er.resource_id = " . ((int) $filterobj->id);
16669 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
16670 $sql .=
", " . MAIN_DB_PREFIX .
"adherent as m";
16671 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
16672 $sql .=
", " . MAIN_DB_PREFIX .
"commande_fournisseur as o";
16673 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
16674 $sql .=
", " . MAIN_DB_PREFIX .
"product as o";
16675 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
16676 $sql .=
", " . MAIN_DB_PREFIX .
"ticket as o";
16677 } elseif (is_object($filterobj) && get_class($filterobj) ==
'BOM') {
16678 $sql .=
", " . MAIN_DB_PREFIX .
"bom_bom as o";
16679 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contrat') {
16680 $sql .=
", " . MAIN_DB_PREFIX .
"contrat as o";
16681 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Facture') {
16682 $sql .=
", " . MAIN_DB_PREFIX .
"facture as o";
16683 } elseif (is_object($filterobj) && get_class($filterobj) ==
'FactureFournisseur') {
16684 $sql .=
", " . MAIN_DB_PREFIX .
"facture_fourn as o";
16685 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Commande') {
16686 $sql .=
", " . MAIN_DB_PREFIX .
"commande as o";
16687 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Expedition') {
16688 $sql .=
", " . MAIN_DB_PREFIX .
"expedition as o";
16689 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Propal') {
16690 $sql .=
", " . MAIN_DB_PREFIX .
"propal as o";
16692 if (is_object($filterobj) && !empty($filterobj->table_element) && !empty($filterobj->element) && !empty($filterobj->id) && array_key_exists(
'ref', $filterobj->fields)) {
16693 $sql .=
", " . MAIN_DB_PREFIX . $filterobj->table_element .
" as o";
16696 $sql .=
" WHERE a.entity IN (" .
getEntity(
'agenda') .
")";
16697 if (!$force_filter_contact) {
16698 if (is_object($filterobj) && in_array(get_class($filterobj), array(
'Societe',
'Client',
'Fournisseur')) && $filterobj->id) {
16699 $sql .=
" AND a.fk_soc = " . ((int) $filterobj->id);
16700 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Project' && $filterobj->id) {
16701 $sql .=
" AND a.fk_project = o.rowid AND a.fk_project = " . ((int) $filterobj->id);
16702 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
16703 $sql .=
" AND a.fk_element = m.rowid AND a.elementtype = 'member'";
16704 if ($filterobj->id) {
16705 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16707 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Commande') {
16708 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'order'";
16709 if ($filterobj->id) {
16710 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16712 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Expedition') {
16713 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'shipping'";
16714 if ($filterobj->id) {
16715 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16717 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Propal') {
16718 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'propal'";
16719 if ($filterobj->id) {
16720 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16722 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
16723 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
16724 if ($filterobj->id) {
16725 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16727 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
16728 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'product'";
16729 if ($filterobj->id) {
16730 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16732 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
16733 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
16734 if ($filterobj->id) {
16735 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16737 } elseif (is_object($filterobj) && get_class($filterobj) ==
'BOM') {
16738 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
16739 if ($filterobj->id) {
16740 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16742 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contrat') {
16743 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
16744 if ($filterobj->id) {
16745 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16747 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contact' && $filterobj->id) {
16748 $sql .=
" AND a.fk_contact = sp.rowid";
16749 if ($filterobj->id) {
16750 $sql .=
" AND a.fk_contact = " . ((int) $filterobj->id);
16752 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Facture') {
16753 $sql .=
" AND a.fk_element = o.rowid";
16754 if ($filterobj->id) {
16755 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id) .
" AND a.elementtype = 'invoice'";
16757 } elseif (is_object($filterobj) && get_class($filterobj) ==
'FactureFournisseur') {
16758 $sql .=
" AND a.fk_element = o.rowid";
16759 if ($filterobj->id) {
16760 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id) .
" AND a.elementtype = 'invoice_supplier'";
16763 if (is_object($filterobj) && !empty($filterobj->element) && !empty($filterobj->id) && array_key_exists(
'ref', $filterobj->fields)) {
16764 $sql .=
" AND a.fk_element = o.rowid";
16765 $sql .=
" AND a.elementtype = '" .
$db->escape($filterobj->element) .
"'";
16766 if ($filterobj->id) {
16767 $sql .=
" AND a.fk_element = " . ((int) $filterobj->id);
16772 $sql .=
" AND u.rowid = " . ((int) $filterobj->id);
16776 if (!empty($actioncode) && $actioncode !=
'-1') {
16778 if ($actioncode ==
'AC_NON_AUTO') {
16779 $sql .=
" AND c.type != 'systemauto'";
16780 } elseif ($actioncode ==
'AC_ALL_AUTO') {
16781 $sql .=
" AND c.type = 'systemauto'";
16783 if ($actioncode ==
'AC_OTH') {
16784 $sql .=
" AND c.type != 'systemauto'";
16785 } elseif ($actioncode ==
'AC_OTH_AUTO') {
16786 $sql .=
" AND c.type = 'systemauto'";
16790 if ($actioncode ==
'AC_NON_AUTO') {
16791 $sql .=
" AND c.type != 'systemauto'";
16792 } elseif ($actioncode ==
'AC_ALL_AUTO') {
16793 $sql .=
" AND c.type = 'systemauto'";
16795 $sql .=
" AND c.code = '" .
$db->escape($actioncode) .
"'";
16799 if ($donetodo ==
'todo') {
16800 $sql .=
" AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '" .
$db->idate($now) .
"'))";
16801 } elseif ($donetodo ==
'done') {
16802 $sql .=
" AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '" .
$db->idate($now) .
"'))";
16804 if (is_array($filters) && $filters[
'search_agenda_label']) {
16805 $sql .=
natural_search(
'a.label', $filters[
'search_agenda_label']);
16812 && (empty($actioncode) || $actioncode ==
'AC_OTH_AUTO' || $actioncode ==
'AC_EMAILING')
16814 $langs->load(
"mails");
16816 $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";
16817 $sql2 .=
", null as fk_element, '' as elementtype, null as contact_id";
16818 $sql2 .=
", 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
16819 $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";
16820 if (is_object($filterobj) && get_class($filterobj) ==
'Societe') {
16821 $sql2 .=
", '' as lastname, '' as firstname";
16822 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
16823 $sql2 .=
", '' as lastname, '' as firstname";
16824 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
16825 $sql2 .=
", '' as ref";
16826 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
16827 $sql2 .=
", '' as ref";
16828 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
16829 $sql2 .=
", '' as ref";
16831 $sql2 .=
" FROM " . MAIN_DB_PREFIX .
"mailing as m, " . MAIN_DB_PREFIX .
"mailing_cibles as mc, " . MAIN_DB_PREFIX .
"user as u";
16832 $sql2 .=
" WHERE mc.email = '" .
$db->escape($objcon->email) .
"'";
16833 $sql2 .=
" AND mc.statut = 1";
16834 $sql2 .=
" AND u.rowid = m.fk_user_valid";
16835 $sql2 .=
" AND mc.fk_mailing=m.rowid";
16839 $MAXWITHOUTPAGINATION =
getDolGlobalInt(
'AGENDA_MAX_EVENTS_ON_PAGE_WITHOUT_PAGINATION', 100);
16841 if ($sql || $sql2) {
16842 if (!empty($sql) && !empty($sql2)) {
16843 $sql = $sql .
" UNION " . $sql2;
16844 } elseif (empty($sql) && !empty($sql2)) {
16850 $limit = $MAXWITHOUTPAGINATION;
16853 $sql .=
$db->order($sanitized_sortfield_new, $sortorder);
16855 $sql .=
$db->plimit($limit + 1, $offset);
16858 dol_syslog(
"function.lib::show_actions_messaging", LOG_DEBUG);
16860 $resql =
$db->query($sql);
16863 $num =
$db->num_rows($resql);
16865 $imaxinloop = ($limit ? min($num, $limit) : $num);
16866 while ($i < $imaxinloop) {
16867 $obj =
$db->fetch_object($resql);
16869 if ($obj->type ==
'action') {
16871 $contactaction->id = $obj->id;
16872 $result = $contactaction->fetchResources();
16875 setEventMessage(
"actions.lib::show_actions_messaging Error fetch resource",
'errors');
16881 if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && $obj->dp > $now)) {
16882 $tododone =
'todo';
16885 $histo[$numaction] = array(
16886 'type' => $obj->type,
16887 'tododone' => $tododone,
16889 'datestart' =>
$db->jdate($obj->dp),
16890 'dateend' =>
$db->jdate($obj->dp2),
16891 'fulldayevent' => (
int) $obj->fulldayevent,
16892 'note' => $obj->label,
16893 'message' => $obj->message,
16894 'percent' => $obj->percent,
16896 'userid' => $obj->user_id,
16897 'login' => $obj->user_login,
16898 'userfirstname' => $obj->user_firstname,
16899 'userlastname' => $obj->user_lastname,
16900 'userphoto' => $obj->user_photo,
16901 'msg_from' => $obj->msg_from,
16903 'contact_id' => $obj->fk_contact,
16904 'socpeopleassigned' => $contactaction->socpeopleassigned,
16905 'lastname' => (empty($obj->lastname) ?
'' : $obj->lastname),
16906 'firstname' => (empty($obj->firstname) ?
'' : $obj->firstname),
16907 'fk_element' => $obj->fk_element,
16908 'elementtype' => $obj->elementtype,
16910 'acode' => $obj->acode,
16911 'alabel' => $obj->alabel,
16912 'libelle' => $obj->alabel,
16913 'apicto' => $obj->apicto
16916 $histo[$numaction] = array(
16917 'type' => $obj->type,
16918 'tododone' =>
'done',
16920 'datestart' =>
$db->jdate($obj->dp),
16921 'dateend' =>
$db->jdate($obj->dp2),
16922 'fulldayevent' => (
int) $obj->fulldayevent,
16923 'note' => $obj->label,
16924 'message' => $obj->message,
16925 'percent' => $obj->percent,
16926 'acode' => $obj->acode,
16928 'userid' => $obj->user_id,
16929 'login' => $obj->user_login,
16930 'userfirstname' => $obj->user_firstname,
16931 'userlastname' => $obj->user_lastname,
16932 'userphoto' => $obj->user_photo
16948 $langs->loadLangs(array(
"admin",
"errors"));
16949 $out =
info_admin($langs->trans(
"WarningModuleXDisabledSoYouMayMissEventHere", $langs->transnoentitiesnoconv(
"Module2400Name")), 0, 0,
'warning');
16953 $delay_warning =
getDolGlobalInt(
'MAIN_DELAY_ACTIONS_TODO') * 24 * 60 * 60;
16955 require_once DOL_DOCUMENT_ROOT .
'/comm/action/class/actioncomm.class.php';
16956 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
16957 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formactions.class.php';
16958 require_once DOL_DOCUMENT_ROOT .
'/contact/class/contact.class.php';
16965 $userGetNomUrlCache = array();
16966 $contactGetNomUrlCache = array();
16968 $out .=
'<div class="filters-container" >';
16969 $out .=
'<form name="listactionsfilter" class="listactionsfilter" action="' . $_SERVER[
"PHP_SELF"] .
'" method="POST">';
16970 $out .=
'<input type="hidden" name="token" value="' .
newToken() .
'">';
16973 $objcon && get_class($objcon) ==
'Contact' &&
16974 (is_null($filterobj) || get_class($filterobj) ==
'Societe')
16976 $out .=
'<input type="hidden" name="id" value="' . $objcon->id .
'" />';
16978 $out .=
'<input type="hidden" name="id" value="' . $filterobj->id .
'" />';
16980 if (($filterobj && get_class($filterobj) ==
'Societe')) {
16981 $out .=
'<input type="hidden" name="socid" value="' . $filterobj->id .
'" />';
16983 $out .=
'<input type="hidden" name="userid" value="' . $filterobj->id .
'" />';
16988 $out .=
'<div class="div-table-responsive-no-min">';
16989 $out .=
'<table class="noborder borderbottom centpercent">';
16991 $out .=
'<tr class="liste_titre">';
16994 if (
$conf->main_checkbox_left_column) {
16995 $out .=
'<th class="liste_titre width50 middle">';
16996 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
16997 $out .= $searchpicto;
17002 $out .=
getTitleFieldOfList(
'Date', 0, $_SERVER[
"PHP_SELF"],
'a.datep',
'', $param,
'', $sortfield, $sortorder,
'nowraponall nopaddingleftimp ') .
"\n";
17004 $out .=
'<th class="liste_titre hideonsmartphone"><strong class="hideonsmartphone">' . $langs->trans(
"Search") .
' : </strong></th>';
17006 $out .=
'<th class="liste_titre"></th>';
17009 $out .=
'<th class="liste_titre">';
17010 $out .=
'<span class="fas fa-square inline-block fawidth30 hideonsmartphone" style="color: #ddd;" title="' . $langs->trans(
"ActionType") .
'"></span>';
17011 $out .= $formactions->select_type_actions($actioncode,
"actioncode",
'',
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE') ? -1 : 1, 0, 0, 1,
'selecttype minwidth100', $langs->trans(
"Type"));
17014 $out .=
'<th class="liste_titre maxwidth100onsmartphone">';
17015 $out .=
'<input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="' . $filters[
'search_agenda_label'] .
'" placeholder="' . $langs->trans(
"Label") .
'">';
17019 if (!
$conf->main_checkbox_left_column) {
17020 $out .=
'<th class="liste_titre width50 middle">';
17021 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
17022 $out .= $searchpicto;
17028 $out .=
'</table>';
17035 $out .=
'<ul class="timeline">';
17039 if ($filterobj instanceof
Societe) {
17040 $tmp .=
'<a href="' . DOL_URL_ROOT .
'/comm/action/list.php?mode=show_list&socid=' . $filterobj->id .
'&status=done">';
17042 if ($filterobj instanceof
User) {
17043 $tmp .=
'<a href="' . DOL_URL_ROOT .
'/comm/action/list.php?mode=show_list&socid=' . $filterobj->id .
'&status=done">';
17045 $tmp .= ($donetodo !=
'done' ? $langs->trans(
"ActionsToDoShort") :
'');
17046 $tmp .= ($donetodo !=
'done' && $donetodo !=
'todo' ?
' / ' :
'');
17047 $tmp .= ($donetodo !=
'todo' ? $langs->trans(
"ActionsDoneShort") :
'');
17049 if ($filterobj instanceof
Societe) {
17052 if ($filterobj instanceof
User) {
17058 require_once DOL_DOCUMENT_ROOT .
'/comm/action/class/cactioncomm.class.php';
17060 $arraylist = $caction->liste_array(1,
'code',
'', (!
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE') ? 1 : 0),
'', 1);
17062 $actualCycleDate =
false;
17065 foreach ($histo as $key => $value) {
17066 $actionstatic->fetch($histo[$key][
'id']);
17068 $actionstatic->type_picto = $histo[$key][
'apicto'];
17069 $actionstatic->type_code = $histo[$key][
'acode'];
17071 $labeltype = $actionstatic->type_code;
17072 if (!
getDolGlobalString(
'AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labeltype])) {
17073 $labeltype =
'AC_OTH';
17075 if (!empty($actionstatic->code) && preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
17076 $labeltype = $langs->trans(
"Message");
17078 if (!empty($arraylist[$labeltype])) {
17079 $labeltype = $arraylist[$labeltype];
17081 if ($actionstatic->type_code ==
'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) {
17082 $labeltype .=
' - ' . $arraylist[$actionstatic->code];
17086 $url = DOL_URL_ROOT .
'/comm/action/card.php?id=' . $histo[$key][
'id'];
17088 $tmpa =
dol_getdate($histo[$key][
'datestart'],
false);
17090 if (isset($tmpa[
'year']) && isset($tmpa[
'yday']) && $actualCycleDate !== $tmpa[
'year'] .
'-' . $tmpa[
'yday']) {
17091 $actualCycleDate = $tmpa[
'year'] .
'-' . $tmpa[
'yday'];
17092 $out .=
'<!-- timeline time label -->';
17093 $out .=
'<li class="time-label">';
17094 $out .=
'<span class="timeline-badge-date">';
17095 $out .=
dol_print_date($histo[$key][
'datestart'],
'daytext',
'tzuserrel', $langs);
17098 $out .=
'<!-- /.timeline-label -->';
17102 $out .=
'<!-- timeline item -->' .
"\n";
17103 $out .=
'<li class="timeline-code-' . (!empty($actionstatic->code) ? strtolower($actionstatic->code) :
"none") .
'">';
17106 $typeicon = $actionstatic->getTypePicto(
'pictofixedwidth timeline-icon-not-applicble', $labeltype);
17111 $out .=
'<div class="timeline-item">' .
"\n";
17113 $out .=
'<span class="time timeline-header-action2">';
17115 if (isset($histo[$key][
'type']) && $histo[$key][
'type'] ==
'mailing') {
17116 $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") .
' ';
17117 $out .= $histo[$key][
'id'];
17120 $out .= $actionstatic->getNomUrl(1, -1,
'valignmiddle') .
' ';
17124 $user->hasRight(
'agenda',
'allactions',
'create') ||
17125 (($actionstatic->authorid == $user->id || $actionstatic->userownerid == $user->id) && $user->hasRight(
'agenda',
'myactions',
'create'))
17127 $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) .
'">';
17129 $out .=
img_picto($langs->trans(
"Modify"),
'edit',
'class="edita"');
17136 $out .=
'<span class="time"><i class="fa fa-clock valignmiddle"></i> ';
17137 $out .=
'<span class="valignmiddle marginrightonly">';
17138 $out .=
dol_print_date($histo[$key][
'datestart'],
'day',
'tzuserrel');
17141 $out .=
' '.dol_print_date($histo[$key][
'datestart'],
'hour',
'tzuserrel',
null,
false,
'opacitymedium');
17143 if ($histo[$key][
'dateend'] && $histo[$key][
'dateend'] != $histo[$key][
'datestart']) {
17144 $tmpa =
dol_getdate($histo[$key][
'datestart'],
true);
17145 $tmpb =
dol_getdate($histo[$key][
'dateend'],
true);
17146 if ($tmpa[
'mday'] == $tmpb[
'mday'] && $tmpa[
'mon'] == $tmpb[
'mon'] && $tmpa[
'year'] == $tmpb[
'year']) {
17147 $out .=
' - ' .
dol_print_date($histo[$key][
'dateend'],
'hour',
'tzuserrel',
null,
false, 1);
17149 $out .=
' - ' .
dol_print_date($histo[$key][
'dateend'],
'day',
'tzuserrel');
17151 $out .=
' '.dol_print_date($histo[$key][
'dateend'],
'hour',
'tzuserrel',
null,
false,
'opacitymedium');
17156 if ($histo[$key][
'percent'] == 0 && $histo[$key][
'datestart'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
17159 if ($histo[$key][
'percent'] == 0 && !$histo[$key][
'datestart'] && $histo[$key][
'dateend'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
17162 if ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100 && $histo[$key][
'dateend'] && $histo[$key][
'dateend'] < ($now - $delay_warning)) {
17165 if ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100 && !$histo[$key][
'dateend'] && $histo[$key][
'datestart'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
17169 $out .=
img_warning($langs->trans(
"Late")) .
' ';
17171 $out .=
"</span></span>\n";
17173 $out .=
'<span class="time">';
17174 $out .= $actionstatic->getLibStatut(2);
17178 $out .=
'<h3 class="timeline-header">';
17181 $out .=
'<div class="messaging-author inline-block tdoverflowmax150 valignmiddle marginrightonly">';
17182 if ($histo[$key][
'userid'] > 0) {
17183 if (!isset($userGetNomUrlCache[$histo[$key][
'userid']])) {
17184 $userstatic->fetch($histo[$key][
'userid']);
17185 $userGetNomUrlCache[$histo[$key][
'userid']] = $userstatic->getNomUrl(-1,
'', 0, 0, 16, 0,
'firstelselast',
'');
17187 $out .= $userGetNomUrlCache[$histo[$key][
'userid']];
17188 } elseif (!empty($histo[$key][
'msg_from']) && $actionstatic->code ==
'TICKET_MSG') {
17189 if (!isset($contactGetNomUrlCache[$histo[$key][
'msg_from']])) {
17190 if ($contactstatic->fetch(0,
null,
'', $histo[$key][
'msg_from']) > 0) {
17191 $contactGetNomUrlCache[$histo[$key][
'msg_from']] = $contactstatic->getNomUrl(-1,
'', 16);
17193 $contactGetNomUrlCache[$histo[$key][
'msg_from']] = $histo[$key][
'msg_from'];
17196 $out .= $contactGetNomUrlCache[$histo[$key][
'msg_from']];
17198 $out .=
'<img class="photomemberphoto userphoto" alt="" src="/public/theme/common/user_anonymous.png">'.$langs->trans(
"Anonymous");
17203 $out .=
' <div class="messaging-title inline-block">';
17205 if (empty(
$conf->dol_optimize_smallscreen) && $actionstatic->type_code !=
'AC_OTH_AUTO') {
17206 $out .= $labeltype .
' - ';
17211 if (!empty($actionstatic->code) && preg_match(
'/^TICKET_MSG_PRIVATE/', $actionstatic->code)) {
17212 $out .= $langs->trans(
'TicketNewMessage').
' - <em>'.
img_picto($langs->trans(
'Private'),
'lock',
'class="valignmiddle"').
' '.$langs->trans(
'Private').
'</em>';
17213 $summary = preg_replace(
'/\[[^\]]*\]\s*/',
'', $actionstatic->label);
17215 $out .=
' - '.dolPrintHTML($summary);
17217 } elseif (!empty($actionstatic->code) && preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
17218 $out .= $langs->trans(
'TicketNewMessage');
17219 } elseif (isset($histo[$key][
'type'])) {
17220 if ($histo[$key][
'type'] ==
'action') {
17221 $transcode = $langs->transnoentitiesnoconv(
"Action" . $histo[$key][
'acode']);
17222 $libelle = ($transcode !=
"Action" . $histo[$key][
'acode'] ? $transcode : $histo[$key][
'alabel']);
17223 $libelle = $histo[$key][
'note'];
17224 $actionstatic->id = $histo[$key][
'id'];
17225 if ($libelle != $labeltype) {
17228 } elseif ($histo[$key][
'type'] ==
'mailing') {
17229 $out .=
'<a href="' . DOL_URL_ROOT .
'/comm/mailing/card.php?id=' . $histo[$key][
'id'] .
'">' .
img_object($langs->trans(
"ShowEMailing"),
"email") .
' ';
17230 $transcode = $langs->transnoentitiesnoconv(
"Action" . $histo[$key][
'acode']);
17231 $libelle = ($transcode !=
"Action" . $histo[$key][
'acode'] ? $transcode :
'Send mass mailing');
17234 $libelle .= $histo[$key][
'note'];
17238 $out = preg_replace(
'/ - $/',
'', $out);
17240 if (isset($histo[$key][
'elementtype']) && !empty($histo[$key][
'fk_element'])) {
17241 if (isset(
$conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']]) && isset(
$conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']][$histo[$key][
'fk_element']])) {
17242 $link =
$conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']][$histo[$key][
'fk_element']];
17244 if (!isset(
$conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']])) {
17245 $conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']] = array();
17247 $link =
dolGetElementUrl($histo[$key][
'fk_element'], $histo[$key][
'elementtype'], 1);
17248 $conf->cache[
'elementlinkcache'][$histo[$key][
'elementtype']][$histo[$key][
'fk_element']] = $link;
17253 if (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
17254 if ($histo[$key][
'elementtype'] ==
'ticket') {
17259 if ($link && $showlink) {
17260 $out .=
' - ' . $link;
17269 if ($actionstatic->code ==
'AC_TICKET_CREATE') {
17270 $newmess = $filterobj->message;
17272 $newmess = $histo[$key][
'message'];
17275 !empty($newmess && $newmess != $libelle)
17276 && $actionstatic->code !=
'AC_TICKET_MODIFY'
17278 $out .=
'<div class="timeline-body wordbreak small">';
17279 $truncateLines =
getDolGlobalInt(
'MAIN_TRUNCATE_TIMELINE_MESSAGE', 3);
17285 if ($truncateLines > 0 && strlen($newmess) > strlen($truncatedText)) {
17286 $out .=
'<div class="readmore-block --closed" >';
17287 $out .=
' <div class="readmore-block__excerpt">';
17288 $out .=
dolPrintHTML($truncatedText, 0, array(
'pre',
'code'));
17289 $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>';
17291 $out .=
' <div class="readmore-block__full-text" >';
17293 $out .=
dolPrintHTML($newmess, 0, array(
'pre',
'code'));
17295 $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>';
17299 $out .=
dolPrintHTML($newmess, 0, array(
'pre',
'code'));
17308 if (isset($histo[$key][
'socpeopleassigned']) && is_array($histo[$key][
'socpeopleassigned']) && count($histo[$key][
'socpeopleassigned']) > 0) {
17310 foreach ($histo[$key][
'socpeopleassigned'] as $cid => $Tab) {
17311 if (empty(
$conf->cache[
'contact'][$cid])) {
17313 $contact->fetch($cid);
17314 $conf->cache[
'contact'][$cid] = $contact;
17316 $contact =
$conf->cache[
'contact'][$cid];
17320 $contactList .= !empty($contactList) ?
', ' :
'';
17321 $contactList .= $contact->getNomUrl(1);
17322 if (isset($histo[$key][
'acode']) && $histo[$key][
'acode'] ==
'AC_TEL') {
17323 if (!empty($contact->phone_pro)) {
17330 $footer .= $langs->trans(
'ActionOnContact') .
' : ' . $contactList;
17331 } elseif (empty($objcon->id) && isset($histo[$key][
'contact_id']) && $histo[$key][
'contact_id'] > 0) {
17332 if (empty(
$conf->cache[
'contact'][$histo[$key][
'contact_id']])) {
17334 $result = $contact->fetch($histo[$key][
'contact_id']);
17335 $conf->cache[
'contact'][$histo[$key][
'contact_id']] = $contact;
17337 $contact =
$conf->cache[
'contact'][$histo[$key][
'contact_id']];
17338 $result = ($contact instanceof
Contact) ? $contact->id : 0;
17342 $footer .= $contact->getNomUrl(1);
17343 if (isset($histo[$key][
'acode']) && $histo[$key][
'acode'] ==
'AC_TEL') {
17344 if (!empty($contact->phone_pro)) {
17352 if (!empty($documents)) {
17353 $footer .=
'<div class="timeline-documents-container">';
17354 foreach ($documents as $doc) {
17355 $footer .=
'<span id="document_' . $doc->id .
'" class="timeline-documents" ';
17356 $footer .=
' data-id="' . $doc->id .
'" ';
17357 $footer .=
' data-path="' . $doc->filepath .
'"';
17361 $filePath = DOL_DATA_ROOT .
'/' . $doc->filepath .
'/' . $doc->filename;
17363 if (empty($doc->agenda_id)) {
17364 $dir_ref = $actionstatic->id;
17365 $modulepart =
'actions';
17367 $split_dir = explode(
'/', $doc->filepath);
17368 $modulepart = array_shift($split_dir);
17369 $dir_ref = implode(
'/', $split_dir);
17372 $file = $dir_ref .
'/' . $doc->filename;
17373 $thumb = $dir_ref .
'/thumbs/' . substr($doc->filename, 0, strrpos($doc->filename,
'.')) .
'_mini' . substr($doc->filename, strrpos($doc->filename,
'.'));
17374 $doclink =
dol_buildpath(
'document.php', 1) .
'?modulepart=' . $modulepart .
'&attachment=0&file=' . urlencode($file) .
'&entity=' .
$conf->entity;
17375 $viewlink =
dol_buildpath(
'viewimage.php', 1) .
'?modulepart=' . $modulepart .
'&file=' . urlencode($thumb) .
'&entity=' .
$conf->entity;
17379 $mimeAttr =
' mime="' . $mime .
'" ';
17381 if (in_array($mime, array(
'image/png',
'image/jpeg',
'application/pdf'))) {
17382 $class .=
' documentpreview';
17385 $footer .=
'<a href="' . $doclink .
'" class="btn-link ' . $class .
'" target="_blank" rel="noopener noreferrer" ' . $mimeAttr .
' >';
17386 $footer .=
img_mime($filePath) .
' ' . $doc->filename;
17389 $footer .=
'</span>';
17391 $footer .=
'</div>';
17394 if (!empty($footer)) {
17395 $out .=
'<div class="timeline-footer">' . $footer .
'</div>';
17398 $out .=
'</div>' .
"\n";
17401 $out .=
'<!-- END timeline item -->';
17408 jQuery(document).ready(function () {
17409 $(document).on("click", "[data-read-more-action]", function(e){
17410 console.log("We click on data-read-more-action");
17411 let readMoreBloc = $(this).closest(".readmore-block");
17412 if(readMoreBloc.length > 0){
17413 e.preventDefault();
17414 if($(this).attr("data-read-more-action") == "close"){
17415 readMoreBloc.addClass("--closed").removeClass("--open");
17416 $("html, body").animate({
17417 scrollTop: readMoreBloc.offset().top - 200
17420 readMoreBloc.addClass("--open").removeClass("--closed");
17428 if (empty($histo)) {
17429 $out .=
'<span class="opacitymedium">' . $langs->trans(
"NoRecordFound") .
'</span>';
17432 if ($num > $MAXWITHOUTPAGINATION) {
17433 $langs->load(
"errors");
17434 $out .=
'<center><span class="opacitymedium">...' . $langs->trans(
"WarningTooManyDataPleaseUseMoreFilters", $MAXWITHOUTPAGINATION) .
'...</span></center>';
17457function buildParamDate($prefix, $timestamp =
null, $hourTime =
'', $gm =
'auto')
17459 if ($timestamp ===
null) {
17460 $timestamp =
GETPOSTDATE($prefix, $hourTime, $gm);
17467 if ($hourTime ===
'getpost' || ($timestamp !==
null &&
dol_print_date($timestamp,
'%H:%M:%S') !==
'00:00:00')) {
17468 $TParam = array_merge($TParam, array(
17475 return '&' . http_build_query($TParam);
17496function recordNotFound($message =
'', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params =
null)
17498 global
$conf,
$db, $langs, $hookmanager;
17501 if (!is_object($langs)) {
17502 include_once DOL_DOCUMENT_ROOT .
'/core/class/translate.class.php';
17504 $langs->setDefaultLang();
17507 $langs->load(
"errors");
17509 if ($printheader) {
17510 if (function_exists(
"llxHeader")) {
17512 } elseif (function_exists(
"llxHeaderVierge")) {
17517 print
'<div class="error">';
17518 if (empty($message)) {
17519 print $langs->trans(
"ErrorRecordNotFound");
17521 print $langs->trans($message);
17526 if (empty($showonlymessage)) {
17527 if (empty($hookmanager)) {
17528 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
17531 $hookmanager->initHooks(array(
'main'));
17534 $parameters = array(
'message' => $message,
'params' => $params);
17535 $reshook = $hookmanager->executeHooks(
'getErrorRecordNotFound', $parameters,
$object, $action);
17536 print $hookmanager->resPrint;
17539 if ($printfooter && function_exists(
"llxFooter")) {
17541 if (is_object(
$db)) {
17582 foreach ($array2 as $key => $value) {
17583 if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
17586 $merged[$key] = $value;
17601 if (!empty($obj->socid)) {
17602 return (
int) $obj->socid;
17603 } elseif (!empty($obj->soc_id)) {
17604 return (
int) $obj->soc_id;
17605 } elseif (!empty($obj->societe_id)) {
17606 return (
int) $obj->societe_id;
17619 if (!empty($_SESSION[
'dol_screenheight']) && $_SESSION[
'dol_screenheight'] < 700) {
17621 } elseif (!empty($_SESSION[
'dol_screenheight']) && $_SESSION[
'dol_screenheight'] < 950) {
17623 } 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.
dolSort($arraytosort)
Sort an array using a user defined function.
verifCond($strToEvaluate, $onlysimplestring='1')
Verify if condition in string is ok or not.
getDolGlobalLoginBadCharUnauthorized()
Return the list of unauthorized characters in user logins.
recordNotFound($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Displays an error page when a record is not found.
getDolGlobalFloat($key, $default=0)
Return a Dolibarr global constant float value.
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formatted size.
isOnlyOneLocalTax($local)
Return true if LocalTax (1 or 2) is unique.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_print_email($email, $contactid=0, $socid=0, $addlink=0, $max=0, $showinvalid=2, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
get_default_localtax($thirdparty_seller, $thirdparty_buyer, $local, $idprod=0)
Function that return localtax of a product line (according to seller, buyer and product vat rate) If ...
img_weather($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $morecss='')
Show weather picto.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
dolCheckFilters($sqlfilters, &$error='', &$parenthesislevel=0)
Return if a $sqlfilters parameter has a valid balance of parenthesis.
show_actions_messaging($conf, $langs, $db, $filterobj, $objcon=null, $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep, a.id', $sortorder='DESC')
Show html area with actions in messaging format.
dol_getmypid()
Return getmypid() or random PID when function is disabled Some web hosts disable this php function fo...
getLanguageCodeFromCountryCode($countrycode)
Return default language from country code.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
setEntity($currentobject)
Set entity id to use when to create an object.
dolForgeExplodeAnd($sqlfilters)
Explode an universal search string with AND parts.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
img_credit_card($brand, $morecss='fa-2x inline-block valignmiddle')
Return image of a credit card according to its brand name.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
dol_print_ip($ip, $mode=0, $showname=0)
Return an IP formatted to be shown on screen.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
dol_ucfirst($string, $encoding="UTF-8")
Convert first character of the first word of a string to upper.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_right($titlealt='default', $selected=0, $moreatt='')
Show right arrow logo.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
dol_strtolower($string, $encoding="UTF-8")
Convert a string to lower.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
dol_htmlentitiesbr_decode($stringtodecode, $pagecodeto='UTF-8')
This function is called to decode a HTML string (it decodes entities and br tags)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_left($titlealt='default', $selected=0, $moreatt='')
Show left arrow logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
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.
getObjectSocId($obj)
Get the socid of an object, supporting legacy attribute names.
getListLimitFromScreenHeight()
Get the limit of list to show according to the screen height.
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.
jsonOrUnserialize($stringtodecode, $assoc=true)
Decode an encoded string.
dol_print_socialnetworks($value, $contactid, $socid, $type, $dictsocialnetworks=array())
Show social network link.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tab header of a card.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
get_localtax_by_third($local)
Get values of localtaxes (1 or 2) for company country for the common vat with the highest value.
dol_escape_php($stringtoescape, $stringforquotes=2)
Returns text escaped for inclusion into a php string, build with double quotes " or '.
dolSetCookie(string $cookiename, string $cookievalue, int $expire=-1)
Set a cookie.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
img_view($titlealt='default', $float=0, $other='class="valignmiddle"')
Show logo view card.
dol_get_object_properties($obj, $properties=[])
Get value of properties for an object - including magic properties when requested.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_strftime($fmt, $ts=false, $is_gmt=false)
Format a string.
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...
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_clone_in_array($srcobject, $startlevel=0)
Create a clone of instance of object into a full array, using recursive call.
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
getMultidirVersion($object, $module='', $forobject=0)
Return the full path of the directory where a module (or an object of a module) stores its versioned ...
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
dol_sanitizeUrl($stringtoclean, $type=1)
Clean a string to use it as an URL (into a href or src attribute)
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.
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)
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolForgeSQLCriteriaCallback($matches)
Function to forge a SQL criteria from a USF (Universal Filter Syntax) string.
dol_shutdown()
Function called at end of web php process.
dol_print_address($address, $htmlid, $element, $id, $noprint=0, $charfornl='')
Format address string.
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.
showSimpleHTMLTable($outputlangs, $object)
Returns simple order table template as string.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_string_nounprintableascii($str, $removetabcrlf=1)
Clean a string from all non printable ASCII chars (0x00-0x1F and 0x7F).
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
img_error($titlealt='default')
Show error logo.
getTimelineIcon($actionstatic, &$histo, $key)
Get timeline icon.
dol_htmloutput_mesg($mesgstring='', $mesgarray=array(), $style='ok', $keepembedded=0)
Print formatted messages to output (Used to show messages on html output).
dolCloseUnclosedHtmlTags($text)
Close the HTML tags left open in a truncated HTML string.
get_product_localtax_for_country($idprod, $local, $thirdpartytouseforcountry)
Return localtax vat rate of a product in a particular country or default country vat if product is un...
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
buildParamDate($prefix, $timestamp=null, $hourTime='', $gm='auto')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_next($titlealt='default', $moreatt='')
Show next logo.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
dol_string_is_good_iso($s, $clean=0)
Check if a string is a correct iso string If not, it will not be considered as HTML encoded even if i...
getNonce()
Return a random string to be used as a nonce value for js.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isStringVarMatching($var, $regextext, $matchrule=1)
Check if a variable with name $var start with $regextext.
dolSlugify($stringtoslugify)
Returns text slugified (lowercase and no special char, separator is "-").
dol_concat($text1, $text2)
Concat 2 strings.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
get_htmloutput_mesg($mesgstring='', $mesgarray=[], $style='ok', $keepembedded=0)
Get formatted messages to output (Used to show messages on html output).
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $selectlimitsuffix='', $beforearrows='', $hidenavigation=0)
Function to show navigation arrows into lists.
dol_nboflines($s, $maxchar=0)
Return nb of lines of a clear text.
dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox=0, $check='restricthtml')
Sanitize a HTML to remove js, dangerous content and external links.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
dol_escape_xml($stringtoescape)
Returns text escaped for inclusion into a XML string.
getActionCommEcmList($object)
getActionCommEcmList
dol_ucwords($string, $encoding="UTF-8")
Convert first character of all the words of a string to upper.
img_edit_add($titlealt='default', $other='')
Show logo "+".
print_fiche_titre($title, $mesg='', $picto='generic', $pictoisfullpath=0, $id='')
Show a title with picto.
dolForgeDummyCriteriaCallback($matches)
Function to forge a SQL criteria from a Dolibarr filter syntax string.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0, $allowphp=0)
Clean a string to keep only desirable HTML tags.
dol_escape_json($stringtoescape)
Returns text escaped for inclusion into javascript code.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
dol_validElement($element)
Return if var element is ok.
dol_sanitizeKeyCode($str)
Clean a string to use it as a key or code.
isModEnabled($module)
Is Dolibarr module enabled.
array_merge_recursive_distinct(array $array1, array $array2)
Recursively merges two arrays while preserving keys and replacing existing values.
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).
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
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.