46include_once DOL_DOCUMENT_ROOT.
'/core/lib/json.lib.php';
49if (!function_exists(
'utf8_encode')) {
56 function utf8_encode($elements)
58 return mb_convert_encoding($elements,
'UTF-8',
'ISO-8859-1');
62if (!function_exists(
'utf8_decode')) {
69 function utf8_decode($elements)
71 return mb_convert_encoding($elements,
'ISO-8859-1',
'UTF-8');
74if (!function_exists(
'str_starts_with')) {
82 function str_starts_with($haystack, $needle)
84 return (
string) $needle !==
'' && strncmp($haystack, $needle, strlen($needle)) === 0;
87if (!function_exists(
'str_ends_with')) {
95 function str_ends_with($haystack, $needle)
97 return $needle !==
'' && substr($haystack, -strlen($needle)) === (string) $needle;
100if (!function_exists(
'str_contains')) {
108 function str_contains($haystack, $needle)
110 return $needle !==
'' && mb_strpos($haystack, $needle) !==
false;
126 if (!is_object($object) && empty($module)) {
129 if (empty($module) && !empty($object->element)) {
130 $module = $object->element;
132 return $conf->$module->multidir_output[(!empty($object->entity) ? $object->entity : $conf->entity)];
146 return (
string) (isset($conf->global->$key) ? $conf->global->$key : $default);
160 return (
int) (isset($conf->global->$key) ? $conf->global->$key : $default);
173 if (empty($tmpuser)) {
179 return (
string) (empty($tmpuser->conf->$key) ? $default : $tmpuser->conf->$key);
192 if (empty($tmpuser)) {
198 return (
int) (empty($tmpuser->conf->$key) ? $default : $tmpuser->conf->$key);
207function isModEnabled($module)
214 'category' =>
'categorie',
215 'contract' =>
'contrat',
216 'project' =>
'projet',
217 'delivery_note' =>
'expedition'
219 if (empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) {
220 $arrayconv[
'supplier_order'] =
'fournisseur';
221 $arrayconv[
'supplier_invoice'] =
'fournisseur';
223 if (!empty($arrayconv[$module])) {
224 $module = $arrayconv[$module];
227 return !empty($conf->modules[$module]);
244 require_once DOL_DOCUMENT_ROOT.
"/core/db/".$type.
'.class.php';
246 $class =
'DoliDB'.ucfirst($type);
247 $dolidb =
new $class($type, $host, $user, $pass, $name, $port);
268function getEntity($element, $shared = 1, $currentobject =
null)
270 global $conf, $mc, $hookmanager, $object, $action, $db;
272 if (!is_object($hookmanager)) {
273 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
280 $element =
'project';
283 $element =
'contract';
285 case 'order_supplier':
286 $element =
'supplier_order';
288 case 'invoice_supplier':
289 $element =
'supplier_invoice';
293 if (is_object($mc)) {
294 $out = $mc->getEntity($element, $shared, $currentobject);
297 $addzero = array(
'user',
'usergroup',
'cronjob',
'c_email_templates',
'email_template',
'default_values',
'overwrite_trans');
298 if (in_array($element, $addzero)) {
301 $out .= ((int) $conf->entity);
306 'element' => $element,
309 'currentobject' => $currentobject,
312 $reshook = $hookmanager->executeHooks(
'hookGetEntity', $parameters, $currentobject, $action);
314 if (is_numeric($reshook)) {
315 if ($reshook == 0 && !empty($hookmanager->resPrint)) {
316 $out .=
','.$hookmanager->resPrint;
317 } elseif ($reshook == 1) {
318 $out = $hookmanager->resPrint;
335 if (is_object($mc) && method_exists($mc,
'setEntity')) {
336 return $mc->setEntity($currentobject);
338 return ((is_object($currentobject) && $currentobject->id > 0 && $currentobject->entity > 0) ? $currentobject->entity : $conf->entity);
350 return preg_match(
'/(_pass|password|_pw|_key|securekey|serverkey|secret\d?|p12key|exportkey|_PW_[a-z]+|token)$/i', $keyname);
362 for ($r =
""; $n >= 0; $n = intval($n / 26) - 1)
363 $r = chr($n % 26 + 0x41) . $r;
386 include_once DOL_DOCUMENT_ROOT.
'/includes/mobiledetect/mobiledetectlib/Mobile_Detect.php';
393 $user_agent = substr($user_agent, 0, 512);
395 $detectmobile =
new Mobile_Detect(
null, $user_agent);
396 $tablet = $detectmobile->isTablet();
398 if ($detectmobile->isMobile()) {
402 if ($detectmobile->is(
'AndroidOS')) {
403 $os = $phone =
'android';
404 } elseif ($detectmobile->is(
'BlackBerryOS')) {
405 $os = $phone =
'blackberry';
406 } elseif ($detectmobile->is(
'iOS')) {
409 } elseif ($detectmobile->is(
'PalmOS')) {
410 $os = $phone =
'palm';
411 } elseif ($detectmobile->is(
'SymbianOS')) {
413 } elseif ($detectmobile->is(
'webOS')) {
415 } elseif ($detectmobile->is(
'MaemoOS')) {
417 } elseif ($detectmobile->is(
'WindowsMobileOS') || $detectmobile->is(
'WindowsPhoneOS')) {
423 if (preg_match(
'/linux/i', $user_agent)) {
425 } elseif (preg_match(
'/macintosh/i', $user_agent)) {
427 } elseif (preg_match(
'/windows/i', $user_agent)) {
433 if (preg_match(
'/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
435 $version = empty($reg[2]) ?
'' : $reg[2];
436 } elseif (preg_match(
'/edge(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
438 $version = empty($reg[2]) ?
'' : $reg[2];
439 } elseif (preg_match(
'/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg)) {
441 $version = empty($reg[2]) ?
'' : $reg[2];
442 } elseif (preg_match(
'/chrome/i', $user_agent, $reg)) {
445 } elseif (preg_match(
'/iceweasel/i', $user_agent)) {
447 } elseif (preg_match(
'/epiphany/i', $user_agent)) {
449 } elseif (preg_match(
'/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
451 $version = empty($reg[2]) ?
'' : $reg[2];
452 } elseif (preg_match(
'/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
455 $version = empty($reg[2]) ?
'' : $reg[2];
456 } elseif (preg_match(
'/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
458 $version = end($reg);
459 } elseif (preg_match(
'/(Windows NT\s([0-9]+\.[0-9])).*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
462 $version = end($reg);
463 } elseif (preg_match(
'/l[iy]n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) {
466 $version = empty($reg[3]) ?
'' : $reg[3];
478 'browsername' => $name,
479 'browserversion' => $version,
481 'browserua' => $user_agent,
495 global $user, $langs, $db;
496 $disconnectdone =
false;
498 if (is_object($db) && !empty($db->connected)) {
499 $depth = $db->transaction_opened;
500 $disconnectdone = $db->close();
502 dol_syslog(
"--- End access to ".$_SERVER[
"PHP_SELF"].(($disconnectdone && $depth) ?
' (Warn: db disconnection forced, transaction depth was '.$depth.
')' :
''), (($disconnectdone && $depth) ? LOG_WARNING : LOG_INFO));
514function GETPOSTISSET($paramname)
518 $relativepathstring = $_SERVER[
"PHP_SELF"];
520 if (constant(
'DOL_URL_ROOT')) {
521 $relativepathstring = preg_replace(
'/^'.preg_quote(constant(
'DOL_URL_ROOT'),
'/').
'/',
'', $relativepathstring);
523 $relativepathstring = preg_replace(
'/^\//',
'', $relativepathstring);
524 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
530 if (!empty($_GET[
'restore_lastsearch_values'])) {
531 if (!empty($_SESSION[
'lastsearch_values_'.$relativepathstring])) {
532 $tmp = json_decode($_SESSION[
'lastsearch_values_'.$relativepathstring],
true);
533 if (is_array($tmp)) {
534 foreach ($tmp as $key => $val) {
535 if ($key == $paramname) {
543 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_'.$relativepathstring])) {
545 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_'.$relativepathstring])) {
547 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_'.$relativepathstring])) {
549 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_'.$relativepathstring])) {
553 $isset = (isset($_POST[$paramname]) || isset($_GET[$paramname]));
570 if (empty($method)) {
571 $val = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
572 } elseif ($method == 1) {
573 $val = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
574 } elseif ($method == 2) {
575 $val = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
576 } elseif ($method == 3) {
577 $val = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
579 $val =
'BadFirstParameterForGETPOST';
582 return is_array($val);
614function GETPOST($paramname, $check =
'alphanohtml', $method = 0, $filter =
null, $options =
null, $noreplace = 0)
616 global $mysoc, $user, $conf;
618 if (empty($paramname)) {
619 return 'BadFirstParameterForGETPOST';
622 dol_syslog(
"Deprecated use of GETPOST, called with 1st param = ".$paramname.
" and 2nd param is '', when calling page ".$_SERVER[
"PHP_SELF"], LOG_WARNING);
627 if (empty($method)) {
628 $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
629 } elseif ($method == 1) {
630 $out = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
631 } elseif ($method == 2) {
632 $out = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
633 } elseif ($method == 3) {
634 $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
636 return 'BadThirdParameterForGETPOST';
639 if (empty($method) || $method == 3 || $method == 4) {
640 $relativepathstring = $_SERVER[
"PHP_SELF"];
642 if (constant(
'DOL_URL_ROOT')) {
643 $relativepathstring = preg_replace(
'/^'.preg_quote(constant(
'DOL_URL_ROOT'),
'/').
'/',
'', $relativepathstring);
645 $relativepathstring = preg_replace(
'/^\//',
'', $relativepathstring);
646 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
652 if (!empty($_GET[
'restore_lastsearch_values'])) {
653 if (!empty($_SESSION[
'lastsearch_values_'.$relativepathstring])) {
654 $tmp = json_decode($_SESSION[
'lastsearch_values_'.$relativepathstring],
true);
655 if (is_array($tmp)) {
656 foreach ($tmp as $key => $val) {
657 if ($key == $paramname) {
665 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_'.$relativepathstring])) {
666 $out = $_SESSION[
'lastsearch_contextpage_'.$relativepathstring];
667 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_'.$relativepathstring])) {
668 $out = $_SESSION[
'lastsearch_limit_'.$relativepathstring];
669 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_'.$relativepathstring])) {
670 $out = $_SESSION[
'lastsearch_page_'.$relativepathstring];
671 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_'.$relativepathstring])) {
672 $out = $_SESSION[
'lastsearch_mode_'.$relativepathstring];
674 } elseif (!isset($_GET[
'sortfield'])) {
677 if (!empty($_GET[
'action']) && $_GET[
'action'] ==
'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
680 if (is_object($object) && isset($object->fields[$paramname][
'default'])) {
681 $out = $object->fields[$paramname][
'default'];
684 if (!empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) {
685 if (!empty($_GET[
'action']) && (preg_match(
'/^create/', $_GET[
'action']) || preg_match(
'/^presend/', $_GET[
'action'])) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
687 if (!empty($user->default_values)) {
688 if (isset($user->default_values[$relativepathstring][
'createform'])) {
689 foreach ($user->default_values[$relativepathstring][
'createform'] as $defkey => $defval) {
691 if ($defkey !=
'_noquery_') {
692 $tmpqueryarraytohave = explode(
'&', $defkey);
695 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
696 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
709 if (isset($user->default_values[$relativepathstring][
'createform'][$defkey][$paramname])) {
710 $out = $user->default_values[$relativepathstring][
'createform'][$defkey][$paramname];
717 } elseif (!empty($paramname) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
719 if (!empty($user->default_values)) {
722 if ($paramname ==
'sortfield' || $paramname ==
'sortorder') {
724 if (isset($user->default_values[$relativepathstring][
'sortorder'])) {
726 foreach ($user->default_values[$relativepathstring][
'sortorder'] as $defkey => $defval) {
728 if ($defkey !=
'_noquery_') {
729 $tmpqueryarraytohave = explode(
'&', $defkey);
732 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
733 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
746 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
747 foreach ($user->default_values[$relativepathstring][
'sortorder'][$defkey] as $key => $val) {
751 if ($paramname ==
'sortfield') {
754 if ($paramname ==
'sortorder') {
762 } elseif (isset($user->default_values[$relativepathstring][
'filters'])) {
763 foreach ($user->default_values[$relativepathstring][
'filters'] as $defkey => $defval) {
764 if (!empty($_GET[
'disabledefaultvalues'])) {
768 if ($defkey !=
'_noquery_') {
769 $tmpqueryarraytohave = explode(
'&', $defkey);
772 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
773 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
785 if ($qualified && isset($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname])) {
787 if (isset($_POST[
'sall']) || isset($_POST[
'search_all']) || isset($_GET[
'sall']) || isset($_GET[
'search_all'])) {
789 if (empty($conf->global->MAIN_DISABLE_DEFAULT_FILTER_FOR_QUICK_SEARCH)) {
790 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
791 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
794 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
795 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
810 if (!is_array($out) && empty($_POST[$paramname]) && empty($noreplace)) {
814 while (preg_match(
'/__([A-Z0-9]+_?[A-Z0-9]+)__/i', $out, $reg) && ($loopnb < $maxloop)) {
818 if ($reg[1] ==
'DAY') {
820 $newout = $tmp[
'mday'];
821 } elseif ($reg[1] ==
'MONTH') {
823 $newout = $tmp[
'mon'];
824 } elseif ($reg[1] ==
'YEAR') {
826 $newout = $tmp[
'year'];
827 } elseif ($reg[1] ==
'PREVIOUS_DAY') {
830 $newout = $tmp2[
'day'];
831 } elseif ($reg[1] ==
'PREVIOUS_MONTH') {
834 $newout = $tmp2[
'month'];
835 } elseif ($reg[1] ==
'PREVIOUS_YEAR') {
837 $newout = ($tmp[
'year'] - 1);
838 } elseif ($reg[1] ==
'NEXT_DAY') {
841 $newout = $tmp2[
'day'];
842 } elseif ($reg[1] ==
'NEXT_MONTH') {
845 $newout = $tmp2[
'month'];
846 } elseif ($reg[1] ==
'NEXT_YEAR') {
848 $newout = ($tmp[
'year'] + 1);
849 } elseif ($reg[1] ==
'MYCOMPANY_COUNTRY_ID' || $reg[1] ==
'MYCOUNTRY_ID' || $reg[1] ==
'MYCOUNTRYID') {
850 $newout = $mysoc->country_id;
851 } elseif ($reg[1] ==
'USER_ID' || $reg[1] ==
'USERID') {
853 } elseif ($reg[1] ==
'USER_SUPERVISOR_ID' || $reg[1] ==
'SUPERVISOR_ID' || $reg[1] ==
'SUPERVISORID') {
854 $newout = $user->fk_user;
855 } elseif ($reg[1] ==
'ENTITY_ID' || $reg[1] ==
'ENTITYID') {
856 $newout = $conf->entity;
861 $out = preg_replace(
'/__'.preg_quote($reg[1],
'/').
'__/', $newout, $out);
866 if (preg_match(
'/^array/', $check)) {
867 if (!is_array($out) || empty($out)) {
870 $tmparray = explode(
':', $check);
871 if (!empty($tmparray[1])) {
872 $tmpcheck = $tmparray[1];
874 $tmpcheck =
'alphanohtml';
876 foreach ($out as $outkey => $outval) {
877 $out[$outkey] =
sanitizeVal($outval, $tmpcheck, $filter, $options);
883 if (strpos($paramname,
'search_') === 0) {
884 $out = preg_replace(
'/([<>])([-+]?\d)/',
'\1 \2', $out);
887 $out =
sanitizeVal($out, $check, $filter, $options);
892 if ($paramname ==
'backtopage' || $paramname ==
'backtolist' || $paramname ==
'backtourl') {
893 $out = str_replace(
'\\',
'/', $out);
894 $out = str_replace(array(
':',
';',
'@',
"\t",
' '),
'', $out);
896 $oldstringtoclean = $out;
897 $out = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $out);
898 $out = preg_replace(array(
'/^[^\?]*%/'),
'', $out);
899 $out = preg_replace(array(
'/^[a-z]*\/\s*\/+/i'),
'', $out);
900 }
while ($oldstringtoclean != $out);
905 if (empty($method) || $method == 3 || $method == 4) {
906 if (preg_match(
'/^search_/', $paramname) || in_array($paramname, array(
'sortorder',
'sortfield'))) {
913 if ($out !=
'' && isset($user)) {
914 $user->lastsearch_values_tmp[$relativepathstring][$paramname] = $out;
933 return (
int)
GETPOST($paramname,
'int', $method,
null,
null, 0);
947function checkVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
949 return sanitizeVal($out, $check, $filter, $options);
961function sanitizeVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
969 if (!is_numeric($out)) {
974 if (is_array($out)) {
975 $out = implode(
',', $out);
977 if (preg_match(
'/[^0-9,-]+/i', $out)) {
982 $out = filter_var($out, FILTER_SANITIZE_STRING);
985 $out = filter_var($out, FILTER_SANITIZE_EMAIL);
988 if (!is_array($out)) {
990 if (preg_match(
'/[^a-z]+/i', $out)) {
996 if (!is_array($out)) {
998 if (preg_match(
'/[^a-z0-9_\-\.]+/i', $out)) {
1004 if (!is_array($out)) {
1006 if (preg_match(
'/[^a-z0-9_\-\.@]+/i', $out)) {
1012 if (!is_array($out)) {
1014 if (preg_match(
'/[^a-z0-9_\-\.,]+/i', $out)) {
1021 if (!is_array($out)) {
1024 $oldstringtoclean = $out;
1031 $out = str_ireplace(array(
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'\',
'\',
'/',
'../',
'..\\'),
'', $out);
1032 }
while ($oldstringtoclean != $out);
1036 case 'alphawithlgt':
1037 if (!is_array($out)) {
1040 $oldstringtoclean = $out;
1046 $out = str_ireplace(array(
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'\',
'\',
'/',
'../',
'..\\'),
'', $out);
1047 }
while ($oldstringtoclean != $out);
1053 case 'restricthtmlnolink':
1054 case 'restricthtml':
1055 case 'restricthtmlallowclass':
1056 case 'restricthtmlallowunvalid':
1061 if (empty($filter)) {
1062 return 'BadParameterForGETPOST - Param 3 of sanitizeVal()';
1067 $out = filter_var($out, $filter, $options);
1076if (!function_exists(
'dol_getprefix')) {
1086 function dol_getprefix($mode =
'')
1089 if ($mode ==
'email') {
1092 if (!empty($conf->global->MAIL_PREFIX_FOR_EMAIL_ID)) {
1093 if ($conf->global->MAIL_PREFIX_FOR_EMAIL_ID !=
'SERVER_NAME') {
1094 return $conf->global->MAIL_PREFIX_FOR_EMAIL_ID;
1095 } elseif (isset($_SERVER[
"SERVER_NAME"])) {
1096 return $_SERVER[
"SERVER_NAME"];
1101 if (!empty($conf->file->instance_unique_id)) {
1102 return sha1(
'dolibarr'.$conf->file->instance_unique_id);
1106 return sha1(DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1110 global $dolibarr_main_instance_unique_id, $dolibarr_main_cookie_cryptkey;
1111 $tmp_instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ?
'' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id;
1114 if (!empty($tmp_instance_unique_id)) {
1115 return sha1(
'dolibarr'.$tmp_instance_unique_id);
1119 if (isset($_SERVER[
"SERVER_NAME"]) && isset($_SERVER[
"DOCUMENT_ROOT"])) {
1120 return sha1($_SERVER[
"SERVER_NAME"].$_SERVER[
"DOCUMENT_ROOT"].DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1122 return sha1(DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1139 global $conf, $langs, $user, $mysoc;
1143 if (!file_exists($fullpath)) {
1144 dol_syslog(
'functions::dol_include_once Tried to load unexisting file: '.$relpath, LOG_WARNING);
1148 if (!empty($classname) && !class_exists($classname)) {
1149 return include $fullpath;
1151 return include_once $fullpath;
1170 $path = preg_replace(
'/^\//',
'', $path);
1173 $res = DOL_DOCUMENT_ROOT.
'/'.$path;
1174 if (is_array($conf->file->dol_document_root)) {
1175 foreach ($conf->file->dol_document_root as $key => $dirroot) {
1176 if ($key ==
'main') {
1180 if (@file_exists($dirroot.
'/'.$path)) {
1181 $res = $dirroot.
'/'.$path;
1186 if ($returnemptyifnotfound) {
1188 if ($returnemptyifnotfound == 1 || !file_exists($res)) {
1200 $res = DOL_URL_ROOT.
'/'.$path;
1203 $res = DOL_MAIN_URL_ROOT.
'/'.$path;
1206 $res = DOL_URL_ROOT.
'/'.$path;
1209 foreach ($conf->file->dol_document_root as $key => $dirroot) {
1210 if ($key ==
'main') {
1212 global $dolibarr_main_url_root;
1215 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1216 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1219 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : $urlwithroot).
'/'.$path;
1224 preg_match(
'/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i', $path, $regs);
1225 if (!empty($regs[1])) {
1228 if (@file_exists($dirroot.
'/'.$regs[1])) {
1230 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : DOL_URL_ROOT).$conf->file->dol_url_root[$key].
'/'.$path;
1233 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : DOL_MAIN_URL_ROOT).$conf->file->dol_url_root[$key].
'/'.$path;
1236 global $dolibarr_main_url_root;
1239 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1240 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1243 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : $urlwithroot).$conf->file->dol_url_root[$key].
'/'.$path;
1270 if (isset($object->db) && isset($object->db->db) && is_object($object->db->db) && get_class($object->db->db) ==
'PgSql\Connection') {
1271 $tmpsavdb = $object->db;
1275 $myclone = unserialize(serialize($object));
1277 if (!empty($tmpsavdb)) {
1278 $object->db = $tmpsavdb;
1280 } elseif ($native == 2) {
1282 $myclone =
new stdClass();
1283 $tmparray = get_object_vars($object);
1285 if (is_array($tmparray)) {
1286 foreach ($tmparray as $propertykey => $propertyval) {
1287 if (is_scalar($propertyval) || is_array($propertyval)) {
1288 $myclone->$propertykey = $propertyval;
1293 $myclone = clone $object;
1311 if (empty($conf->dol_optimize_smallscreen)) {
1314 if ($type ==
'width' && $size > 250) {
1339 $filesystem_forbidden_chars = array(
'<',
'>',
'/',
'\\',
'?',
'*',
'|',
'"',
':',
'°',
'$',
';',
'`');
1341 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
1342 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $tmp);
1343 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1344 $tmp = str_replace(
'..',
'', $tmp);
1364 $filesystem_forbidden_chars = array(
'<',
'>',
'?',
'*',
'|',
'"',
'°',
'$',
';',
'`');
1366 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
1367 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $tmp);
1368 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1369 $tmp = str_replace(
'..',
'', $tmp);
1384 $stringtoclean = preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $stringtoclean);
1386 $stringtoclean = preg_replace(
'/<!--[^>]*-->/',
'', $stringtoclean);
1388 $stringtoclean = str_replace(
'\\',
'/', $stringtoclean);
1392 $stringtoclean = str_replace(array(
':',
';',
'@'),
'', $stringtoclean);
1396 $oldstringtoclean = $stringtoclean;
1399 $stringtoclean = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $stringtoclean);
1400 }
while ($oldstringtoclean != $stringtoclean);
1404 $stringtoclean = preg_replace(array(
'/^[a-z]*\/\/+/i'),
'', $stringtoclean);
1407 return $stringtoclean;
1419 $oldstringtoclean = $stringtoclean;
1420 $stringtoclean = str_ireplace(array(
'"',
':',
'[',
']',
"\n",
"\r",
'\\',
'\/'),
'', $stringtoclean);
1421 }
while ($oldstringtoclean != $stringtoclean);
1423 return $stringtoclean;
1438 if (is_null($str)) {
1443 if (extension_loaded(
'intl') && !empty($conf->global->MAIN_UNACCENT_USE_TRANSLITERATOR)) {
1444 $transliterator = Transliterator::createFromRules(
':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', Transliterator::FORWARD);
1445 return $transliterator->transliterate($str);
1448 $string = rawurlencode($str);
1449 $replacements = array(
1450 '%C3%80' =>
'A',
'%C3%81' =>
'A',
'%C3%82' =>
'A',
'%C3%83' =>
'A',
'%C3%84' =>
'A',
'%C3%85' =>
'A',
1452 '%C3%88' =>
'E',
'%C3%89' =>
'E',
'%C3%8A' =>
'E',
'%C3%8B' =>
'E',
1453 '%C3%8C' =>
'I',
'%C3%8D' =>
'I',
'%C3%8E' =>
'I',
'%C3%8F' =>
'I',
1455 '%C3%92' =>
'O',
'%C3%93' =>
'O',
'%C3%94' =>
'O',
'%C3%95' =>
'O',
'%C3%96' =>
'O',
1457 '%C3%99' =>
'U',
'%C3%9A' =>
'U',
'%C3%9B' =>
'U',
'%C3%9C' =>
'U',
1458 '%C3%9D' =>
'Y',
'%C5%B8' =>
'y',
1459 '%C3%A0' =>
'a',
'%C3%A1' =>
'a',
'%C3%A2' =>
'a',
'%C3%A3' =>
'a',
'%C3%A4' =>
'a',
'%C3%A5' =>
'a',
1461 '%C3%A8' =>
'e',
'%C3%A9' =>
'e',
'%C3%AA' =>
'e',
'%C3%AB' =>
'e',
1462 '%C3%AC' =>
'i',
'%C3%AD' =>
'i',
'%C3%AE' =>
'i',
'%C3%AF' =>
'i',
1464 '%C3%B2' =>
'o',
'%C3%B3' =>
'o',
'%C3%B4' =>
'o',
'%C3%B5' =>
'o',
'%C3%B6' =>
'o',
1466 '%C3%B9' =>
'u',
'%C3%BA' =>
'u',
'%C3%BB' =>
'u',
'%C3%BC' =>
'u',
1467 '%C3%BD' =>
'y',
'%C3%BF' =>
'y'
1469 $string = strtr($string, $replacements);
1470 return rawurldecode($string);
1475 "\xC0\xC1\xC2\xC3\xC4\xC5\xC7
1476 \xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1
1477 \xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD
1478 \xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB
1479 \xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8
1480 \xF9\xFA\xFB\xFC\xFD\xFF",
1488 $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"));
1506function dol_string_nospecial($str, $newstr =
'_', $badcharstoreplace =
'', $badcharstoremove =
'', $keepspaces = 0)
1508 $forbidden_chars_to_replace = array(
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
",",
";",
"=",
'°',
'$',
';');
1509 if (empty($keepspaces)) {
1510 $forbidden_chars_to_replace[] =
" ";
1512 $forbidden_chars_to_remove = array();
1515 if (is_array($badcharstoreplace)) {
1516 $forbidden_chars_to_replace = $badcharstoreplace;
1518 if (is_array($badcharstoremove)) {
1519 $forbidden_chars_to_remove = $badcharstoremove;
1522 return str_replace($forbidden_chars_to_replace, $newstr, str_replace($forbidden_chars_to_remove,
"", $str));
1541 if ($removetabcrlf) {
1542 return preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $str);
1544 return preg_replace(
'/[\x00-\x08\x11-\x12\x14-\x1F\x7F]/u',
'', $str);
1558 if (is_null($stringtoescape)) {
1563 $substitjs = array(
"'"=>
"\\'",
"\r"=>
'\\r');
1565 if (empty($noescapebackslashn)) {
1566 $substitjs[
"\n"] =
'\\n';
1567 $substitjs[
'\\'] =
'\\\\';
1570 $substitjs[
"'"] =
"\\'";
1571 $substitjs[
'"'] =
"\\'";
1572 } elseif ($mode == 1) {
1573 $substitjs[
"'"] =
"\\'";
1574 } elseif ($mode == 2) {
1575 $substitjs[
'"'] =
'\\"';
1576 } elseif ($mode == 3) {
1577 $substitjs[
"'"] =
"\\'";
1578 $substitjs[
'"'] =
"\\\"";
1580 return strtr($stringtoescape, $substitjs);
1591 return str_replace(
'"',
'\"', $stringtoescape);
1647function dol_escape_htmltag($stringtoescape, $keepb = 0, $keepn = 0, $noescapetags =
'', $escapeonlyhtmltags = 0, $cleanalsojavascript = 0)
1649 if ($noescapetags ==
'common') {
1650 $noescapetags =
'html,body,a,b,em,hr,i,u,ul,li,br,div,img,font,p,span,strong,table,tr,td,th,tbody';
1652 if ($cleanalsojavascript) {
1657 if ($escapeonlyhtmltags) {
1658 $tmp = htmlspecialchars_decode((
string) $stringtoescape, ENT_COMPAT);
1660 $tmp = html_entity_decode((
string) $stringtoescape, ENT_COMPAT,
'UTF-8');
1663 $tmp = strtr($tmp, array(
"<b>"=>
'',
'</b>'=>
'',
'<strong>'=>
'',
'</strong>'=>
''));
1666 $tmp = strtr($tmp, array(
"\r"=>
'\\r',
"\n"=>
'\\n'));
1669 if ($escapeonlyhtmltags) {
1670 return htmlspecialchars($tmp, ENT_COMPAT,
'UTF-8');
1674 $tmparrayoftags = array();
1675 if ($noescapetags) {
1676 $tmparrayoftags = explode(
',', $noescapetags);
1678 if (count($tmparrayoftags)) {
1679 foreach ($tmparrayoftags as $tagtoreplace) {
1680 $tmp = str_ireplace(
'<'.$tagtoreplace.
'>',
'__BEGINTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
1681 $tmp = str_ireplace(
'</'.$tagtoreplace.
'>',
'__ENDTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
1682 $tmp = str_ireplace(
'<'.$tagtoreplace.
' />',
'__BEGINENDTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
1686 $result = htmlentities($tmp, ENT_COMPAT,
'UTF-8');
1688 if (count($tmparrayoftags)) {
1689 foreach ($tmparrayoftags as $tagtoreplace) {
1690 $result = str_ireplace(
'__BEGINTAGTOREPLACE'.$tagtoreplace.
'__',
'<'.$tagtoreplace.
'>', $result);
1691 $result = str_ireplace(
'__ENDTAGTOREPLACE'.$tagtoreplace.
'__',
'</'.$tagtoreplace.
'>', $result);
1692 $result = str_ireplace(
'__BEGINENDTAGTOREPLACE'.$tagtoreplace.
'__',
'<'.$tagtoreplace.
' />', $result);
1709 if (function_exists(
'mb_strtolower')) {
1710 return mb_strtolower($string, $encoding);
1712 return strtolower($string);
1726 if (function_exists(
'mb_strtoupper')) {
1727 return mb_strtoupper($string, $encoding);
1729 return strtoupper($string);
1743 if (function_exists(
'mb_substr')) {
1744 return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding).mb_substr($string, 1,
null, $encoding);
1746 return ucfirst($string);
1760 if (function_exists(
'mb_convert_case')) {
1761 return mb_convert_case($string, MB_CASE_TITLE, $encoding);
1763 return ucwords($string);
1788function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename =
'', $restricttologhandler =
'', $logcontext =
null)
1790 global $conf, $user, $debugbar;
1793 if (!isModEnabled(
'syslog')) {
1798 if (defined(
'USEEXTERNALSERVER') && !defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
1799 global $website, $websitekey;
1800 if (is_object($website) && !empty($website->ref)) {
1801 $suffixinfilename .=
'_website_'.$website->ref;
1802 } elseif (!empty($websitekey)) {
1803 $suffixinfilename .=
'_website_'.$websitekey;
1808 if (defined(
'USESUFFIXINLOG')) {
1809 $suffixinfilename .= constant(
'USESUFFIXINLOG');
1813 foreach ($conf->loghandlers as $loghandlerinstance) {
1814 $loghandlerinstance->setIdent($ident);
1818 if (!empty($message)) {
1820 $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');
1822 if (!array_key_exists($level, $logLevels)) {
1823 dol_syslog(
'Error Bad Log Level '.$level, LOG_ERR);
1824 $level = $logLevels[LOG_ERR];
1830 if (empty($conf->global->MAIN_SHOW_PASSWORD_INTO_LOG)) {
1831 $message = preg_replace(
'/password=\'[^\']*\'/',
'password=\'hidden\'', $message);
1835 if ((!empty($_REQUEST[
'logtohtml']) && !empty($conf->global->MAIN_ENABLE_LOG_TO_HTML))
1836 || (!empty($user->rights->debugbar->read) && is_object($debugbar))) {
1837 $conf->logbuffer[] =
dol_print_date(time(),
"%Y-%m-%d %H:%M:%S").
" ".$logLevels[$level].
" ".$message;
1842 if (!empty($conf->global->MAIN_ENABLE_LOG_INLINE_HTML) && !empty($_GET[
"log"])) {
1843 print
"\n\n<!-- Log start\n";
1845 print
"Log end -->\n";
1849 'message' => $message,
1850 'script' => (isset($_SERVER[
'PHP_SELF']) ? basename($_SERVER[
'PHP_SELF'],
'.php') :
false),
1852 'user' => ((is_object($user) && $user->id) ? $user->login :
false),
1857 if (!empty($remoteip)) {
1858 $data[
'ip'] = $remoteip;
1860 if (!empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) && $_SERVER[
'HTTP_X_FORWARDED_FOR'] != $remoteip) {
1861 $data[
'ip'] = $_SERVER[
'HTTP_X_FORWARDED_FOR'].
' -> '.$data[
'ip'];
1862 } elseif (!empty($_SERVER[
'HTTP_CLIENT_IP']) && $_SERVER[
'HTTP_CLIENT_IP'] != $remoteip) {
1863 $data[
'ip'] = $_SERVER[
'HTTP_CLIENT_IP'].
' -> '.$data[
'ip'];
1865 } elseif (!empty($_SERVER[
'SERVER_ADDR'])) {
1867 $data[
'ip'] = $_SERVER[
'SERVER_ADDR'];
1868 } elseif (!empty($_SERVER[
'COMPUTERNAME'])) {
1870 $data[
'ip'] = $_SERVER[
'COMPUTERNAME'].(empty($_SERVER[
'USERNAME']) ?
'' :
'@'.$_SERVER[
'USERNAME']);
1871 } elseif (!empty($_SERVER[
'LOGNAME'])) {
1873 $data[
'ip'] =
'???@'.$_SERVER[
'LOGNAME'];
1877 foreach ($conf->loghandlers as $loghandlerinstance) {
1878 if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
1881 $loghandlerinstance->export($data, $suffixinfilename);
1887 foreach ($conf->loghandlers as $loghandlerinstance) {
1888 $loghandlerinstance->setIdent($ident);
1909function dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled =
'', $morecss =
'classlink button bordertransp', $jsonopen =
'', $backtopagejsfields =
'', $accesskey =
'')
1913 if (strpos($url,
'?') > 0) {
1914 $url .=
'&dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup='.urlencode($name);
1916 $url .=
'?dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup='.urlencode($name);
1921 $backtopagejsfieldsid =
''; $backtopagejsfieldslabel =
'';
1922 if ($backtopagejsfields) {
1923 $tmpbacktopagejsfields = explode(
':', $backtopagejsfields);
1924 if (empty($tmpbacktopagejsfields[1])) {
1925 $backtopagejsfields = $name.
":".$backtopagejsfields;
1926 $tmp2backtopagejsfields = explode(
',', $tmpbacktopagejsfields[0]);
1928 $tmp2backtopagejsfields = explode(
',', $tmpbacktopagejsfields[1]);
1930 $backtopagejsfieldsid = empty($tmp2backtopagejsfields[0]) ?
'' : $tmp2backtopagejsfields[0];
1931 $backtopagejsfieldslabel = empty($tmp2backtopagejsfields[1]) ?
'' : $tmp2backtopagejsfields[1];
1932 $url .=
'&backtopagejsfields='.urlencode($backtopagejsfields);
1936 $out .=
'<!-- a link for button to open url into a dialog popup with backtopagejsfields = '.$backtopagejsfields.
' -->';
1937 $out .=
'<a '.($accesskey ?
' accesskey="'.$accesskey.
'"' :
'').
' class="cursorpointer reposition button_'.$name.($morecss ?
' '.$morecss :
'').
'"'.$disabled.
' title="'.
dol_escape_htmltag($label).
'"';
1938 if (empty($conf->use_javascript_ajax)) {
1939 $out .=
' href="'.DOL_URL_ROOT.$url.
'" target="_blank"';
1940 } elseif ($jsonopen) {
1941 $out .=
' href="#" onclick="'.$jsonopen.
'"';
1943 $out .=
' href="#"';
1945 $out .=
'>'.$buttonstring.
'</a>';
1947 if (!empty($conf->use_javascript_ajax)) {
1949 $out .=
'<!-- code to open popup and variables to retreive returned variables -->';
1950 $out .=
'<div id="idfordialog'.$name.
'" class="hidden">div for dialog</div>';
1951 $out .=
'<div id="varforreturndialogid'.$name.
'" class="hidden">div for returned id</div>';
1952 $out .=
'<div id="varforreturndialoglabel'.$name.
'" class="hidden">div for returned label</div>';
1953 $out .=
'<!-- Add js code to open dialog popup on dialog -->';
1954 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">
1955 jQuery(document).ready(function () {
1956 jQuery(".button_'.$name.
'").click(function () {
1957 console.log(\'Open popup with jQuery(...).dialog() on URL '.
dol_escape_js(DOL_URL_ROOT.$url).
'\');
1958 var $tmpdialog = $(\
'#idfordialog'.$name.
'\');
1959 $tmpdialog.html(\
'<iframe class="iframedialog" id="iframedialog'.$name.
'" style="border: 0px;" src="'.DOL_URL_ROOT.$url.
'" width="100%" height="98%"></iframe>\');
1963 height: (window.innerHeight - 150),
1966 open:
function (event, ui) {
1967 console.log(
"open popup name='.$name.', backtopagejsfields='.$backtopagejsfields.'");
1969 close:
function (event, ui) {
1970 var returnedid = jQuery(
"#varforreturndialogid'.$name.'").text();
1971 var returnedlabel = jQuery(
"#varforreturndialoglabel'.$name.'").text();
1972 console.log(
"popup has been closed. returnedid (js var defined into parent page)="+returnedid+
" returnedlabel="+returnedlabel);
1973 if (returnedid !=
"" && returnedid !=
"div for returned id") {
1974 jQuery(
"#'.(empty($backtopagejsfieldsid)?"none
":$backtopagejsfieldsid).'").val(returnedid);
1976 if (returnedlabel !=
"" && returnedlabel !=
"div for returned label") {
1977 jQuery(
"#'.(empty($backtopagejsfieldslabel)?"none
":$backtopagejsfieldslabel).'").val(returnedlabel);
1982 $tmpdialog.dialog(\
'open\');
2007function dol_fiche_head($links = array(), $active =
'0', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'')
2009 print
dol_get_fiche_head($links, $active, $title, $notab, $picto, $pictoisfullpath, $morehtmlright, $morecss, $limittoshow, $moretabssuffix);
2028function dol_get_fiche_head($links = array(), $active =
'', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'', $dragdropfile = 0)
2030 global $conf, $langs, $hookmanager;
2034 if (!empty($conf->dol_optimize_smallscreen)) {
2038 $out =
"\n".
'<!-- dol_fiche_head - dol_get_fiche_head -->';
2040 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
2041 $out .=
'<div class="tabs'.($picto ?
'' :
' nopaddingleft').
'" data-role="controlgroup" data-type="horizontal">'.
"\n";
2045 if ($morehtmlright) {
2046 $out .=
'<div class="inline-block floatright tabsElem">'.$morehtmlright.
'</div>';
2050 if (!empty($title) && $showtitle && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2052 $out .=
'<a class="tabTitle">';
2054 $noprefix = $pictoisfullpath;
2055 if (strpos($picto,
'fontawesome_') !==
false) {
2058 $out .=
img_picto($title, ($noprefix ?
'' :
'object_').$picto,
'', $pictoisfullpath, 0, 0,
'',
'imgTabTitle').
' ';
2060 $out .=
'<span class="tabTitleText">'.dol_escape_htmltag(
dol_trunc($title, $limittitle)).
'</span>';
2068 if (is_array($links) && !empty($links)) {
2069 $keys = array_keys($links);
2071 $maxkey = max($keys);
2077 if (empty($limittoshow)) {
2078 $limittoshow = (empty($conf->global->MAIN_MAXTABS_IN_CARD) ? 99 : $conf->global->MAIN_MAXTABS_IN_CARD);
2080 if (!empty($conf->dol_optimize_smallscreen)) {
2088 for ($i = 0; $i <= $maxkey; $i++) {
2089 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
2091 if ($i >= $limittoshow) {
2097 for ($i = 0; $i <= $maxkey; $i++) {
2098 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
2104 if ($i < $limittoshow || $isactive) {
2106 $out .=
'<div class="inline-block tabsElem'.($isactive ?
' tabsElemActive' :
'').((!$isactive && !empty($conf->global->MAIN_HIDE_INACTIVETAB_ON_PRINT)) ?
' hideonprint' :
'').
'"><!-- id tab = '.(empty($links[$i][2]) ?
'' :
dol_escape_htmltag($links[$i][2])).
' -->';
2108 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
2109 if (!empty($links[$i][0])) {
2110 $out .=
'<a class="tabimage'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">'.$links[$i][1].
'</a>'.
"\n";
2112 $out .=
'<span class="tabspan">'.$links[$i][1].
'</span>'.
"\n";
2114 } elseif (!empty($links[$i][1])) {
2116 $out .=
'<div class="tab tab'.($isactive?
'active':
'unactive').
'" style="margin: 0 !important">';
2117 if (!empty($links[$i][0])) {
2118 $titletoshow = preg_replace(
'/<.*$/',
'', $links[$i][1]);
2119 $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).
'">';
2121 $out .= $links[$i][1];
2122 if (!empty($links[$i][0])) {
2123 $out .=
'</a>'.
"\n";
2125 $out .= empty($links[$i][4]) ?
'' : $links[$i][4];
2134 $outmore .=
'<div class="popuptabset wordwrap">';
2136 $outmore .=
'<div class="popuptab wordwrap" style="display:inherit;">';
2137 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
2138 if (!empty($links[$i][0])) {
2139 $outmore .=
'<a class="tabimage'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">'.$links[$i][1].
'</a>'.
"\n";
2141 $outmore .=
'<span class="tabspan">'.$links[$i][1].
'</span>'.
"\n";
2143 } elseif (!empty($links[$i][1])) {
2144 $outmore .=
'<a'.(!empty($links[$i][2]) ?
' id="'.$links[$i][2].
'"' :
'').
' class="wordwrap inline-block'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">';
2145 $outmore .= preg_replace(
'/([a-z])\|([a-z])/i',
'\\1 | \\2', $links[$i][1]);
2146 $outmore .=
'</a>'.
"\n";
2148 $outmore .=
'</div>';
2155 $outmore .=
'</div>';
2159 $left = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'right' :
'left');
2160 $right = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right');
2161 $widthofpopup = 200;
2163 $tabsname = $moretabssuffix;
2164 if (empty($tabsname)) {
2165 $tabsname = str_replace(
"@",
"", $picto);
2167 $out .=
'<div id="moretabs'.$tabsname.
'" class="inline-block tabsElem valignmiddle">';
2168 $out .=
'<div class="tab"><a href="#" class="tab moretab inline-block tabunactive"><span class="hideonsmartphone">'.$langs->trans(
"More").
'</span>... ('.$nbintab.
')</a></div>';
2169 $out .=
'<div id="moretabsList'.$tabsname.
'" style="width: '.$widthofpopup.
'px; position: absolute; '.$left.
': -999em; text-align: '.$left.
'; margin:0px; padding:2px; z-index:10;">';
2172 $out .=
'<div></div>';
2175 $out .=
'<script nonce="'.getNonce().
'">';
2176 $out .=
"$('#moretabs".$tabsname.
"').mouseenter( function() {
2177 var x = this.offsetLeft, y = this.offsetTop;
2178 console.log('mouseenter ".$left.
" x='+x+' y='+y+' window.innerWidth='+window.innerWidth);
2179 if ((window.innerWidth - x) < ".($widthofpopup + 10).
") {
2180 $('#moretabsList".$tabsname.
"').css('".$right.
"','8px');
2182 $('#moretabsList".$tabsname.
"').css('".$left.
"','auto');
2185 $out .=
"$('#moretabs".$tabsname.
"').mouseleave( function() { console.log('mouseleave ".$left.
"'); $('#moretabsList".$tabsname.
"').css('".$left.
"','-999em');});";
2186 $out .=
"</script>";
2189 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
2193 if (!$notab || $notab == -1 || $notab == -2 || $notab == -3) {
2194 $out .=
"\n".
'<div id="dragDropAreaTabBar" class="tabBar'.($notab == -1 ?
'' : ($notab == -2 ?
' tabBarNoTop' : (($notab == -3 ?
' noborderbottom' :
'').
' tabBarWithBottom'))).
'">'.
"\n";
2196 if (!empty($dragdropfile)) {
2199 $parameters = array(
'tabname' => $active,
'out' => $out);
2200 $reshook = $hookmanager->executeHooks(
'printTabsHead', $parameters);
2202 $out = $hookmanager->resPrint;
2228 if (!$notab || $notab == -1) {
2229 return "\n</div>\n";
2254function dol_banner_tab($object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $onlybanner = 0, $morehtmlright =
'')
2256 global $conf, $form, $user, $langs, $hookmanager, $action;
2260 $maxvisiblephotos = 1;
2262 $entity = (empty($object->entity) ? $conf->entity : $object->entity);
2263 $showbarcode = empty($conf->barcode->enabled) ? 0 : (empty($object->barcode) ? 0 : 1);
2264 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
2267 $modulepart =
'unknown';
2269 if ($object->element ==
'societe' || $object->element ==
'contact' || $object->element ==
'product' || $object->element ==
'ticket') {
2270 $modulepart = $object->element;
2271 } elseif ($object->element ==
'member') {
2272 $modulepart =
'memberphoto';
2273 } elseif ($object->element ==
'user') {
2274 $modulepart =
'userphoto';
2277 if (class_exists(
"Imagick")) {
2278 if ($object->element ==
'expensereport' || $object->element ==
'propal' || $object->element ==
'commande' || $object->element ==
'facture' || $object->element ==
'supplier_proposal') {
2279 $modulepart = $object->element;
2280 } elseif ($object->element ==
'fichinter') {
2281 $modulepart =
'ficheinter';
2282 } elseif ($object->element ==
'contrat') {
2283 $modulepart =
'contract';
2284 } elseif ($object->element ==
'order_supplier') {
2285 $modulepart =
'supplier_order';
2286 } elseif ($object->element ==
'invoice_supplier') {
2287 $modulepart =
'supplier_invoice';
2291 if ($object->element ==
'product') {
2293 $cssclass =
'photowithmargin photoref';
2294 $showimage = $object->is_photo_available($conf->product->multidir_output[$entity]);
2295 $maxvisiblephotos = (isset($conf->global->PRODUCT_MAX_VISIBLE_PHOTO) ? $conf->global->PRODUCT_MAX_VISIBLE_PHOTO : 5);
2296 if ($conf->browser->layout ==
'phone') {
2297 $maxvisiblephotos = 1;
2300 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$object->show_photos(
'product', $conf->product->multidir_output[$entity],
'small', $maxvisiblephotos, 0, 0, 0, 0, $width, 0,
'').
'</div>';
2302 if (!empty($conf->global->PRODUCT_NODISPLAYIFNOPHOTO)) {
2304 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
2306 $nophoto =
'/public/theme/common/nophoto.png';
2307 $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>';
2310 } elseif ($object->element ==
'ticket') {
2312 $cssclass =
'photoref';
2313 $showimage = $object->is_photo_available($conf->ticket->multidir_output[$entity].
'/'.$object->ref);
2314 $maxvisiblephotos = (isset($conf->global->TICKET_MAX_VISIBLE_PHOTO) ? $conf->global->TICKET_MAX_VISIBLE_PHOTO : 2);
2315 if ($conf->browser->layout ==
'phone') {
2316 $maxvisiblephotos = 1;
2320 $showphoto = $object->show_photos(
'ticket', $conf->ticket->multidir_output[$entity],
'small', $maxvisiblephotos, 0, 0, 0, $width, 0);
2321 if ($object->nbphoto > 0) {
2322 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$showphoto.
'</div>';
2328 if (!empty($conf->global->TICKET_NODISPLAYIFNOPHOTO)) {
2330 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
2332 $nophoto =
img_picto(
'No photo',
'object_ticket');
2333 $morehtmlleft .=
'<!-- No photo to show -->';
2334 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
2335 $morehtmlleft .= $nophoto;
2336 $morehtmlleft .=
'</div></div>';
2341 if ($modulepart !=
'unknown') {
2344 if (in_array($modulepart, array(
'propal',
'commande',
'facture',
'ficheinter',
'contract',
'supplier_order',
'supplier_proposal',
'supplier_invoice',
'expensereport')) && class_exists(
"Imagick")) {
2346 $dir_output = (empty($conf->$modulepart->multidir_output[$entity]) ? $conf->$modulepart->dir_output : $conf->$modulepart->multidir_output[$entity]).
"/";
2347 if (in_array($modulepart, array(
'invoice_supplier',
'supplier_invoice'))) {
2348 $subdir =
get_exdir($object->id, 2, 0, 1, $object, $modulepart);
2349 $subdir .= ((!empty($subdir) && !preg_match(
'/\/$/', $subdir)) ?
'/' :
'').$objectref;
2351 $subdir =
get_exdir($object->id, 0, 0, 1, $object, $modulepart);
2353 if (empty($subdir)) {
2354 $subdir =
'errorgettingsubdirofobject';
2357 $filepath = $dir_output.$subdir.
"/";
2359 $filepdf = $filepath.$objectref.
".pdf";
2360 $relativepath = $subdir.
'/'.$objectref.
'.pdf';
2363 $fileimage = $filepdf.
'_preview.png';
2364 $relativepathimage = $relativepath.
'_preview.png';
2366 $pdfexists = file_exists($filepdf);
2371 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
2372 if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) {
2373 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2382 if ($pdfexists && !$error) {
2383 $heightforphotref = 80;
2384 if (!empty($conf->dol_optimize_smallscreen)) {
2385 $heightforphotref = 60;
2388 if (file_exists($fileimage)) {
2389 $phototoshow =
'<div class="photoref">';
2390 $phototoshow .=
'<img height="'.$heightforphotref.
'" class="photo photowithborder" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart=apercu'.$modulepart.
'&file='.urlencode($relativepathimage).
'">';
2391 $phototoshow .=
'</div>';
2394 } elseif (!$phototoshow) {
2395 $phototoshow .= $form->showphoto($modulepart, $object, 0, 0, 0,
'photowithmargin photoref',
'small', 1, 0, $maxvisiblephotos);
2399 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">';
2400 $morehtmlleft .= $phototoshow;
2401 $morehtmlleft .=
'</div>';
2405 if (empty($phototoshow)) {
2406 if ($object->element ==
'action') {
2408 $cssclass =
'photorefcenter';
2409 $nophoto =
img_picto(
'No photo',
'title_agenda');
2412 $cssclass =
'photorefcenter';
2413 $picto = $object->picto;
2414 $prefix =
'object_';
2415 if ($object->element ==
'project' && !$object->public) {
2418 if (strpos($picto,
'fontawesome_') !==
false) {
2421 $nophoto =
img_picto(
'No photo', $prefix.$picto);
2423 $morehtmlleft .=
'<!-- No photo to show -->';
2424 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
2425 $morehtmlleft .= $nophoto;
2426 $morehtmlleft .=
'</div></div>';
2433 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$form->showbarcode($object, 100,
'photoref valignmiddle').
'</div>';
2436 if ($object->element ==
'societe') {
2437 if (!empty($conf->use_javascript_ajax) && $user->hasRight(
'societe',
'creer') && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
2438 $morehtmlstatus .=
ajax_object_onoff($object,
'status',
'status',
'InActivity',
'ActivityCeased');
2440 $morehtmlstatus .= $object->getLibStatut(6);
2442 } elseif ($object->element ==
'product') {
2444 if (!empty($conf->use_javascript_ajax) && $user->hasRight(
'produit',
'creer') && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
2445 $morehtmlstatus .=
ajax_object_onoff($object,
'status',
'tosell',
'ProductStatusOnSell',
'ProductStatusNotOnSell');
2447 $morehtmlstatus .=
'<span class="statusrefsell">'.$object->getLibStatut(6, 0).
'</span>';
2449 $morehtmlstatus .=
' ';
2451 if (!empty($conf->use_javascript_ajax) && $user->hasRight(
'produit',
'creer') && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
2452 $morehtmlstatus .=
ajax_object_onoff($object,
'status_buy',
'tobuy',
'ProductStatusOnBuy',
'ProductStatusNotOnBuy');
2454 $morehtmlstatus .=
'<span class="statusrefbuy">'.$object->getLibStatut(6, 1).
'</span>';
2456 } elseif (in_array($object->element, array(
'facture',
'invoice',
'invoice_supplier'))) {
2457 $totalallpayments = $object->getSommePaiement(0);
2458 $totalallpayments += $object->getSumCreditNotesUsed(0);
2459 $totalallpayments += $object->getSumDepositsUsed(0);
2460 $tmptxt = $object->getLibStatut(6, $totalallpayments);
2461 if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
2462 $tmptxt = $object->getLibStatut(5, $totalallpayments);
2464 $morehtmlstatus .= $tmptxt;
2465 } elseif (in_array($object->element, array(
'chargesociales',
'loan',
'tva'))) {
2466 $tmptxt = $object->getLibStatut(6, $object->totalpaid);
2467 if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
2468 $tmptxt = $object->getLibStatut(5, $object->totalpaid);
2470 $morehtmlstatus .= $tmptxt;
2471 } elseif ($object->element ==
'contrat' || $object->element ==
'contract') {
2472 if ($object->statut == 0) {
2473 $morehtmlstatus .= $object->getLibStatut(5);
2475 $morehtmlstatus .= $object->getLibStatut(4);
2477 } elseif ($object->element ==
'facturerec') {
2478 if ($object->frequency == 0) {
2479 $morehtmlstatus .= $object->getLibStatut(2);
2481 $morehtmlstatus .= $object->getLibStatut(5);
2483 } elseif ($object->element ==
'project_task') {
2484 $object->fk_statut = 1;
2485 if ($object->progress > 0) {
2486 $object->fk_statut = 2;
2488 if ($object->progress >= 100) {
2489 $object->fk_statut = 3;
2491 $tmptxt = $object->getLibStatut(5);
2492 $morehtmlstatus .= $tmptxt;
2493 } elseif (method_exists($object,
'getLibStatut')) {
2494 $tmptxt = $object->getLibStatut(6);
2495 if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
2496 $tmptxt = $object->getLibStatut(5);
2498 $morehtmlstatus .= $tmptxt;
2502 if (isModEnabled(
'accounting') && in_array($object->element, array(
'bank',
'paiementcharge',
'facture',
'invoice',
'invoice_supplier',
'expensereport',
'payment_various'))) {
2504 if (method_exists($object,
'getVentilExportCompta')) {
2505 $accounted = $object->getVentilExportCompta();
2506 $langs->load(
"accountancy");
2507 $morehtmlstatus .=
'</div><div class="statusref statusrefbis"><span class="opacitymedium">'.($accounted > 0 ? $langs->trans(
"Accounted") : $langs->trans(
"NotYetAccounted")).
'</span>';
2512 if (!empty($object->name_alias)) {
2513 $morehtmlref .=
'<div class="refidno opacitymedium">'.dol_escape_htmltag($object->name_alias).
'</div>';
2517 if (in_array($object->element, array(
'product',
'bank_account',
'project_task'))) {
2518 if (!empty($object->label)) {
2519 $morehtmlref .=
'<div class="refidno opacitymedium">'.$object->label.
'</div>';
2524 if (method_exists($object,
'getBannerAddress') && !in_array($object->element, array(
'product',
'bookmark',
'ecm_directories',
'ecm_files'))) {
2525 $moreaddress = $object->getBannerAddress(
'refaddress', $object);
2527 $morehtmlref .=
'<div class="refidno refaddress">';
2528 $morehtmlref .= $moreaddress;
2529 $morehtmlref .=
'</div>';
2532 if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && ($conf->global->MAIN_SHOW_TECHNICAL_ID ==
'1' || preg_match(
'/'.preg_quote($object->element,
'/').
'/i', $conf->global->MAIN_SHOW_TECHNICAL_ID)) && !empty($object->id)) {
2533 $morehtmlref .=
'<div style="clear: both;"></div>';
2534 $morehtmlref .=
'<div class="refidno opacitymedium">';
2535 $morehtmlref .= $langs->trans(
"TechnicalID").
': '.((int) $object->id);
2536 $morehtmlref .=
'</div>';
2539 $parameters=array(
'morehtmlref'=>$morehtmlref);
2540 $reshook = $hookmanager->executeHooks(
'formDolBanner', $parameters, $object, $action);
2543 } elseif (empty($reshook)) {
2544 $morehtmlref .= $hookmanager->resPrint;
2545 } elseif ($reshook > 0) {
2546 $morehtmlref = $hookmanager->resPrint;
2550 print
'<div class="'.($onlybanner ?
'arearefnobottom ' :
'arearef ').
'heightref valignmiddle centpercent">';
2551 print $form->showrefnav($object, $paramid, $morehtml, $shownav, $fieldid, $fieldref, $morehtmlref, $moreparam, $nodbprefix, $morehtmlleft, $morehtmlstatus, $morehtmlright);
2553 print
'<div class="underrefbanner clearboth"></div>';
2569 if ($fieldrequired) {
2570 $ret .=
'<span class="fieldrequired">';
2572 $ret .=
'<label for="'.$fieldkey.
'">';
2573 $ret .= $langs->trans($langkey);
2575 if ($fieldrequired) {
2591 $ret =
' '.$bc[$var];
2593 $ret = preg_replace(
'/class=\"/',
'class="'.$moreclass.
' ', $ret);
2611function dol_format_address($object, $withcountry = 0, $sep =
"\n", $outputlangs =
'', $mode = 0, $extralangcode =
'')
2613 global $conf, $langs, $hookmanager;
2616 $countriesusingstate = array(
'AU',
'CA',
'US',
'IN',
'GB',
'ES',
'UK',
'TR',
'CN');
2621 $ret .= ($extralangcode ? $object->array_languages[
'address'][$extralangcode] : (empty($object->address) ?
'' : preg_replace(
'/(\r\n|\r|\n)+/', $sep, $object->address)));
2624 if (isset($object->country_code) && in_array($object->country_code, array(
'AU',
'CA',
'US',
'CN')) || !empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS)) {
2626 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2627 $ret .= (($ret && $town) ? $sep :
'').$town;
2629 if (!empty($object->state)) {
2630 $ret .= ($ret ? ($town ?
", " : $sep) :
'').$object->state;
2632 if (!empty($object->zip)) {
2633 $ret .= ($ret ? (($town || $object->state) ?
", " : $sep) :
'').$object->zip;
2635 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'GB',
'UK'))) {
2637 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2638 $ret .= ($ret ? $sep :
'').$town;
2639 if (!empty($object->state)) {
2640 $ret .= ($ret ?
", " :
'').$object->state;
2642 if (!empty($object->zip)) {
2643 $ret .= ($ret ? $sep :
'').$object->zip;
2645 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'ES',
'TR'))) {
2647 $ret .= ($ret ? $sep :
'').$object->zip;
2648 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2649 $ret .= ($town ? (($object->zip ?
' ' :
'').$town) :
'');
2650 if (!empty($object->state)) {
2651 $ret .= $sep.$object->state;
2653 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'JP'))) {
2656 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2657 $ret .= ($ret ? $sep :
'').($object->state ? $object->state.
', ' :
'').$town.($object->zip ?
' ' :
'').$object->zip;
2658 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'IT'))) {
2660 $ret .= ($ret ? $sep :
'').$object->zip;
2661 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2662 $ret .= ($town ? (($object->zip ?
' ' :
'').$town) :
'');
2663 $ret .= (empty($object->state_code) ?
'' : (
' '.$object->state_code));
2666 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2667 $ret .= !empty($object->zip) ? (($ret ? $sep :
'').$object->zip) :
'';
2668 $ret .= ($town ? (($object->zip ?
' ' : ($ret ? $sep :
'')).$town) :
'');
2669 if (!empty($object->state) && in_array($object->country_code, $countriesusingstate)) {
2670 $ret .= ($ret ?
", " :
'').$object->state;
2674 if (!is_object($outputlangs)) {
2675 $outputlangs = $langs;
2678 $langs->load(
"dict");
2679 $ret .= (empty($object->country_code) ?
'' : ($ret ? $sep :
'').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv(
"Country".$object->country_code)));
2682 $parameters = array(
'withcountry' => $withcountry,
'sep' => $sep,
'outputlangs' => $outputlangs,
'mode' => $mode,
'extralangcode' => $extralangcode);
2683 $reshook = $hookmanager->executeHooks(
'formatAddress', $parameters, $object);
2687 $ret .= $hookmanager->resPrint;
2705 if ((abs($ts) <= 0x7FFFFFFF)) {
2706 return ($is_gmt) ? @gmstrftime($fmt, $ts) : @strftime($fmt, $ts);
2708 return 'Error date into a not supported range';
2733function dol_print_date($time, $format =
'', $tzoutput =
'auto', $outputlangs =
'', $encodetooutput =
false)
2735 global $conf, $langs;
2742 if ($tzoutput ===
'auto') {
2743 $tzoutput = (empty($conf) ?
'tzserver' : (isset($conf->tzuserinputkey) ? $conf->tzuserinputkey :
'tzserver'));
2748 $offsettz = $offsetdst = 0;
2751 if (is_string($tzoutput)) {
2752 if ($tzoutput ==
'tzserver') {
2754 $offsettzstring = @date_default_timezone_get();
2757 } elseif ($tzoutput ==
'tzuser' || $tzoutput ==
'tzuserrel') {
2759 $offsettzstring = (empty($_SESSION[
'dol_tz_string']) ?
'UTC' : $_SESSION[
'dol_tz_string']);
2761 if (class_exists(
'DateTimeZone')) {
2762 $user_date_tz =
new DateTimeZone($offsettzstring);
2763 $user_dt =
new DateTime();
2764 $user_dt->setTimezone($user_date_tz);
2765 $user_dt->setTimestamp($tzoutput ==
'tzuser' ?
dol_now() : (int) $time);
2766 $offsettz = $user_dt->getOffset();
2768 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
2769 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
2774 if (!is_object($outputlangs)) {
2775 $outputlangs = $langs;
2778 $format =
'daytextshort';
2783 $reduceformat = (!empty($conf->dol_optimize_smallscreen) && in_array($format, array(
'day',
'dayhour'))) ? 1 : 0;
2784 $format = preg_replace(
'/inputnoreduce/',
'', $format);
2785 $formatwithoutreduce = preg_replace(
'/reduceformat/',
'', $format);
2786 if ($formatwithoutreduce != $format) {
2787 $format = $formatwithoutreduce;
2793 if ($format ==
'day') {
2794 $format = ($outputlangs->trans(
"FormatDateShort") !=
"FormatDateShort" ? $outputlangs->trans(
"FormatDateShort") : $conf->format_date_short);
2795 } elseif ($format ==
'hour') {
2796 $format = ($outputlangs->trans(
"FormatHourShort") !=
"FormatHourShort" ? $outputlangs->trans(
"FormatHourShort") : $conf->format_hour_short);
2797 } elseif ($format ==
'hourduration') {
2798 $format = ($outputlangs->trans(
"FormatHourShortDuration") !=
"FormatHourShortDuration" ? $outputlangs->trans(
"FormatHourShortDuration") : $conf->format_hour_short_duration);
2799 } elseif ($format ==
'daytext') {
2800 $format = ($outputlangs->trans(
"FormatDateText") !=
"FormatDateText" ? $outputlangs->trans(
"FormatDateText") : $conf->format_date_text);
2801 } elseif ($format ==
'daytextshort') {
2802 $format = ($outputlangs->trans(
"FormatDateTextShort") !=
"FormatDateTextShort" ? $outputlangs->trans(
"FormatDateTextShort") : $conf->format_date_text_short);
2803 } elseif ($format ==
'dayhour') {
2804 $format = ($outputlangs->trans(
"FormatDateHourShort") !=
"FormatDateHourShort" ? $outputlangs->trans(
"FormatDateHourShort") : $conf->format_date_hour_short);
2805 } elseif ($format ==
'dayhoursec') {
2806 $format = ($outputlangs->trans(
"FormatDateHourSecShort") !=
"FormatDateHourSecShort" ? $outputlangs->trans(
"FormatDateHourSecShort") : $conf->format_date_hour_sec_short);
2807 } elseif ($format ==
'dayhourtext') {
2808 $format = ($outputlangs->trans(
"FormatDateHourText") !=
"FormatDateHourText" ? $outputlangs->trans(
"FormatDateHourText") : $conf->format_date_hour_text);
2809 } elseif ($format ==
'dayhourtextshort') {
2810 $format = ($outputlangs->trans(
"FormatDateHourTextShort") !=
"FormatDateHourTextShort" ? $outputlangs->trans(
"FormatDateHourTextShort") : $conf->format_date_hour_text_short);
2811 } elseif ($format ==
'dayhourlog') {
2813 $format =
'%Y%m%d%H%M%S';
2814 } elseif ($format ==
'dayhourlogsmall') {
2816 $format =
'%y%m%d%H%M';
2817 } elseif ($format ==
'dayhourldap') {
2818 $format =
'%Y%m%d%H%M%SZ';
2819 } elseif ($format ==
'dayhourxcard') {
2820 $format =
'%Y%m%dT%H%M%SZ';
2821 } elseif ($format ==
'dayxcard') {
2823 } elseif ($format ==
'dayrfc') {
2824 $format =
'%Y-%m-%d';
2825 } elseif ($format ==
'dayhourrfc') {
2826 $format =
'%Y-%m-%dT%H:%M:%SZ';
2827 } elseif ($format ==
'standard') {
2828 $format =
'%Y-%m-%d %H:%M:%S';
2831 if ($reduceformat) {
2832 $format = str_replace(
'%Y',
'%y', $format);
2833 $format = str_replace(
'yyyy',
'yy', $format);
2837 if (preg_match(
'/%b/i', $format)) {
2839 $format = str_replace(
'%b',
'__b__', $format);
2840 $format = str_replace(
'%B',
'__B__', $format);
2842 if (preg_match(
'/%a/i', $format)) {
2844 $format = str_replace(
'%a',
'__a__', $format);
2845 $format = str_replace(
'%A',
'__A__', $format);
2850 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', $time, $reg)) {
2851 dol_print_error(
'',
"Functions.lib::dol_print_date function called with a bad value from page ".$_SERVER[
"PHP_SELF"]);
2853 } elseif (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $time, $reg)) {
2855 dol_syslog(
"Functions.lib::dol_print_date function called with a bad value from page ".$_SERVER[
"PHP_SELF"], LOG_WARNING);
2858 $syear = (!empty($reg[1]) ? $reg[1] :
'');
2859 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
2860 $sday = (!empty($reg[3]) ? $reg[3] :
'');
2861 $shour = (!empty($reg[4]) ? $reg[4] :
'');
2862 $smin = (!empty($reg[5]) ? $reg[5] :
'');
2863 $ssec = (!empty($reg[6]) ? $reg[6] :
'');
2865 $time =
dol_mktime($shour, $smin, $ssec, $smonth, $sday, $syear,
true);
2868 $tzo =
new DateTimeZone(
'UTC');
2870 $tzo =
new DateTimeZone(date_default_timezone_get());
2872 $dtts =
new DateTime();
2873 $dtts->setTimestamp($time);
2874 $dtts->setTimezone($tzo);
2875 $newformat = str_replace(
2876 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2877 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2879 $ret = $dtts->format($newformat);
2881 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2882 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2887 if ($time < 100000000000) {
2888 $timetouse = $time + $offsettz + $offsetdst;
2891 $tzo =
new DateTimeZone(
'UTC');
2893 $tzo =
new DateTimeZone(date_default_timezone_get());
2895 $dtts =
new DateTime();
2896 $dtts->setTimestamp($timetouse);
2897 $dtts->setTimezone($tzo);
2898 $newformat = str_replace(
2899 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'%w',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2900 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'w',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2902 $ret = $dtts->format($newformat);
2904 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2905 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2910 $ret =
'Bad value '.$time.
' for date';
2914 if (preg_match(
'/__b__/i', $format)) {
2915 $timetouse = $time + $offsettz + $offsetdst;
2918 $tzo =
new DateTimeZone(
'UTC');
2920 $tzo =
new DateTimeZone(date_default_timezone_get());
2922 $dtts =
new DateTime();
2923 $dtts->setTimestamp($timetouse);
2924 $dtts->setTimezone($tzo);
2925 $month = $dtts->format(
"m");
2926 $month = sprintf(
"%02d", $month);
2927 if ($encodetooutput) {
2928 $monthtext = $outputlangs->transnoentities(
'Month'.$month);
2929 $monthtextshort = $outputlangs->transnoentities(
'MonthShort'.$month);
2931 $monthtext = $outputlangs->transnoentitiesnoconv(
'Month'.$month);
2932 $monthtextshort = $outputlangs->transnoentitiesnoconv(
'MonthShort'.$month);
2935 $ret = str_replace(
'__b__', $monthtextshort, $ret);
2936 $ret = str_replace(
'__B__', $monthtext, $ret);
2940 if (preg_match(
'/__a__/i', $format)) {
2942 $timetouse = $time + $offsettz + $offsetdst;
2945 $tzo =
new DateTimeZone(
'UTC');
2947 $tzo =
new DateTimeZone(date_default_timezone_get());
2949 $dtts =
new DateTime();
2950 $dtts->setTimestamp($timetouse);
2951 $dtts->setTimezone($tzo);
2952 $w = $dtts->format(
"w");
2953 $dayweek = $outputlangs->transnoentitiesnoconv(
'Day'.$w);
2955 $ret = str_replace(
'__A__', $dayweek, $ret);
2956 $ret = str_replace(
'__a__',
dol_substr($dayweek, 0, 3), $ret);
2985 if ($timestamp ===
'') {
2989 $datetimeobj =
new DateTime();
2990 $datetimeobj->setTimestamp($timestamp);
2991 if ($forcetimezone) {
2992 $datetimeobj->setTimezone(
new DateTimeZone($forcetimezone ==
'gmt' ?
'UTC' : $forcetimezone));
2995 'year'=>((
int) date_format($datetimeobj,
'Y')),
2996 'mon'=>((
int) date_format($datetimeobj,
'm')),
2997 'mday'=>((
int) date_format($datetimeobj,
'd')),
2998 'wday'=>((
int) date_format($datetimeobj,
'w')),
2999 'yday'=>((
int) date_format($datetimeobj,
'z')),
3000 'hours'=>((
int) date_format($datetimeobj,
'H')),
3001 'minutes'=>((
int) date_format($datetimeobj,
'i')),
3002 'seconds'=>((
int) date_format($datetimeobj,
's')),
3030function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm =
'auto', $check = 1)
3035 if ($gm ===
'auto') {
3036 $gm = (empty($conf) ?
'tzserver' : $conf->tzuserinputkey);
3041 if ($hour == -1 || empty($hour)) {
3044 if ($minute == -1 || empty($minute)) {
3047 if ($second == -1 || empty($second)) {
3053 if (!$month || !$day) {
3062 if ($hour < 0 || $hour > 24) {
3065 if ($minute < 0 || $minute > 60) {
3068 if ($second < 0 || $second > 60) {
3073 if (empty($gm) || ($gm ===
'server' || $gm ===
'tzserver')) {
3074 $default_timezone = @date_default_timezone_get();
3075 $localtz =
new DateTimeZone($default_timezone);
3076 } elseif ($gm ===
'user' || $gm ===
'tzuser' || $gm ===
'tzuserrel') {
3078 $default_timezone = (empty($_SESSION[
"dol_tz_string"]) ? @date_default_timezone_get() : $_SESSION[
"dol_tz_string"]);
3080 $localtz =
new DateTimeZone($default_timezone);
3082 dol_syslog(
"Warning dol_tz_string contains an invalid value ".$_SESSION[
"dol_tz_string"], LOG_WARNING);
3083 $default_timezone = @date_default_timezone_get();
3085 } elseif (strrpos($gm,
"tz,") !==
false) {
3086 $timezone = str_replace(
"tz,",
"", $gm);
3088 $localtz =
new DateTimeZone($timezone);
3090 dol_syslog(
"Warning passed timezone contains an invalid value ".$timezone, LOG_WARNING);
3094 if (empty($localtz)) {
3095 $localtz =
new DateTimeZone(
'UTC');
3099 $dt =
new DateTime(
'now', $localtz);
3100 $dt->setDate((
int) $year, (
int) $month, (
int) $day);
3101 $dt->setTime((
int) $hour, (
int) $minute, (
int) $second);
3102 $date = $dt->getTimestamp();
3122 if ($mode ===
'auto') {
3126 if ($mode ==
'gmt') {
3128 } elseif ($mode ==
'tzserver') {
3129 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
3131 $ret = (int) (
dol_now(
'gmt') + ($tzsecond * 3600));
3137 } elseif ($mode ==
'tzuser' || $mode ==
'tzuserrel') {
3140 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
3141 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
3142 $ret = (int) (
dol_now(
'gmt') + ($offsettz + $offsetdst));
3159 global $conf, $langs;
3162 if (!empty($conf->dol_optimize_smallscreen)) {
3167 if (empty($shortvalue) || $size < ($level * 10)) {
3169 $textunitshort = $langs->trans(
"b");
3170 $textunitlong = $langs->trans(
"Bytes");
3172 $ret = round($size / $level, 0);
3173 $textunitshort = $langs->trans(
"Kb");
3174 $textunitlong = $langs->trans(
"KiloBytes");
3177 if (empty($shortunit)) {
3178 $ret .=
' '.$textunitlong;
3180 $ret .=
' '.$textunitshort;
3196function dol_print_url($url, $target =
'_blank', $max = 32, $withpicto = 0, $morecss =
'float')
3204 $link =
'<a href="';
3205 if (!preg_match(
'/^http/i', $url)) {
3211 $link .=
' target="'.$target.
'"';
3214 if (!preg_match(
'/^http/i', $url)) {
3220 if ($morecss ==
'float') {
3221 return '<div class="nospan'.($morecss ?
' '.$morecss :
'').
'" style="margin-right: 10px">'.($withpicto ?
img_picto($langs->trans(
"Url"),
'globe').
' ' :
'').$link.
'</div>';
3223 return '<span class="nospan'.($morecss ?
' '.$morecss :
'').
'" style="margin-right: 10px">'.($withpicto ?
img_picto($langs->trans(
"Url"),
'globe').
' ' :
'').$link.
'</span>';
3239function dol_print_email($email, $cid = 0, $socid = 0, $addlink = 0, $max = 64, $showinvalid = 1, $withpicto = 0)
3241 global $conf, $user, $langs, $hookmanager;
3245 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) {
3249 if (empty($email)) {
3253 if (!empty($addlink)) {
3254 $newemail =
'<a style="text-overflow: ellipsis;" href="';
3255 if (!preg_match(
'/^mailto:/i', $email)) {
3256 $newemail .=
'mailto:';
3258 $newemail .= $email;
3261 $newemail .=
'</a>';
3263 $langs->load(
"errors");
3264 $newemail .=
img_warning($langs->trans(
"ErrorBadEMail", $email));
3267 if (($cid || $socid) && isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
3270 if (!empty($conf->global->AGENDA_ADDACTIONFOREMAIL)) {
3271 $link =
'<a href="'.DOL_URL_ROOT.
'/comm/action/card.php?action=create&backtopage=1&actioncode='.$type.
'&contactid='.$cid.
'&socid='.$socid.
'">'.
img_object($langs->trans(
"AddAction"),
"calendar").
'</a>';
3274 $newemail =
'<div>'.$newemail.
' '.$link.
'</div>';
3279 $langs->load(
"errors");
3280 $newemail .=
img_warning($langs->trans(
"ErrorBadEMail", $email));
3285 $rep = ($withpicto ?
img_picto($langs->trans(
"EMail").
' : '.$email, (is_numeric($withpicto) ?
'email' : $withpicto)).
' ' :
'').$newemail;
3288 $parameters = array(
'cid' => $cid,
'socid' => $socid,
'addlink' => $addlink,
'picto' => $withpicto);
3290 $reshook = $hookmanager->executeHooks(
'printEmail', $parameters, $email);
3294 $rep .= $hookmanager->resPrint;
3309 $socialnetworks = array();
3311 require_once DOL_DOCUMENT_ROOT.
'/core/lib/memory.lib.php';
3312 $cachekey =
'socialnetworks_' . $conf->entity;
3314 if (!is_null($dataretrieved)) {
3315 $socialnetworks = $dataretrieved;
3317 $sql =
"SELECT rowid, code, label, url, icon, active FROM ".MAIN_DB_PREFIX.
"c_socialnetworks";
3318 $sql .=
" WHERE entity=".$conf->entity;
3319 $resql = $db->query($sql);
3321 while ($obj = $db->fetch_object($resql)) {
3322 $socialnetworks[$obj->code] = array(
3323 'rowid' => $obj->rowid,
3324 'label' => $obj->label,
3326 'icon' => $obj->icon,
3327 'active' => $obj->active,
3334 return $socialnetworks;
3349 global $conf, $user, $langs;
3353 if (empty($value)) {
3357 if (!empty($type)) {
3358 $htmllink =
'<div class="divsocialnetwork inline-block valignmiddle">';
3360 $htmllink .=
'<span class="fa pictofixedwidth '.($dictsocialnetworks[$type][
'icon'] ? $dictsocialnetworks[$type][
'icon'] :
'fa-link').
'"></span>';
3361 if ($type ==
'skype') {
3363 $htmllink .=
' <a href="skype:';
3365 $htmllink .=
'?call" alt="'.$langs->trans(
"Call").
' '.$value.
'" title="'.
dol_escape_htmltag($langs->trans(
"Call").
' '.$value).
'">';
3366 $htmllink .=
'<img src="'.DOL_URL_ROOT.
'/theme/common/skype_callbutton.png" border="0">';
3367 $htmllink .=
'</a><a href="skype:';
3369 $htmllink .=
'?chat" alt="'.$langs->trans(
"Chat").
' '.$value.
'" title="'.
dol_escape_htmltag($langs->trans(
"Chat").
' '.$value).
'">';
3370 $htmllink .=
'<img class="paddingleft" src="'.DOL_URL_ROOT.
'/theme/common/skype_chatbutton.png" border="0">';
3371 $htmllink .=
'</a>';
3372 if (($cid || $socid) && isModEnabled(
'agenda') && $user->hasRight(
'agenda',
'myactions',
'create')) {
3373 $addlink =
'AC_SKYPE';
3375 if (!empty($conf->global->AGENDA_ADDACTIONFORSKYPE)) {
3376 $link =
'<a href="'.DOL_URL_ROOT.
'/comm/action/card.php?action=create&backtopage=1&actioncode='.$addlink.
'&contactid='.$cid.
'&socid='.$socid.
'">'.
img_object($langs->trans(
"AddAction"),
"calendar").
'</a>';
3378 $htmllink .= ($link ?
' '.$link :
'');
3381 if (!empty($dictsocialnetworks[$type][
'url'])) {
3382 $tmpvirginurl = preg_replace(
'/\/?{socialid}/',
'', $dictsocialnetworks[$type][
'url']);
3383 if ($tmpvirginurl) {
3384 $value = preg_replace(
'/^www\.'.preg_quote($tmpvirginurl,
'/').
'\/?/',
'', $value);
3385 $value = preg_replace(
'/^'.preg_quote($tmpvirginurl,
'/').
'\/?/',
'', $value);
3387 $tmpvirginurl3 = preg_replace(
'/^https:\/\//i',
'https://www.', $tmpvirginurl);
3388 if ($tmpvirginurl3) {
3389 $value = preg_replace(
'/^www\.'.preg_quote($tmpvirginurl3,
'/').
'\/?/',
'', $value);
3390 $value = preg_replace(
'/^'.preg_quote($tmpvirginurl3,
'/').
'\/?/',
'', $value);
3393 $tmpvirginurl2 = preg_replace(
'/^https?:\/\//i',
'', $tmpvirginurl);
3394 if ($tmpvirginurl2) {
3395 $value = preg_replace(
'/^www\.'.preg_quote($tmpvirginurl2,
'/').
'\/?/',
'', $value);
3396 $value = preg_replace(
'/^'.preg_quote($tmpvirginurl2,
'/').
'\/?/',
'', $value);
3399 $link = str_replace(
'{socialid}', $value, $dictsocialnetworks[$type][
'url']);
3400 if (preg_match(
'/^https?:\/\//i', $link)) {
3401 $htmllink .=
'<a href="'.dol_sanitizeUrl($link, 0).
'" target="_blank" rel="noopener noreferrer">'.
dol_escape_htmltag($value).
'</a>';
3403 $htmllink .=
'<a href="'.dol_sanitizeUrl($link, 1).
'" target="_blank" rel="noopener noreferrer">'.
dol_escape_htmltag($value).
'</a>';
3409 $htmllink .=
'</div>';
3411 $langs->load(
"errors");
3412 $htmllink .=
img_warning($langs->trans(
"ErrorBadSocialNetworkValue", $value));
3427function dol_print_profids($profID, $profIDtype, $countrycode =
'', $addcpButton = 1, $separ =
' ')
3431 if (empty($profID) || empty($profIDtype)) {
3434 if (empty($countrycode)) $countrycode = $mysoc->country_code;
3435 $newProfID = $profID;
3436 $id = substr($profIDtype, -1);
3438 if (strtoupper($countrycode) ==
'FR') {
3440 if ($id == 1 &&
dol_strlen($newProfID) == 9) $newProfID = substr($newProfID, 0, 3).$separ.substr($newProfID, 3, 3).$separ.substr($newProfID, 6, 3);
3441 if ($id == 2 &&
dol_strlen($newProfID) == 14) $newProfID = substr($newProfID, 0, 3).$separ.substr($newProfID, 3, 3).$separ.substr($newProfID, 6, 3).$separ.substr($newProfID, 9, 5);
3442 if ($profIDtype ===
'VAT' &&
dol_strlen($newProfID) == 13) $newProfID = substr($newProfID, 0, 4).$separ.substr($newProfID, 4, 3).$separ.substr($newProfID, 7, 3).$separ.substr($newProfID, 10, 3);
3445 else $ret = $newProfID;
3463function dol_print_phone($phone, $countrycode =
'', $cid = 0, $socid = 0, $addlink =
'', $separ =
" ", $withpicto =
'', $titlealt =
'', $adddivfloat = 0)
3465 global $conf, $user, $langs, $mysoc, $hookmanager;
3468 $phone = is_null($phone) ?
'' : preg_replace(
"/[\s.-]/",
"", trim($phone));
3469 if (empty($phone)) {
3472 if (!empty($conf->global->MAIN_PHONE_SEPAR)) {
3473 $separ = $conf->global->MAIN_PHONE_SEPAR;
3475 if (empty($countrycode) && is_object($mysoc)) {
3476 $countrycode = $mysoc->country_code;
3480 if ($conf->dol_optimize_smallscreen) {
3485 if (strtoupper($countrycode) ==
"FR") {
3488 $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);
3490 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 2).$separ.substr($newphone, 5, 2);
3492 $newphone = substr($newphone, 0, 2).$separ.substr($newphone, 2, 3).$separ.substr($newphone, 5, 2).$separ.substr($newphone, 7, 2);
3494 $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);
3496 $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);
3498 $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);
3500 } elseif (strtoupper($countrycode) ==
"CA") {
3502 $newphone = ($separ !=
'' ?
'(' :
'').substr($newphone, 0, 3).($separ !=
'' ?
')' :
'').$separ.substr($newphone, 3, 3).($separ !=
'' ?
'-' :
'').substr($newphone, 6, 4);
3504 } elseif (strtoupper($countrycode) ==
"PT") {
3506 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3508 } elseif (strtoupper($countrycode) ==
"SR") {
3510 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3);
3512 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 4);
3514 } elseif (strtoupper($countrycode) ==
"DE") {
3516 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 4).$separ.substr($newphone, 11, 3);
3518 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 4).$separ.substr($newphone, 10, 3);
3520 } elseif (strtoupper($countrycode) ==
"ES") {
3522 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3524 } elseif (strtoupper($countrycode) ==
"BF") {
3526 $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);
3528 } elseif (strtoupper($countrycode) ==
"RO") {
3530 $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);
3532 } elseif (strtoupper($countrycode) ==
"TR") {
3534 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 4);
3536 } elseif (strtoupper($countrycode) ==
"US") {
3538 $newphone = substr($newphone, 0, 2).$separ.substr($newphone, 2, 3).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 4);
3540 } elseif (strtoupper($countrycode) ==
"MX") {
3542 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 2);
3544 $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);
3546 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 4);
3548 } elseif (strtoupper($countrycode) ==
"ML") {
3550 $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);
3552 } elseif (strtoupper($countrycode) ==
"TH") {
3554 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 3);
3556 $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);
3558 } elseif (strtoupper($countrycode) ==
"MU") {
3561 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 2).$separ.substr($newphone, 9, 2);
3563 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 4).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 2);
3565 } elseif (strtoupper($countrycode) ==
"ZA") {
3567 $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);
3569 } elseif (strtoupper($countrycode) ==
"SY") {
3571 $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);
3573 $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);
3575 } elseif (strtoupper($countrycode) ==
"AE") {
3577 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 2);
3579 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3581 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 4);
3583 } elseif (strtoupper($countrycode) ==
"DZ") {
3585 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3587 } elseif (strtoupper($countrycode) ==
"BE") {
3589 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 3);
3591 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3593 } elseif (strtoupper($countrycode) ==
"PF") {
3595 $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);
3597 } elseif (strtoupper($countrycode) ==
"CO") {
3599 $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);
3601 } elseif (strtoupper($countrycode) ==
"JO") {
3603 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 1).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 7, 2).$separ.substr($newphone, 9, 2);
3605 } elseif (strtoupper($countrycode) ==
"JM") {
3607 $newphone = substr($newphone, 0, 5).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 4);
3609 } elseif (strtoupper($countrycode) ==
"MG") {
3611 $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);
3613 } elseif (strtoupper($countrycode) ==
"GB") {
3615 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3617 } elseif (strtoupper($countrycode) ==
"CH") {
3619 $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);
3621 $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);
3623 } elseif (strtoupper($countrycode) ==
"TN") {
3625 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3627 } elseif (strtoupper($countrycode) ==
"GF") {
3629 $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);
3631 } elseif (strtoupper($countrycode) ==
"GP") {
3633 $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);
3635 } elseif (strtoupper($countrycode) ==
"MQ") {
3637 $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);
3639 } elseif (strtoupper($countrycode) ==
"IT") {
3641 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3643 $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);
3645 } elseif (strtoupper($countrycode) ==
"AU") {
3649 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 1).$separ.substr($newphone, 4, 4).$separ.substr($newphone, 8, 4);
3651 } elseif (strtoupper($countrycode) ==
"LU") {
3654 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 2);
3656 $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);
3658 $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);
3660 $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);
3663 if (!empty($addlink)) {
3664 if ($addlink ==
'tel' || $conf->browser->layout ==
'phone' || (isModEnabled(
'clicktodial') && !empty($conf->global->CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS))) {
3665 $newphoneform = $newphone;
3666 $newphone =
'<a href="tel:'.$phone.
'"';
3667 $newphone .=
'>'.$newphoneform.
'</a>';
3668 } elseif (isModEnabled(
'clicktodial') && $addlink ==
'AC_TEL') {
3669 if (empty($user->clicktodial_loaded)) {
3670 $user->fetch_clicktodial();
3674 $urlmask =
'ErrorClickToDialModuleNotConfigured';
3675 if (!empty($conf->global->CLICKTODIAL_URL)) {
3676 $urlmask = $conf->global->CLICKTODIAL_URL;
3678 if (!empty($user->clicktodial_url)) {
3679 $urlmask = $user->clicktodial_url;
3682 $clicktodial_poste = (!empty($user->clicktodial_poste) ?urlencode($user->clicktodial_poste) :
'');
3683 $clicktodial_login = (!empty($user->clicktodial_login) ?urlencode($user->clicktodial_login) :
'');
3684 $clicktodial_password = (!empty($user->clicktodial_password) ?urlencode($user->clicktodial_password) :
'');
3686 $url = sprintf($urlmask, urlencode($phone), $clicktodial_poste, $clicktodial_login, $clicktodial_password);
3688 $substitarray = array(
'__PHONEFROM__'=>$clicktodial_poste,
3689 '__PHONETO__'=>urlencode($phone),
3690 '__LOGIN__'=>$clicktodial_login,
3691 '__PASS__'=>$clicktodial_password);
3693 $newphonesav = $newphone;
3694 if (empty($conf->global->CLICKTODIAL_DO_NOT_USE_AJAX_CALL)) {
3696 $newphone =
'<a href="'.$url.
'" class="cssforclicktodial"';
3697 $newphone .=
'>'.$newphonesav.
'</a>';
3700 $newphone =
'<a href="'.$url.
'"';
3701 if (!empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) {
3702 $newphone .=
' target="_blank" rel="noopener noreferrer"';
3704 $newphone .=
'>'.$newphonesav.
'</a>';
3709 if (isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
3712 if ($addlink ==
'AC_FAX') {
3715 if (!empty($conf->global->AGENDA_ADDACTIONFORPHONE)) {
3716 $link =
'<a href="'.DOL_URL_ROOT.
'/comm/action/card.php?action=create&backtopage='. urlencode($_SERVER[
'REQUEST_URI']) .
'&actioncode='.$type.($cid ?
'&contactid='.$cid :
'').($socid ?
'&socid='.$socid :
'').
'">'.
img_object($langs->trans(
"AddAction"),
"calendar").
'</a>';
3719 $newphone =
'<div>'.$newphone.
' '.$link.
'</div>';
3724 if (empty($titlealt)) {
3725 $titlealt = ($withpicto ==
'fax' ? $langs->trans(
"Fax") : $langs->trans(
"Phone"));
3730 $parameters = array(
'countrycode' => $countrycode,
'cid' => $cid,
'socid' => $socid,
'titlealt' => $titlealt,
'picto' => $withpicto);
3731 $reshook = $hookmanager->executeHooks(
'printPhone', $parameters, $phone);
3732 $rep .= $hookmanager->resPrint;
3734 if (empty($reshook)) {
3737 if ($withpicto ==
'fax') {
3738 $picto =
'phoning_fax';
3739 } elseif ($withpicto ==
'phone') {
3741 } elseif ($withpicto ==
'mobile') {
3742 $picto =
'phoning_mobile';
3747 if ($adddivfloat == 1) {
3748 $rep .=
'<div class="nospan float" style="margin-right: 10px">';
3749 } elseif (empty($adddivfloat)) {
3750 $rep .=
'<span style="margin-right: 10px;">';
3752 $rep .= ($withpicto ?
img_picto($titlealt,
'object_'.$picto.
'.png').
' ' :
'').$newphone;
3753 if ($adddivfloat == 1) {
3755 } elseif (empty($adddivfloat)) {
3772 global $conf, $langs;
3783 if (file_exists(DOL_DOCUMENT_ROOT.
'/theme/common/flags/'.$countrycode.
'.png')) {
3784 $ret .=
' '.img_picto($countrycode.
' '.$langs->trans(
"AccordingToGeoIPDatabase"), DOL_URL_ROOT.
'/theme/common/flags/'.$countrycode.
'.png',
'', 1);
3786 $ret .=
' ('.$countrycode.
')';
3806 if (empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) || preg_match(
'/[^0-9\.\:,\[\]]/', $_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
3807 if (empty($_SERVER[
'HTTP_CLIENT_IP']) || preg_match(
'/[^0-9\.\:,\[\]]/', $_SERVER[
'HTTP_CLIENT_IP'])) {
3808 if (empty($_SERVER[
"HTTP_CF_CONNECTING_IP"])) {
3809 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
3811 $ip = $_SERVER[
"HTTP_CF_CONNECTING_IP"];
3814 $ip = $_SERVER[
'HTTP_CLIENT_IP'];
3817 $ip = $_SERVER[
'HTTP_X_FORWARDED_FOR'];
3833 if (isset($_SERVER[
'HTTPS']) && $_SERVER[
'HTTPS'] ==
'on') {
3835 } elseif (!empty($_SERVER[
'HTTP_X_FORWARDED_PROTO']) && $_SERVER[
'HTTP_X_FORWARDED_PROTO'] ==
'https' || !empty($_SERVER[
'HTTP_X_FORWARDED_SSL']) && $_SERVER[
'HTTP_X_FORWARDED_SSL'] ==
'on') {
3853 if (!empty($conf->geoipmaxmind->enabled)) {
3857 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeoip.class.php';
3858 $geoip =
new DolGeoIP(
'country', $datafile);
3860 $countrycode = $geoip->getCountryCodeFromIP($ip);
3863 return $countrycode;
3875 global $conf, $langs, $user;
3879 if (!empty($conf->geoipmaxmind->enabled)) {
3884 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeoip.class.php';
3885 $geoip =
new DolGeoIP(
'country', $datafile);
3886 $countrycode = $geoip->getCountryCodeFromIP($ip);
3887 $ret = $countrycode;
3906 global $conf, $user, $langs, $hookmanager;
3912 $parameters = array(
'element' => $element,
'id' => $id);
3913 $reshook = $hookmanager->executeHooks(
'printAddress', $parameters, $address);
3914 $out .= $hookmanager->resPrint;
3916 if (empty($reshook)) {
3917 if (empty($charfornl)) {
3918 $out .= nl2br($address);
3920 $out .= preg_replace(
'/[\r\n]+/', $charfornl, $address);
3924 $showgmap = $showomap = 0;
3925 if (($element ==
'thirdparty' || $element ==
'societe') && isModEnabled(
'google') && !empty($conf->global->GOOGLE_ENABLE_GMAPS)) {
3928 if ($element ==
'contact' && isModEnabled(
'google') && !empty($conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS)) {
3931 if ($element ==
'member' && isModEnabled(
'google') && !empty($conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS)) {
3934 if (($element ==
'thirdparty' || $element ==
'societe') && isModEnabled(
'openstreetmap') && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS)) {
3937 if ($element ==
'contact' && isModEnabled(
'openstreetmap') && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS)) {
3940 if ($element ==
'member' && isModEnabled(
'openstreetmap') && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS)) {
3944 $url =
dol_buildpath(
'/google/gmaps.php?mode='.$element.
'&id='.$id, 1);
3945 $out .=
' <a href="'.$url.
'" target="_gmaps"><img id="'.$htmlid.
'" class="valigntextbottom" src="'.DOL_URL_ROOT.
'/theme/common/gmap.png"></a>';
3948 $url =
dol_buildpath(
'/openstreetmap/maps.php?mode='.$element.
'&id='.$id, 1);
3949 $out .=
' <a href="'.$url.
'" target="_gmaps"><img id="'.$htmlid.
'_openstreetmap" class="valigntextbottom" src="'.DOL_URL_ROOT.
'/theme/common/gmap.png"></a>';
3970function isValidEmail($address, $acceptsupervisorkey = 0, $acceptuserkey = 0)
3972 if ($acceptsupervisorkey && $address ==
'__SUPERVISOREMAIL__') {
3975 if ($acceptuserkey && $address ==
'__USER_EMAIL__') {
3978 if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
3995 if (function_exists(
'idn_to_ascii') && function_exists(
'checkdnsrr')) {
3996 if (!checkdnsrr(idn_to_ascii($domain),
'MX')) {
3999 if (function_exists(
'getmxrr')) {
4002 getmxrr(idn_to_ascii($domain), $mxhosts, $weight);
4003 if (count($mxhosts) > 1) {
4006 if (count($mxhosts) == 1 && !empty($mxhosts[0])) {
4043 $tmparray = explode(
' ', $s);
4044 foreach ($tmparray as $tmps) {
4061 if (is_null($string)) {
4065 if (function_exists(
'mb_strlen')) {
4066 return mb_strlen($string, $stringencoding);
4068 return strlen($string);
4082function dol_substr($string, $start, $length =
null, $stringencoding =
'', $trunconbytes = 0)
4086 if (empty($stringencoding)) {
4087 $stringencoding = $langs->charset_output;
4091 if (empty($trunconbytes)) {
4092 if (function_exists(
'mb_substr')) {
4093 $ret = mb_substr($string, $start, $length, $stringencoding);
4095 $ret = substr($string, $start, $length);
4098 if (function_exists(
'mb_strcut')) {
4099 $ret = mb_strcut($string, $start, $length, $stringencoding);
4101 $ret = substr($string, $start, $length);
4121function dol_trunc($string, $size = 40, $trunc =
'right', $stringencoding =
'UTF-8', $nodot = 0, $display = 0)
4125 if (empty($size) || !empty($conf->global->MAIN_DISABLE_TRUNC)) {
4129 if (empty($stringencoding)) {
4130 $stringencoding =
'UTF-8';
4133 if ($conf->dol_optimize_smallscreen == 1 && $display == 1) {
4134 $size = round($size / 3);
4138 if ($trunc ==
'right') {
4140 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
4142 return dol_substr($newstring, 0, $size, $stringencoding).($nodot ?
'' :
'…');
4147 } elseif ($trunc ==
'middle') {
4149 if (
dol_strlen($newstring, $stringencoding) > 2 &&
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
4150 $size1 = round($size / 2);
4151 $size2 = round($size / 2);
4152 return dol_substr($newstring, 0, $size1, $stringencoding).
'…'.
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
4156 } elseif ($trunc ==
'left') {
4158 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
4160 return '…'.dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
4164 } elseif ($trunc ==
'wrap') {
4166 if (
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
4172 return 'BadParam3CallingDolTrunc';
4197function img_picto($titlealt, $picto, $moreatt =
'', $pictoisfullpath =
false, $srconly = 0, $notitle = 0, $alt =
'', $morecss =
'', $marginleftonlyshort = 2)
4199 global $conf, $langs;
4202 $url = DOL_URL_ROOT;
4203 $theme = isset($conf->theme) ? $conf->theme :
null;
4204 $path =
'theme/'.$theme;
4206 if ($pictoisfullpath) {
4208 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
4211 $fullpathpicto = $picto;
4213 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
4214 $morecss .= ($morecss ?
' ' :
'').$reg[1];
4215 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
4218 $pictowithouttext = preg_replace(
'/(\.png|\.gif|\.svg)$/',
'', $picto);
4219 $pictowithouttext = str_replace(
'object_',
'', $pictowithouttext);
4220 $pictowithouttext = str_replace(
'_nocolor',
'', $pictowithouttext);
4222 if (strpos($pictowithouttext,
'fontawesome_') !==
false || preg_match(
'/^fa-/', $pictowithouttext)) {
4224 $pictowithouttext = str_replace(
'fontawesome_',
'', $pictowithouttext);
4225 $pictowithouttext = str_replace(
'fa-',
'', $pictowithouttext);
4227 $pictowithouttextarray = explode(
'_', $pictowithouttext);
4228 $marginleftonlyshort = 0;
4230 if (!empty($pictowithouttextarray[1])) {
4232 $fakey =
'fa-'.$pictowithouttextarray[0];
4233 $fa = empty($pictowithouttextarray[1]) ?
'fa' : $pictowithouttextarray[1];
4234 $facolor = empty($pictowithouttextarray[2]) ?
'' : $pictowithouttextarray[2];
4235 $fasize = empty($pictowithouttextarray[3]) ?
'' : $pictowithouttextarray[3];
4237 $fakey =
'fa-'.$pictowithouttext;
4247 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
4248 $morecss .= ($morecss ?
' ' :
'').$reg[1];
4249 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
4251 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
4252 $morestyle = $reg[1];
4253 $moreatt = str_replace(
'style="'.$reg[1].
'"',
'', $moreatt);
4255 $moreatt = trim($moreatt);
4257 $enabledisablehtml =
'<span class="'.$fa.
' '.$fakey.($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
4258 $enabledisablehtml .= ($morecss ?
' '.$morecss :
'').
'" style="'.($fasize ? (
'font-size: '.$fasize.
';') :
'').($facolor ? (
' color: '.$facolor.
';') :
'').($morestyle ?
' '.$morestyle :
'').
'"'.(($notitle || empty($titlealt)) ?
'' :
' title="'.dol_escape_htmltag($titlealt).
'"').($moreatt ?
' '.$moreatt :
'').
'>';
4262 $enabledisablehtml .=
'</span>';
4264 return $enabledisablehtml;
4267 if (empty($srconly) && in_array($pictowithouttext, array(
4268 '1downarrow',
'1uparrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected',
4269 'accountancy',
'accounting_account',
'account',
'accountline',
'action',
'add',
'address',
'angle-double-down',
'angle-double-up',
'asset',
4270 'bank_account',
'barcode',
'bank',
'bell',
'bill',
'billa',
'billr',
'billd',
'birthday-cake',
'bookmark',
'bom',
'briefcase-medical',
'bug',
'building',
4271 'card',
'calendarlist',
'calendar',
'calendarmonth',
'calendarweek',
'calendarday',
'calendarperuser',
'calendarpertype',
4272 'cash-register',
'category',
'chart',
'check',
'clock',
'clone',
'close_title',
'cog',
'collab',
'company',
'contact',
'country',
'contract',
'conversation',
'cron',
'cross',
'cubes',
4273 'currency',
'multicurrency',
4274 'delete',
'dolly',
'dollyrevert',
'donation',
'download',
'dynamicprice',
4275 'edit',
'ellipsis-h',
'email',
'entity',
'envelope',
'eraser',
'establishment',
'expensereport',
'external-link-alt',
'external-link-square-alt',
'eye',
4276 'filter',
'file-code',
'file-export',
'file-import',
'file-upload',
'autofill',
'folder',
'folder-open',
'folder-plus',
4277 'gears',
'generate',
'generic',
'globe',
'globe-americas',
'graph',
'grip',
'grip_title',
'group',
4278 'hands-helping',
'help',
'holiday',
4279 'id-card',
'images',
'incoterm',
'info',
'intervention',
'inventory',
'intracommreport',
'jobprofile',
4280 'knowledgemanagement',
4281 'label',
'language',
'line',
'link',
'list',
'list-alt',
'listlight',
'loan',
'lock',
'lot',
'long-arrow-alt-right',
4282 'margin',
'map-marker-alt',
'member',
'meeting',
'money-bill-alt',
'movement',
'mrp',
'note',
'next',
4283 'off',
'on',
'order',
4284 'paiment',
'paragraph',
'play',
'pdf',
'phone',
'phoning',
'phoning_mobile',
'phoning_fax',
'playdisabled',
'previous',
'poll',
'pos',
'printer',
'product',
'propal',
'proposal',
'puce',
4285 'stock',
'resize',
'service',
'stats',
'trip',
4286 'security',
'setup',
'share-alt',
'sign-out',
'split',
'stripe',
'stripe-s',
'switch_off',
'switch_on',
'switch_on_warning',
'switch_on_red',
'tools',
'unlink',
'uparrow',
'user',
'user-tie',
'vcard',
'wrench',
4287 'github',
'google',
'jabber',
'microsoft',
'skype',
'twitter',
'facebook',
'linkedin',
'instagram',
'snapchat',
'youtube',
'google-plus-g',
'whatsapp',
4288 'chevron-left',
'chevron-right',
'chevron-down',
'chevron-top',
'commercial',
'companies',
4289 'generic',
'home',
'hrm',
'members',
'products',
'invoicing',
4290 'partnership',
'payment',
'payment_vat',
'pencil-ruler',
'pictoconfirm',
'preview',
'project',
'projectpub',
'projecttask',
'question',
'refresh',
'region',
4291 'salary',
'shipment',
'state',
'supplier_invoice',
'supplier_invoicea',
'supplier_invoicer',
'supplier_invoiced',
4292 'technic',
'ticket',
4294 'recent',
'reception',
'recruitmentcandidature',
'recruitmentjobposition',
'replacement',
'resource',
'recurring',
'rss',
4295 'shapes',
'skill',
'square',
'stop-circle',
'supplier',
'supplier_proposal',
'supplier_order',
'supplier_invoice',
4296 'timespent',
'title_setup',
'title_accountancy',
'title_bank',
'title_hrm',
'title_agenda',
4297 'uncheck',
'url',
'user-cog',
'user-injured',
'user-md',
'vat',
'website',
'workstation',
'webhook',
'world',
'private',
4298 'conferenceorbooth',
'eventorganization',
4299 'stamp',
'signature'
4301 $fakey = $pictowithouttext;
4305 if (in_array($pictowithouttext, array(
'card',
'bell',
'clock',
'establishment',
'generic',
'minus-square',
'object_generic',
'pdf',
'plus-square',
'timespent',
'note',
'off',
'on',
'object_bookmark',
'bookmark',
'vcard'))) {
4308 if (in_array($pictowithouttext, array(
'black-tie',
'github',
'google',
'microsoft',
'skype',
'twitter',
'facebook',
'linkedin',
'instagram',
'snapchat',
'stripe',
'stripe-s',
'youtube',
'google-plus-g',
'whatsapp'))) {
4312 $arrayconvpictotofa = array(
4313 'account'=>
'university',
'accounting_account'=>
'clipboard-list',
'accountline'=>
'receipt',
'accountancy'=>
'search-dollar',
'action'=>
'calendar-alt',
'add'=>
'plus-circle',
'address'=>
'address-book',
'asset'=>
'money-check-alt',
'autofill'=>
'fill',
4314 'bank_account'=>
'university',
4315 'bill'=>
'file-invoice-dollar',
'billa'=>
'file-excel',
'billr'=>
'file-invoice-dollar',
'billd'=>
'file-medical',
4316 'supplier_invoice'=>
'file-invoice-dollar',
'supplier_invoicea'=>
'file-excel',
'supplier_invoicer'=>
'file-invoice-dollar',
'supplier_invoiced'=>
'file-medical',
4318 'card'=>
'address-card',
'chart'=>
'chart-line',
'company'=>
'building',
'contact'=>
'address-book',
'contract'=>
'suitcase',
'collab'=>
'people-arrows',
'conversation'=>
'comments',
'country'=>
'globe-americas',
'cron'=>
'business-time',
'cross'=>
'times',
4319 'donation'=>
'file-alt',
'dynamicprice'=>
'hand-holding-usd',
4320 'setup'=>
'cog',
'companies'=>
'building',
'products'=>
'cube',
'commercial'=>
'suitcase',
'invoicing'=>
'coins',
4321 'accounting'=>
'search-dollar',
'category'=>
'tag',
'dollyrevert'=>
'dolly',
4322 'generate'=>
'plus-square',
'hrm'=>
'user-tie',
'incoterm'=>
'truck-loading',
4323 'margin'=>
'calculator',
'members'=>
'user-friends',
'ticket'=>
'ticket-alt',
'globe'=>
'external-link-alt',
'lot'=>
'barcode',
4324 'email'=>
'at',
'establishment'=>
'building',
'edit'=>
'pencil-alt',
'entity'=>
'globe',
4325 'graph'=>
'chart-line',
'grip_title'=>
'arrows-alt',
'grip'=>
'arrows-alt',
'help'=>
'question-circle',
4326 'generic'=>
'file',
'holiday'=>
'umbrella-beach',
4327 'info'=>
'info-circle',
'inventory'=>
'boxes',
'intracommreport'=>
'globe-europe',
'jobprofile'=>
'cogs',
4328 'knowledgemanagement'=>
'ticket-alt',
'label'=>
'layer-group',
'line'=>
'bars',
'loan'=>
'money-bill-alt',
4329 'member'=>
'user-alt',
'meeting'=>
'chalkboard-teacher',
'mrp'=>
'cubes',
'next'=>
'arrow-alt-circle-right',
4330 'trip'=>
'wallet',
'expensereport'=>
'wallet',
'group'=>
'users',
'movement'=>
'people-carry',
4331 'sign-out'=>
'sign-out-alt',
4332 'switch_off'=>
'toggle-off',
'switch_on'=>
'toggle-on',
'switch_on_warning'=>
'toggle-on',
'switch_on_red'=>
'toggle-on',
'check'=>
'check',
'bookmark'=>
'star',
4333 'bank'=>
'university',
'close_title'=>
'times',
'delete'=>
'trash',
'filter'=>
'filter',
4334 'list-alt'=>
'list-alt',
'calendarlist'=>
'bars',
'calendar'=>
'calendar-alt',
'calendarmonth'=>
'calendar-alt',
'calendarweek'=>
'calendar-week',
'calendarday'=>
'calendar-day',
'calendarperuser'=>
'table',
4335 'intervention'=>
'ambulance',
'invoice'=>
'file-invoice-dollar',
'currency'=>
'dollar-sign',
'multicurrency'=>
'dollar-sign',
'order'=>
'file-invoice',
4336 'error'=>
'exclamation-triangle',
'warning'=>
'exclamation-triangle',
4338 'playdisabled'=>
'play',
'pdf'=>
'file-pdf',
'poll'=>
'check-double',
'pos'=>
'cash-register',
'preview'=>
'binoculars',
'project'=>
'project-diagram',
'projectpub'=>
'project-diagram',
'projecttask'=>
'tasks',
'propal'=>
'file-signature',
'proposal'=>
'file-signature',
4339 'partnership'=>
'handshake',
'payment'=>
'money-check-alt',
'payment_vat'=>
'money-check-alt',
'pictoconfirm'=>
'check-square',
'phoning'=>
'phone',
'phoning_mobile'=>
'mobile-alt',
'phoning_fax'=>
'fax',
'previous'=>
'arrow-alt-circle-left',
'printer'=>
'print',
'product'=>
'cube',
'puce'=>
'angle-right',
4340 'recent' =>
'check-square',
'reception'=>
'dolly',
'recruitmentjobposition'=>
'id-card-alt',
'recruitmentcandidature'=>
'id-badge',
4341 'resize'=>
'crop',
'supplier_order'=>
'dol-order_supplier',
'supplier_proposal'=>
'file-signature',
4342 'refresh'=>
'redo',
'region'=>
'map-marked',
'replacement'=>
'exchange-alt',
'resource'=>
'laptop-house',
'recurring'=>
'history',
4343 'service'=>
'concierge-bell',
4344 'skill'=>
'shapes',
'state'=>
'map-marked-alt',
'security'=>
'key',
'salary'=>
'wallet',
'shipment'=>
'dolly',
'stock'=>
'box-open',
'stats' =>
'chart-bar',
'split'=>
'code-branch',
'stripe'=>
'stripe-s',
4345 'supplier'=>
'building',
'technic'=>
'cogs',
4346 'timespent'=>
'clock',
'title_setup'=>
'tools',
'title_accountancy'=>
'money-check-alt',
'title_bank'=>
'university',
'title_hrm'=>
'umbrella-beach',
4347 'title_agenda'=>
'calendar-alt',
4348 'uncheck'=>
'times',
'uparrow'=>
'share',
'url'=>
'external-link-alt',
'vat'=>
'money-check-alt',
'vcard'=>
'arrow-alt-circle-down',
4349 'jabber'=>
'comment-o',
4350 'website'=>
'globe-americas',
'workstation'=>
'pallet',
'webhook'=>
'bullseye',
'world'=>
'globe',
'private'=>
'user-lock',
4351 'conferenceorbooth'=>
'chalkboard-teacher',
'eventorganization'=>
'project-diagram'
4353 if ($pictowithouttext ==
'off') {
4354 $fakey =
'fa-square';
4356 } elseif ($pictowithouttext ==
'on') {
4357 $fakey =
'fa-check-square';
4359 } elseif ($pictowithouttext ==
'listlight') {
4360 $fakey =
'fa-download';
4361 $marginleftonlyshort = 1;
4362 } elseif ($pictowithouttext ==
'printer') {
4363 $fakey =
'fa-print';
4365 } elseif ($pictowithouttext ==
'note') {
4366 $fakey =
'fa-sticky-note';
4367 $marginleftonlyshort = 1;
4368 } elseif (in_array($pictowithouttext, array(
'1uparrow',
'1downarrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected'))) {
4369 $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');
4370 $fakey =
'fa-'.$convertarray[$pictowithouttext];
4371 if (preg_match(
'/selected/', $pictowithouttext)) {
4374 $marginleftonlyshort = 1;
4375 } elseif (!empty($arrayconvpictotofa[$pictowithouttext])) {
4376 $fakey =
'fa-'.$arrayconvpictotofa[$pictowithouttext];
4378 $fakey =
'fa-'.$pictowithouttext;
4381 if (in_array($pictowithouttext, array(
'dollyrevert',
'member',
'members',
'contract',
'group',
'resource',
'shipment'))) {
4382 $morecss .=
' em092';
4384 if (in_array($pictowithouttext, array(
'conferenceorbooth',
'collab',
'eventorganization',
'holiday',
'info',
'project',
'workstation'))) {
4385 $morecss .=
' em088';
4387 if (in_array($pictowithouttext, array(
'asset',
'intervention',
'payment',
'loan',
'partnership',
'stock',
'technic'))) {
4388 $morecss .=
' em080';
4392 $arrayconvpictotomarginleftonly = array(
4393 'bank',
'check',
'delete',
'generic',
'grip',
'grip_title',
'jabber',
4394 'grip_title',
'grip',
'listlight',
'note',
'on',
'off',
'playdisabled',
'printer',
'resize',
'sign-out',
'stats',
'switch_on',
'switch_on_red',
'switch_off',
4395 'uparrow',
'1uparrow',
'1downarrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected'
4397 if (!isset($arrayconvpictotomarginleftonly[$pictowithouttext])) {
4398 $marginleftonlyshort = 0;
4402 $arrayconvpictotomorcess = array(
4403 'action'=>
'infobox-action',
'account'=>
'infobox-bank_account',
'accounting_account'=>
'infobox-bank_account',
'accountline'=>
'infobox-bank_account',
'accountancy'=>
'infobox-bank_account',
'asset'=>
'infobox-bank_account',
4404 'bank_account'=>
'infobox-bank_account',
4405 'bill'=>
'infobox-commande',
'billa'=>
'infobox-commande',
'billr'=>
'infobox-commande',
'billd'=>
'infobox-commande',
4406 'margin'=>
'infobox-bank_account',
'conferenceorbooth'=>
'infobox-project',
4407 'cash-register'=>
'infobox-bank_account',
'contract'=>
'infobox-contrat',
'check'=>
'font-status4',
'collab'=>
'infobox-action',
'conversation'=>
'infobox-contrat',
4408 'donation'=>
'infobox-commande',
'dolly'=>
'infobox-commande',
'dollyrevert'=>
'flip infobox-order_supplier',
4409 'ecm'=>
'infobox-action',
'eventorganization'=>
'infobox-project',
4410 'hrm'=>
'infobox-adherent',
'group'=>
'infobox-adherent',
'intervention'=>
'infobox-contrat',
4411 'incoterm'=>
'infobox-supplier_proposal',
4412 'currency'=>
'infobox-bank_account',
'multicurrency'=>
'infobox-bank_account',
4413 'members'=>
'infobox-adherent',
'member'=>
'infobox-adherent',
'money-bill-alt'=>
'infobox-bank_account',
4414 'order'=>
'infobox-commande',
4415 'user'=>
'infobox-adherent',
'users'=>
'infobox-adherent',
4416 'error'=>
'pictoerror',
'warning'=>
'pictowarning',
'switch_on'=>
'font-status4',
'switch_on_warning'=>
'font-status4 warning',
'switch_on_red'=>
'font-status8',
4417 'holiday'=>
'infobox-holiday',
'info'=>
'opacityhigh',
'invoice'=>
'infobox-commande',
4418 'knowledgemanagement'=>
'infobox-contrat rotate90',
'loan'=>
'infobox-bank_account',
4419 'payment'=>
'infobox-bank_account',
'payment_vat'=>
'infobox-bank_account',
'poll'=>
'infobox-adherent',
'pos'=>
'infobox-bank_account',
'project'=>
'infobox-project',
'projecttask'=>
'infobox-project',
4420 'propal'=>
'infobox-propal',
'proposal'=>
'infobox-propal',
'private'=>
'infobox-project',
4421 'reception'=>
'flip',
'recruitmentjobposition'=>
'infobox-adherent',
'recruitmentcandidature'=>
'infobox-adherent',
4422 'resource'=>
'infobox-action',
4423 'salary'=>
'infobox-bank_account',
'shipment'=>
'infobox-commande',
'supplier_invoice'=>
'infobox-order_supplier',
'supplier_invoicea'=>
'infobox-order_supplier',
'supplier_invoiced'=>
'infobox-order_supplier',
4424 'supplier'=>
'infobox-order_supplier',
'supplier_order'=>
'infobox-order_supplier',
'supplier_proposal'=>
'infobox-supplier_proposal',
4425 'ticket'=>
'infobox-contrat',
'title_accountancy'=>
'infobox-bank_account',
'title_hrm'=>
'infobox-holiday',
'expensereport'=>
'infobox-expensereport',
'trip'=>
'infobox-expensereport',
'title_agenda'=>
'infobox-action',
4426 'vat'=>
'infobox-bank_account',
4428 'list-alt'=>
'imgforviewmode',
'calendar'=>
'imgforviewmode',
'calendarweek'=>
'imgforviewmode',
'calendarmonth'=>
'imgforviewmode',
'calendarday'=>
'imgforviewmode',
'calendarperuser'=>
'imgforviewmode'
4430 if (!empty($arrayconvpictotomorcess[$pictowithouttext]) && strpos($picto,
'_nocolor') ===
false) {
4431 $morecss .= ($morecss ?
' ' :
'').$arrayconvpictotomorcess[$pictowithouttext];
4435 $arrayconvpictotocolor = array(
4436 'address'=>
'#6c6aa8',
'building'=>
'#6c6aa8',
'bom'=>
'#a69944',
4437 'clone'=>
'#999',
'cog'=>
'#999',
'companies'=>
'#6c6aa8',
'company'=>
'#6c6aa8',
'contact'=>
'#6c6aa8',
'cron'=>
'#555',
4438 'dynamicprice'=>
'#a69944',
4439 'edit'=>
'#444',
'note'=>
'#999',
'error'=>
'',
'help'=>
'#bbb',
'listlight'=>
'#999',
'language'=>
'#555',
4441 'lock'=>
'#ddd',
'lot'=>
'#a69944',
4442 'map-marker-alt'=>
'#aaa',
'mrp'=>
'#a69944',
'product'=>
'#a69944',
'service'=>
'#a69944',
'inventory'=>
'#a69944',
'stock'=>
'#a69944',
'movement'=>
'#a69944',
4443 'other'=>
'#ddd',
'world'=>
'#986c6a',
4444 'partnership'=>
'#6c6aa8',
'playdisabled'=>
'#ccc',
'printer'=>
'#444',
'projectpub'=>
'#986c6a',
'reception'=>
'#a69944',
'resize'=>
'#444',
'rss'=>
'#cba',
4446 'security'=>
'#999',
'square'=>
'#888',
'stop-circle'=>
'#888',
'stats'=>
'#444',
'switch_off'=>
'#999',
'technic'=>
'#999',
'timespent'=>
'#555',
4447 'uncheck'=>
'#800',
'uparrow'=>
'#555',
'user-cog'=>
'#999',
'country'=>
'#aaa',
'globe-americas'=>
'#aaa',
'region'=>
'#aaa',
'state'=>
'#aaa',
4448 'website'=>
'#304',
'workstation'=>
'#a69944'
4450 if (isset($arrayconvpictotocolor[$pictowithouttext]) && strpos($picto,
'_nocolor') ===
false) {
4451 $facolor = $arrayconvpictotocolor[$pictowithouttext];
4458 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
4459 $morecss .= ($morecss ?
' ' :
'').$reg[1];
4460 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
4462 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
4463 $morestyle = $reg[1];
4464 $moreatt = str_replace(
'style="'.$reg[1].
'"',
'', $moreatt);
4466 $moreatt = trim($moreatt);
4468 $enabledisablehtml =
'<span class="'.$fa.
' '.$fakey.($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
4469 $enabledisablehtml .= ($morecss ?
' '.$morecss :
'').
'" style="'.($fasize ? (
'font-size: '.$fasize.
';') :
'').($facolor ? (
' color: '.$facolor.
';') :
'').($morestyle ?
' '.$morestyle :
'').
'"'.(($notitle || empty($titlealt)) ?
'' :
' title="'.dol_escape_htmltag($titlealt).
'"').($moreatt ?
' '.$moreatt :
'').
'>';
4473 $enabledisablehtml .=
'</span>';
4475 return $enabledisablehtml;
4478 if (!empty($conf->global->MAIN_OVERWRITE_THEME_PATH)) {
4479 $path = $conf->global->MAIN_OVERWRITE_THEME_PATH.
'/theme/'.$theme;
4480 } elseif (!empty($conf->global->MAIN_OVERWRITE_THEME_RES)) {
4481 $path = $conf->global->MAIN_OVERWRITE_THEME_RES.
'/theme/'.$conf->global->MAIN_OVERWRITE_THEME_RES;
4482 } elseif (!empty($conf->modules_parts[
'theme']) && array_key_exists($theme, $conf->modules_parts[
'theme'])) {
4483 $path = $theme.
'/theme/'.$theme;
4488 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $picto, $regs)) {
4494 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
4499 foreach ($conf->file->dol_document_root as $type => $dirroot) {
4500 if ($type ==
'main') {
4504 if (file_exists($dirroot.
'/'.$path.
'/img/'.$picto)) {
4505 $url = DOL_URL_ROOT.$conf->file->dol_url_root[$type];
4511 $fullpathpicto = $url.
'/'.$path.
'/img/'.$picto;
4515 return $fullpathpicto;
4519 return '<img src="'.$fullpathpicto.
'"'.($notitle ?
'' :
' alt="'.dol_escape_htmltag($alt).
'"').(($notitle || empty($titlealt)) ?
'' :
' title="'.dol_escape_htmltag($titlealt).
'"').($moreatt ?
' '.$moreatt.($morecss ?
' class="'.$morecss.
'"' :
'') :
' class="inline-block'.($morecss ?
' '.$morecss :
'').
'"').
'>';
4535function img_object($titlealt, $picto, $moreatt =
'', $pictoisfullpath =
false, $srconly = 0, $notitle = 0)
4537 if (strpos($picto,
'^') === 0) {
4538 return img_picto($titlealt, str_replace(
'^',
'', $picto), $moreatt, $pictoisfullpath, $srconly, $notitle);
4540 return img_picto($titlealt,
'object_'.$picto, $moreatt, $pictoisfullpath, $srconly, $notitle);
4555function img_weather($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $morecss =
'')
4559 if (is_numeric($picto)) {
4562 return '<i class="fa fa-weather-level'.$picto.
'"></i>';
4563 } elseif (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
4567 $path = DOL_URL_ROOT.
'/theme/'.$conf->theme.
'/img/weather/'.$picto;
4569 return img_picto($titlealt, $path, $moreatt, 1, 0, 0,
'', $morecss);
4587 if (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
4591 if ($pictoisfullpath) {
4594 $path = DOL_URL_ROOT.
'/theme/common/'.$picto;
4596 if (!empty($conf->global->MAIN_MODULE_CAN_OVERWRITE_COMMONICONS)) {
4597 $themepath = DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/img/'.$picto;
4599 if (file_exists($themepath)) {
4605 return img_picto($titlealt, $path, $moreatt, 1, 0, $notitle);
4621function img_action($titlealt, $numaction, $picto =
'', $moreatt =
'')
4625 if (empty($titlealt) || $titlealt ==
'default') {
4626 if ($numaction ==
'-1' || $numaction ==
'ST_NO') {
4628 $titlealt = $langs->transnoentitiesnoconv(
'ChangeDoNotContact');
4629 } elseif ($numaction ==
'0' || $numaction ==
'ST_NEVER') {
4631 $titlealt = $langs->transnoentitiesnoconv(
'ChangeNeverContacted');
4632 } elseif ($numaction ==
'1' || $numaction ==
'ST_TODO') {
4634 $titlealt = $langs->transnoentitiesnoconv(
'ChangeToContact');
4635 } elseif ($numaction ==
'2' || $numaction ==
'ST_PEND') {
4637 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactInProcess');
4638 } elseif ($numaction ==
'3' || $numaction ==
'ST_DONE') {
4640 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactDone');
4642 $titlealt = $langs->transnoentitiesnoconv(
'ChangeStatus '.$numaction);
4646 if (!is_numeric($numaction)) {
4650 return img_picto($titlealt, (empty($picto) ?
'stcomm'.$numaction.
'.png' : $picto), $moreatt);
4664 if ($titlealt ==
'default') {
4665 $titlealt = $langs->trans(
'Show');
4668 return img_picto($titlealt,
'pdf'.$size.
'.png');
4682 if ($titlealt ==
'default') {
4683 $titlealt = $langs->trans(
'Add');
4686 return img_picto($titlealt,
'edit_add.png', $other);
4699 if ($titlealt ==
'default') {
4700 $titlealt = $langs->trans(
'Remove');
4703 return img_picto($titlealt,
'edit_remove.png', $other);
4714function img_edit($titlealt =
'default', $float = 0, $other =
'')
4718 if ($titlealt ==
'default') {
4719 $titlealt = $langs->trans(
'Modify');
4722 return img_picto($titlealt,
'edit.png', ($float ?
'style="float: '.($langs->tab_translate[
"DIRECTION"] ==
'rtl' ?
'left' :
'right').
'"' :
"").($other ?
' '.$other :
''));
4733function img_view($titlealt =
'default', $float = 0, $other =
'class="valignmiddle"')
4737 if ($titlealt ==
'default') {
4738 $titlealt = $langs->trans(
'View');
4741 $moreatt = ($float ?
'style="float: right" ' :
'').$other;
4743 return img_picto($titlealt,
'eye', $moreatt);
4754function img_delete($titlealt =
'default', $other =
'class="pictodelete"', $morecss =
'')
4758 if ($titlealt ==
'default') {
4759 $titlealt = $langs->trans(
'Delete');
4762 return img_picto($titlealt,
'delete.png', $other,
false, 0, 0,
'', $morecss);
4775 if ($titlealt ==
"default") {
4776 $titlealt = $langs->trans(
"Print");
4778 return img_picto($titlealt,
'printer.png', $other);
4788function img_split($titlealt =
'default', $other =
'class="pictosplit"')
4792 if ($titlealt ==
'default') {
4793 $titlealt = $langs->trans(
'Split');
4796 return img_picto($titlealt,
'split.png', $other);
4811 if (is_string($usealttitle)) {
4814 $usealttitle = $langs->trans(
'Info');
4818 return img_picto($usealttitle,
'info.png',
'style="vertical-align: middle;'.($usehelpcursor == 1 ?
' cursor: help' : ($usehelpcursor == 2 ?
' cursor: pointer' :
'')).
'"');
4831 if ($titlealt ==
'default') {
4832 $titlealt = $langs->trans(
'Informations');
4835 return img_picto($titlealt,
'info.png',
'style="vertical-align: middle;"');
4846function img_warning($titlealt =
'default', $moreatt =
'', $morecss =
'pictowarning')
4850 if ($titlealt ==
'default') {
4851 $titlealt = $langs->trans(
'Warning');
4855 return img_picto($titlealt,
'warning.png',
'class="'.$morecss.
'"'.($moreatt ? ($moreatt ==
'1' ?
' style="float: right"' :
' '.$moreatt) :
''));
4868 if ($titlealt ==
'default') {
4869 $titlealt = $langs->trans(
'Error');
4872 return img_picto($titlealt,
'error.png');
4886 if ($titlealt ==
'default') {
4887 $titlealt = $langs->trans(
'Next');
4891 return '<span class="fa fa-chevron-right paddingright paddingleft" title="'.dol_escape_htmltag($titlealt).
'"></span>';
4905 if ($titlealt ==
'default') {
4906 $titlealt = $langs->trans(
'Previous');
4910 return '<span class="fa fa-chevron-left paddingright paddingleft" title="'.dol_escape_htmltag($titlealt).
'"></span>';
4921function img_down($titlealt =
'default', $selected = 0, $moreclass =
'')
4925 if ($titlealt ==
'default') {
4926 $titlealt = $langs->trans(
'Down');
4929 return img_picto($titlealt, ($selected ?
'1downarrow_selected.png' :
'1downarrow.png'),
'class="imgdown'.($moreclass ?
" ".$moreclass :
"").
'"');
4940function img_up($titlealt =
'default', $selected = 0, $moreclass =
'')
4944 if ($titlealt ==
'default') {
4945 $titlealt = $langs->trans(
'Up');
4948 return img_picto($titlealt, ($selected ?
'1uparrow_selected.png' :
'1uparrow.png'),
'class="imgup'.($moreclass ?
" ".$moreclass :
"").
'"');
4959function img_left($titlealt =
'default', $selected = 0, $moreatt =
'')
4963 if ($titlealt ==
'default') {
4964 $titlealt = $langs->trans(
'Left');
4967 return img_picto($titlealt, ($selected ?
'1leftarrow_selected.png' :
'1leftarrow.png'), $moreatt);
4978function img_right($titlealt =
'default', $selected = 0, $moreatt =
'')
4982 if ($titlealt ==
'default') {
4983 $titlealt = $langs->trans(
'Right');
4986 return img_picto($titlealt, ($selected ?
'1rightarrow_selected.png' :
'1rightarrow.png'), $moreatt);
5000 if ($titlealt ==
'default') {
5001 $titlealt = $langs->trans(
'Active');
5005 return img_picto($titlealt,
'tick.png');
5020 if (is_null($morecss)) {
5024 if ($brand ==
'visa' || $brand ==
'Visa') {
5026 } elseif ($brand ==
'mastercard' || $brand ==
'MasterCard') {
5027 $brand =
'cc-mastercard';
5028 } elseif ($brand ==
'amex' || $brand ==
'American Express') {
5030 } elseif ($brand ==
'discover' || $brand ==
'Discover') {
5031 $brand =
'cc-discover';
5032 } elseif ($brand ==
'jcb' || $brand ==
'JCB') {
5034 } elseif ($brand ==
'diners' || $brand ==
'Diners club') {
5035 $brand =
'cc-diners-club';
5036 } elseif (!in_array($brand, array(
'cc-visa',
'cc-mastercard',
'cc-amex',
'cc-discover',
'cc-jcb',
'cc-diners-club'))) {
5037 $brand =
'credit-card';
5040 return '<span class="fa fa-'.$brand.
' fa-fw'.($morecss ?
' '.$morecss :
'').
'"></span>';
5053 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
5059 if (empty($titlealt)) {
5060 $titlealt =
'Mime type: '.$mimetype;
5064 return '<i class="fa fa-'.$mimefa.
' paddingright'.($morecss ?
' '.$morecss :
'').
'"'.($titlealt ?
' title="'.$titlealt.
'"' :
'').
'></i>';
5077 global $conf, $langs;
5079 if ($titlealt ==
'default') {
5080 $titlealt = $langs->trans(
'Search');
5083 $img =
img_picto($titlealt,
'search.png', $other,
false, 1);
5085 $input =
'<input type="image" class="liste_titre" name="button_search" src="'.$img.
'" ';
5086 $input .=
'value="'.dol_escape_htmltag($titlealt).
'" title="'.
dol_escape_htmltag($titlealt).
'" >';
5100 global $conf, $langs;
5102 if ($titlealt ==
'default') {
5103 $titlealt = $langs->trans(
'Search');
5106 $img =
img_picto($titlealt,
'searchclear.png', $other,
false, 1);
5108 $input =
'<input type="image" class="liste_titre" name="button_removefilter" src="'.$img.
'" ';
5109 $input .=
'value="'.dol_escape_htmltag($titlealt).
'" title="'.
dol_escape_htmltag($titlealt).
'" >';
5125function info_admin($text, $infoonimgalt = 0, $nodiv = 0, $admin =
'1', $morecss =
'hideonsmartphone', $textfordropdown =
'')
5127 global $conf, $langs;
5129 if ($infoonimgalt) {
5130 $result =
img_picto($text,
'info',
'class="'.($morecss ?
' '.$morecss :
'').
'"');
5132 if (empty($conf->use_javascript_ajax)) {
5133 $textfordropdown =
'';
5136 $class = (empty($admin) ?
'undefined' : ($admin ==
'1' ?
'info' : $admin));
5137 $result = ($nodiv ?
'' :
'<div class="'.$class.($morecss ?
' '.$morecss :
'').($textfordropdown ?
' hidden' :
'').
'">').
'<span class="fa fa-info-circle" title="'.
dol_escape_htmltag($admin ? $langs->trans(
'InfoAdmin') : $langs->trans(
'Note')).
'"></span> '.$text.($nodiv ?
'' :
'</div>');
5139 if ($textfordropdown) {
5140 $tmpresult =
'<span class="'.$class.
'text opacitymedium cursorpointer">'.$langs->trans($textfordropdown).
' '.
img_picto($langs->trans($textfordropdown),
'1downarrow').
'</span>';
5141 $tmpresult .=
'<script nonce="'.getNonce().
'" type="text/javascript">
5142 jQuery(document).ready(function() {
5143 jQuery(".'.$class.
'text").click(function() {
5144 console.log("toggle text");
5145 jQuery(".'.$class.
'").toggle();
5150 $result = $tmpresult.$result;
5171 global $conf, $langs, $argv;
5172 global $dolibarr_main_prod;
5179 require_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
5181 $langs->load(
"main");
5185 $langs->loadLangs(array(
'main',
'errors'));
5187 if ($_SERVER[
'DOCUMENT_ROOT']) {
5188 $out .= $langs->trans(
"DolibarrHasDetectedError").
".<br>\n";
5190 $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";
5192 $out .= $langs->trans(
"InformationToHelpDiagnose").
":<br>\n";
5194 $out .=
"<b>".$langs->trans(
"Date").
":</b> ".
dol_print_date(time(),
'dayhourlog').
"<br>\n";
5195 $out .=
"<b>".$langs->trans(
"Dolibarr").
":</b> ".DOL_VERSION.
" - https://www.dolibarr.org<br>\n";
5196 if (isset($conf->global->MAIN_FEATURES_LEVEL)) {
5197 $out .=
"<b>".$langs->trans(
"LevelOfFeature").
":</b> ".
getDolGlobalInt(
'MAIN_FEATURES_LEVEL').
"<br>\n";
5199 if (function_exists(
"phpversion")) {
5200 $out .=
"<b>".$langs->trans(
"PHP").
":</b> ".phpversion().
"<br>\n";
5202 $out .=
"<b>".$langs->trans(
"Server").
":</b> ".(isset($_SERVER[
"SERVER_SOFTWARE"]) ?
dol_htmlentities($_SERVER[
"SERVER_SOFTWARE"], ENT_COMPAT) :
'').
"<br>\n";
5203 if (function_exists(
"php_uname")) {
5204 $out .=
"<b>".$langs->trans(
"OS").
":</b> ".php_uname().
"<br>\n";
5206 $out .=
"<b>".$langs->trans(
"UserAgent").
":</b> ".(isset($_SERVER[
"HTTP_USER_AGENT"]) ?
dol_htmlentities($_SERVER[
"HTTP_USER_AGENT"], ENT_COMPAT) :
'').
"<br>\n";
5208 $out .=
"<b>".$langs->trans(
"RequestedUrl").
":</b> ".
dol_htmlentities($_SERVER[
"REQUEST_URI"], ENT_COMPAT).
"<br>\n";
5209 $out .=
"<b>".$langs->trans(
"Referer").
":</b> ".(isset($_SERVER[
"HTTP_REFERER"]) ?
dol_htmlentities($_SERVER[
"HTTP_REFERER"], ENT_COMPAT) :
'').
"<br>\n";
5210 $out .=
"<b>".$langs->trans(
"MenuManager").
":</b> ".(isset($conf->standard_menu) ?
dol_htmlentities($conf->standard_menu, ENT_COMPAT) :
'').
"<br>\n";
5212 $syslog .=
"url=".dol_escape_htmltag($_SERVER[
"REQUEST_URI"]);
5213 $syslog .=
", query_string=".dol_escape_htmltag($_SERVER[
"QUERY_STRING"]);
5215 $out .=
'> '.$langs->transnoentities(
"ErrorInternalErrorDetected").
":\n".$argv[0].
"\n";
5216 $syslog .=
"pid=".dol_getmypid();
5219 if (!empty($conf->modules)) {
5220 $out .=
"<b>".$langs->trans(
"Modules").
":</b> ".join(
', ', $conf->modules).
"<br>\n";
5223 if (is_object($db)) {
5224 if ($_SERVER[
'DOCUMENT_ROOT']) {
5225 $out .=
"<b>".$langs->trans(
"DatabaseTypeManager").
":</b> ".$db->type.
"<br>\n";
5226 $lastqueryerror = $db->lastqueryerror();
5228 $lastqueryerror =
"SQL error string is not a valid UTF8 string. We can't show it.";
5230 $out .=
"<b>".$langs->trans(
"RequestLastAccessInError").
":</b> ".($lastqueryerror ?
dol_escape_htmltag($lastqueryerror) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
5231 $out .=
"<b>".$langs->trans(
"ReturnCodeLastAccessInError").
":</b> ".($db->lasterrno() ?
dol_escape_htmltag($db->lasterrno()) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
5232 $out .=
"<b>".$langs->trans(
"InformationLastAccessInError").
":</b> ".($db->lasterror() ?
dol_escape_htmltag($db->lasterror()) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
5236 $out .=
'> '.$langs->transnoentities(
"DatabaseTypeManager").
":\n".$db->type.
"\n";
5237 $out .=
'> '.$langs->transnoentities(
"RequestLastAccessInError").
":\n".($db->lastqueryerror() ? $db->lastqueryerror() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
5238 $out .=
'> '.$langs->transnoentities(
"ReturnCodeLastAccessInError").
":\n".($db->lasterrno() ? $db->lasterrno() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
5239 $out .=
'> '.$langs->transnoentities(
"InformationLastAccessInError").
":\n".($db->lasterror() ? $db->lasterror() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
5241 $syslog .=
", sql=".$db->lastquery();
5242 $syslog .=
", db_error=".$db->lasterror();
5245 if ($error || $errors) {
5246 $langs->load(
"errors");
5249 if (is_array($error) && is_array($errors)) {
5250 $errors = array_merge($error, $errors);
5251 } elseif (is_array($error)) {
5253 } elseif (is_array($errors)) {
5254 $errors = array_merge(array($error), $errors);
5256 $errors = array_merge(array($error), array($errors));
5259 foreach ($errors as $msg) {
5263 if ($_SERVER[
'DOCUMENT_ROOT']) {
5267 $out .=
'> '.$langs->transnoentities(
"Message").
":\n".$msg.
"\n";
5269 $syslog .=
", msg=".$msg;
5272 if (empty($dolibarr_main_prod) && $_SERVER[
'DOCUMENT_ROOT'] && function_exists(
'xdebug_print_function_stack') && function_exists(
'xdebug_call_file')) {
5273 xdebug_print_function_stack();
5274 $out .=
'<b>XDebug informations:</b>'.
"<br>\n";
5275 $out .=
'File: '.xdebug_call_file().
"<br>\n";
5276 $out .=
'Line: '.xdebug_call_line().
"<br>\n";
5277 $out .=
'Function: '.xdebug_call_function().
"<br>\n";
5282 if (!headers_sent()) {
5283 if (function_exists(
'top_httphead')) {
5287 http_response_code(202);
5290 if (empty($dolibarr_main_prod)) {
5293 if (empty($langs->defaultlang)) {
5294 $langs->setDefaultLang();
5296 $langs->loadLangs(array(
"main",
"errors"));
5298 print
'This website or feature is currently temporarly 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";
5299 print $langs->trans(
"DolibarrHasDetectedError").
'. ';
5300 print $langs->trans(
"YouCanSetOptionDolibarrMainProdToZero");
5301 if (!defined(
"MAIN_CORE_ERROR")) {
5302 define(
"MAIN_CORE_ERROR", 1);
5319function dol_print_error_email($prefixcode, $errormessage =
'', $errormessages = array(), $morecss =
'error', $email =
'')
5321 global $langs, $conf;
5323 if (empty($email)) {
5324 $email = $conf->global->MAIN_INFO_SOCIETE_MAIL;
5327 $langs->load(
"errors");
5330 print
'<br><div class="center login_main_message"><div class="'.$morecss.
'">';
5331 print $langs->trans(
"ErrorContactEMail", $email, $prefixcode.
'-'.
dol_print_date($now,
'%Y%m%d%H%M%S'));
5332 if ($errormessage) {
5333 print
'<br><br>'.$errormessage;
5335 if (is_array($errormessages) && count($errormessages)) {
5336 foreach ($errormessages as $mesgtoshow) {
5337 print
'<br><br>'.$mesgtoshow;
5340 print
'</div></div>';
5359function print_liste_field_titre($name, $file =
"", $field =
"", $begin =
"", $moreparam =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $tooltip =
"", $forcenowrapcolumntitle = 0)
5361 print
getTitleFieldOfList($name, 0, $file, $field, $begin, $moreparam, $moreattrib, $sortfield, $sortorder, $prefix, 0, $tooltip, $forcenowrapcolumntitle);
5382function getTitleFieldOfList($name, $thead = 0, $file =
"", $field =
"", $begin =
"", $moreparam =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $disablesortlink = 0, $tooltip =
'', $forcenowrapcolumntitle = 0)
5384 global $conf, $langs, $form;
5387 if ($moreattrib ==
'class="right"') {
5388 $prefix .=
'right ';
5391 $sortorder = strtoupper($sortorder);
5400 $tmpsortfield = explode(
',', $sortfield);
5401 $sortfield1 = trim($tmpsortfield[0]);
5402 $tmpfield = explode(
',', $field);
5403 $field1 = trim($tmpfield[0]);
5405 if (empty($conf->global->MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE) && empty($forcenowrapcolumntitle)) {
5406 $prefix =
'wrapcolumntitle '.$prefix;
5412 $liste_titre =
'liste_titre';
5413 if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace(
"/^[^\.]+\./",
"", $field1))) {
5414 $liste_titre =
'liste_titre_sel';
5417 $tagstart =
'<'.$tag.
' class="'.$prefix.$liste_titre.
'" '.$moreattrib;
5419 $tagstart .= ($name && empty($conf->global->MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE) && empty($forcenowrapcolumntitle) && !
dol_textishtml($name)) ?
' title="'.
dol_escape_htmltag($langs->trans($name)).
'"' :
'';
5422 if (empty($thead) && $field && empty($disablesortlink)) {
5423 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
5424 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
5425 $options = preg_replace(
'/&+/i',
'&', $options);
5426 if (!preg_match(
'/^&/', $options)) {
5427 $options =
'&'.$options;
5430 $sortordertouseinlink =
'';
5431 if ($field1 != $sortfield1) {
5432 if (preg_match(
'/^DESC/i', $sortorder)) {
5433 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
5435 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
5438 if (preg_match(
'/^ASC/i', $sortorder)) {
5439 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
5441 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
5444 $sortordertouseinlink = preg_replace(
'/,$/',
'', $sortordertouseinlink);
5445 $out .=
'<a class="reposition" href="'.$file.
'?sortfield='.$field.
'&sortorder='.$sortordertouseinlink.
'&begin='.$begin.$options.
'"';
5451 if (preg_match(
'/:\w+$/', $tooltip)) {
5452 $tmptooltip = explode(
':', $tooltip);
5454 $tmptooltip = array($tooltip);
5456 $out .= $form->textwithpicto($langs->trans($name), $langs->trans($tmptooltip[0]), 1,
'help',
'', 0, 3, (empty($tmptooltip[1]) ?
'' :
'extra_'.str_replace(
'.',
'_', $field).
'_'.$tmptooltip[1]));
5458 $out .= $langs->trans($name);
5461 if (empty($thead) && $field && empty($disablesortlink)) {
5465 if (empty($thead) && $field) {
5466 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
5467 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
5468 $options = preg_replace(
'/&+/i',
'&', $options);
5469 if (!preg_match(
'/^&/', $options)) {
5470 $options =
'&'.$options;
5473 if (!$sortorder || ($field1 != $sortfield1)) {
5477 if (preg_match(
'/^DESC/', $sortorder)) {
5480 $sortimg .=
'<span class="nowrap">'.img_up(
"Z-A", 0,
'paddingright').
'</span>';
5482 if (preg_match(
'/^ASC/', $sortorder)) {
5485 $sortimg .=
'<span class="nowrap">'.img_down(
"A-Z", 0,
'paddingright').
'</span>';
5490 $tagend =
'</'.$tag.
'>';
5492 $out = $tagstart.$sortimg.$out.$tagend;
5507 dol_syslog(__FUNCTION__.
" is deprecated", LOG_WARNING);
5509 print
'<div class="titre">'.$title.
'</div>';
5541function load_fiche_titre($titre, $morehtmlright =
'', $picto =
'generic', $pictoisfullpath = 0, $id =
'', $morecssontable =
'', $morehtmlcenter =
'')
5547 if ($picto ==
'setup') {
5552 $return .=
'<table '.($id ?
'id="'.$id.
'" ' :
'').
'class="centpercent notopnoleftnoright table-fiche-title'.($morecssontable ?
' '.$morecssontable :
'').
'">';
5553 $return .=
'<tr class="titre">';
5555 $return .=
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">'.img_picto(
'', $picto,
'class="valignmiddle widthpictotitle pictotitle"', $pictoisfullpath).
'</td>';
5557 $return .=
'<td class="nobordernopadding valignmiddle col-title">';
5558 $return .=
'<div class="titre inline-block">'.$titre.
'</div>';
5561 $return .=
'<td class="nobordernopadding center valignmiddle col-center">'.$morehtmlcenter.
'</td>';
5564 $return .=
'<td class="nobordernopadding titre_right wordbreakimp right valignmiddle col-right">'.$morehtmlright.
'</td>';
5566 $return .=
'</tr></table>'.
"\n";
5594function print_barre_liste($titre, $page, $file, $options =
'', $sortfield =
'', $sortorder =
'', $morehtmlcenter =
'', $num = -1, $totalnboflines =
'', $picto =
'generic', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limit = -1, $hideselectlimit = 0, $hidenavigation = 0, $pagenavastextinput = 0, $morehtmlrightbeforearrow =
'')
5596 global $conf, $langs;
5599 $savtotalnboflines = $totalnboflines;
5600 $totalnboflines = abs((
int) $totalnboflines);
5602 $page = (int) $page;
5604 if ($picto ==
'setup') {
5605 $picto =
'title_setup.png';
5607 if (($conf->browser->name ==
'ie') && $picto ==
'generic') {
5608 $picto =
'title.gif';
5611 $limit = $conf->liste_limit;
5614 if ($savlimit != 0 && (($num > $limit) || ($num == -1) || ($limit == 0))) {
5622 print
"<!-- Begin title -->\n";
5623 print
'<table class="centpercent notopnoleftnoright table-fiche-title'.($morecss ?
' '.$morecss :
'').
'"><tr>';
5627 if ($picto && $titre) {
5628 print
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">'.img_picto(
'', $picto,
'class="valignmiddle pictotitle widthpictotitle"', $pictoisfullpath).
'</td>';
5631 print
'<td class="nobordernopadding valignmiddle col-title">';
5632 print
'<div class="titre inline-block">'.$titre;
5633 if (!empty($titre) && $savtotalnboflines >= 0 && (
string) $savtotalnboflines !=
'') {
5634 print
'<span class="opacitymedium colorblack paddingleft">('.$totalnboflines.
')</span>';
5636 print
'</div></td>';
5639 if ($morehtmlcenter && empty($conf->dol_optimize_smallscreen)) {
5640 print
'<td class="nobordernopadding center valignmiddle col-center">'.$morehtmlcenter.
'</td>';
5644 print
'<td class="nobordernopadding valignmiddle right col-right">';
5645 print
'<input type="hidden" name="pageplusoneold" value="'.((int) $page + 1).
'">';
5647 $options .=
"&sortfield=".urlencode($sortfield);
5650 $options .=
"&sortorder=".urlencode($sortorder);
5654 if ($savlimit != 0 && ($page > 0 || $num > $limit)) {
5655 if ($totalnboflines) {
5657 $maxnbofpage = (empty($conf->dol_optimize_smallscreen) ? 4 : 0);
5660 $nbpages = ceil($totalnboflines / $limit);
5664 $cpt = ($page - $maxnbofpage);
5670 if (empty($pagenavastextinput)) {
5671 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page=0'.$options.
'">1</a></li>';
5673 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
5674 } elseif ($cpt == 2) {
5675 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page=1'.$options.
'">2</a></li>';
5681 if ($pagenavastextinput) {
5682 if ($cpt == $page) {
5683 $pagelist .=
'<li class="pagination"><input type="text" class="'.($totalnboflines > 100 ?
'width40' :
'width25').
' center pageplusone" name="pageplusone" value="'.($page + 1).
'"></li>';
5687 if ($cpt == $page) {
5688 $pagelist .=
'<li class="pagination"><span class="active">'.($page + 1).
'</span></li>';
5690 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page='.$cpt.$options.
'">'.($cpt + 1).
'</a></li>';
5694 }
while ($cpt < $nbpages && $cpt <= ($page + $maxnbofpage));
5696 if (empty($pagenavastextinput)) {
5697 if ($cpt < $nbpages) {
5698 if ($cpt < $nbpages - 2) {
5699 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
5700 } elseif ($cpt == $nbpages - 2) {
5701 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page='.($nbpages - 2).$options.
'">'.($nbpages - 1).
'</a></li>';
5703 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page='.($nbpages - 1).$options.
'">'.$nbpages.
'</a></li>';
5707 $pagelist .=
'<li class="pagination paginationlastpage"><a href="'.$file.
'?page='.($nbpages - 1).$options.
'">'.$nbpages.
'</a></li>';
5710 $pagelist .=
'<li class="pagination"><span class="active">'.($page + 1).
"</li>";
5714 if ($savlimit || $morehtmlright || $morehtmlrightbeforearrow) {
5715 print_fleche_navigation($page, $file, $options, $nextpage, $pagelist, $morehtmlright, $savlimit, $totalnboflines, $hideselectlimit, $morehtmlrightbeforearrow, $hidenavigation);
5719 if ($pagenavastextinput) {
5726 print
'</table>'.
"\n";
5729 if ($morehtmlcenter && !empty($conf->dol_optimize_smallscreen)) {
5730 print
'<div class="nobordernopadding marginbottomonly center valignmiddle col-center centpercent">'.$morehtmlcenter.
'</div>';
5733 print
"<!-- End title -->\n\n";
5752function print_fleche_navigation($page, $file, $options =
'', $nextpage = 0, $betweenarrows =
'', $afterarrows =
'', $limit = -1, $totalnboflines = 0, $hideselectlimit = 0, $beforearrows =
'', $hidenavigation = 0)
5754 global $conf, $langs;
5756 print
'<div class="pagination"><ul>';
5757 if ($beforearrows) {
5758 print
'<li class="paginationbeforearrows">';
5759 print $beforearrows;
5763 if (empty($hidenavigation)) {
5764 if ((
int) $limit > 0 && empty($hideselectlimit)) {
5765 $pagesizechoices =
'10:10,15:15,20:20,30:30,40:40,50:50,100:100,250:250,500:500,1000:1000';
5766 $pagesizechoices .=
',5000:5000,10000:10000,20000:20000';
5769 if (!empty($conf->global->MAIN_PAGESIZE_CHOICES)) {
5770 $pagesizechoices = $conf->global->MAIN_PAGESIZE_CHOICES;
5773 print
'<li class="pagination">';
5774 print
'<select class="flat selectlimit" name="limit" title="'.dol_escape_htmltag($langs->trans(
"MaxNbOfRecordPerPage")).
'">';
5775 $tmpchoice = explode(
',', $pagesizechoices);
5776 $tmpkey = $limit.
':'.$limit;
5777 if (!in_array($tmpkey, $tmpchoice)) {
5778 $tmpchoice[] = $tmpkey;
5780 $tmpkey = $conf->liste_limit.
':'.$conf->liste_limit;
5781 if (!in_array($tmpkey, $tmpchoice)) {
5782 $tmpchoice[] = $tmpkey;
5784 asort($tmpchoice, SORT_NUMERIC);
5785 foreach ($tmpchoice as $val) {
5787 $tmp = explode(
':', $val);
5790 if ($key !=
'' && $val !=
'') {
5791 if ((
int) $key == (
int) $limit) {
5792 $selected =
' selected="selected"';
5794 print
'<option name="'.$key.
'"'.$selected.
'>'.
dol_escape_htmltag($val).
'</option>'.
"\n";
5798 if ($conf->use_javascript_ajax) {
5799 print
'<!-- JS CODE TO ENABLE select limit to launch submit of page -->
5801 jQuery(document).ready(function () {
5802 jQuery(".selectlimit").change(function() {
5803 console.log("Change limit. Send submit");
5804 $(this).parents(\'form:first\').submit();
5813 print
'<li class="pagination paginationpage paginationpageleft"><a class="paginationprevious" href="'.$file.
'?page='.($page - 1).$options.
'"><i class="fa fa-chevron-left" title="'.
dol_escape_htmltag($langs->trans(
"Previous")).
'"></i></a></li>';
5815 if ($betweenarrows) {
5816 print
'<!--<div class="betweenarrows nowraponall inline-block">-->';
5817 print $betweenarrows;
5818 print
'<!--</div>-->';
5820 if ($nextpage > 0) {
5821 print
'<li class="pagination paginationpage paginationpageright"><a class="paginationnext" href="'.$file.
'?page='.($page + 1).$options.
'"><i class="fa fa-chevron-right" title="'.
dol_escape_htmltag($langs->trans(
"Next")).
'"></i></a></li>';
5824 print
'<li class="paginationafterarrows">';
5829 print
'</ul></div>'.
"\n";
5844function vatrate($rate, $addpercent =
false, $info_bits = 0, $usestarfornpr = 0, $html = 0)
5848 if (preg_match(
'/%/', $rate)) {
5849 $rate = str_replace(
'%',
'', $rate);
5853 if (preg_match(
'/\((.*)\)/', $rate, $reg)) {
5854 $morelabel =
' ('.$reg[1].
')';
5855 $rate = preg_replace(
'/\s*'.preg_quote($morelabel,
'/').
'/',
'', $rate);
5856 $morelabel =
' '.($html ?
'<span class="opacitymedium">' :
'').
'('.$reg[1].
')'.($html ?
'</span>' :
'');
5858 if (preg_match(
'/\*/', $rate)) {
5859 $rate = str_replace(
'*',
'', $rate);
5864 if (!preg_match(
'/\//', $rate)) {
5865 $ret =
price($rate, 0,
'', 0, 0).($addpercent ?
'%' :
'');
5868 $ret = $rate.($addpercent ?
'%' :
'');
5870 if (($info_bits & 1) && $usestarfornpr >= 0) {
5893function price($amount, $form = 0, $outlangs =
'', $trunc = 1, $rounding = -1, $forcerounding = -1, $currency_code =
'')
5895 global $langs, $conf;
5898 if (empty($amount)) {
5901 $amount = (is_numeric($amount) ? $amount : 0);
5902 if ($rounding == -1) {
5903 $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
5905 $nbdecimal = $rounding;
5907 if ($outlangs ===
'none') {
5917 if (!is_object($outlangs)) {
5921 if ($outlangs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
5922 $dec = $outlangs->transnoentitiesnoconv(
"SeparatorDecimal");
5924 if ($outlangs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
5925 $thousand = $outlangs->transnoentitiesnoconv(
"SeparatorThousand");
5927 if ($thousand ==
'None') {
5929 } elseif ($thousand ==
'Space') {
5936 $amount = str_replace(
',',
'.', $amount);
5938 $datas = explode(
'.', $amount);
5939 $decpart = isset($datas[1]) ? $datas[1] :
'';
5940 $decpart = preg_replace(
'/0+$/i',
'', $decpart);
5949 $max_nbdecimal = (int) str_replace(
'...',
'',
getDolGlobalString(
'MAIN_MAX_DECIMALS_SHOWN'));
5950 if ($trunc && $nbdecimal > $max_nbdecimal) {
5951 $nbdecimal = $max_nbdecimal;
5959 if ((
string) $forcerounding !=
'-1') {
5960 if ($forcerounding ===
'MU') {
5961 $nbdecimal = $conf->global->MAIN_MAX_DECIMALS_UNIT;
5962 } elseif ($forcerounding ===
'MT') {
5963 $nbdecimal = $conf->global->MAIN_MAX_DECIMALS_TOT;
5964 } elseif ($forcerounding >= 0) {
5965 $nbdecimal = $forcerounding;
5970 $output = number_format($amount, $nbdecimal, $dec, $thousand);
5972 $output = preg_replace(
'/\s/',
' ', $output);
5973 $output = preg_replace(
'/\'/',
''', $output);
5976 $cursymbolbefore = $cursymbolafter =
'';
5977 if ($currency_code && is_object($outlangs)) {
5978 if ($currency_code ==
'auto') {
5979 $currency_code = $conf->currency;
5982 $listofcurrenciesbefore = array(
'AUD',
'CAD',
'CNY',
'COP',
'CLP',
'GBP',
'HKD',
'MXN',
'PEN',
'USD',
'CRC');
5983 $listoflanguagesbefore = array(
'nl_NL');
5984 if (in_array($currency_code, $listofcurrenciesbefore) || in_array($outlangs->defaultlang, $listoflanguagesbefore)) {
5985 $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
5987 $tmpcur = $outlangs->getCurrencySymbol($currency_code);
5988 $cursymbolafter .= ($tmpcur == $currency_code ?
' '.$tmpcur : $tmpcur);
5991 $output = $cursymbolbefore.$output.$end.($cursymbolafter ?
' ' :
'').$cursymbolafter;
6022 global $langs, $conf;
6025 if (is_null($amount)) {
6034 if (is_null($langs)) {
6038 if ($langs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
6039 $dec = $langs->transnoentitiesnoconv(
"SeparatorDecimal");
6041 if ($langs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
6042 $thousand = $langs->transnoentitiesnoconv(
"SeparatorThousand");
6045 if ($thousand ==
'None') {
6047 } elseif ($thousand ==
'Space') {
6055 if (!is_numeric($amount)) {
6056 $amount = preg_replace(
'/[a-zA-Z\/\\\*\(\)<>\_]/',
'', $amount);
6059 if ($option == 2 && $thousand ==
'.' && preg_match(
'/\.(\d\d\d)$/', (
string) $amount)) {
6060 $amount = str_replace($thousand,
'', $amount);
6066 if (is_numeric($amount)) {
6068 $temps = sprintf(
"%0.10F", $amount - intval($amount));
6069 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
6071 $amount = number_format($amount, $nbofdec, $dec, $thousand);
6076 if ($thousand !=
',' && $thousand !=
'.') {
6077 $amount = str_replace(
',',
'.', $amount);
6080 $amount = str_replace(
' ',
'', $amount);
6081 $amount = str_replace($thousand,
'', $amount);
6082 $amount = str_replace($dec,
'.', $amount);
6084 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
6090 $nbofdectoround =
'';
6091 if ($rounding ==
'MU') {
6092 $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_UNIT;
6093 } elseif ($rounding ==
'MT') {
6094 $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_TOT;
6095 } elseif ($rounding ==
'MS') {
6096 $nbofdectoround = isset($conf->global->MAIN_MAX_DECIMALS_STOCK) ? $conf->global->MAIN_MAX_DECIMALS_STOCK : 5;
6097 } elseif ($rounding ==
'CU') {
6098 $nbofdectoround = max($conf->global->MAIN_MAX_DECIMALS_UNIT, 8);
6099 } elseif ($rounding ==
'CT') {
6100 $nbofdectoround = max($conf->global->MAIN_MAX_DECIMALS_TOT, 8);
6101 } elseif (is_numeric($rounding)) {
6102 $nbofdectoround = (int) $rounding;
6107 $amount = round(is_string($amount) ? (
float) $amount : $amount, $nbofdectoround);
6109 return 'ErrorBadParameterProvidedToFunction';
6115 if (is_numeric($amount)) {
6117 $temps = sprintf(
"%0.10F", $amount - intval($amount));
6118 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
6120 $amount = number_format($amount, min($nbofdec, $nbofdectoround), $dec, $thousand);
6126 if ($thousand !=
',' && $thousand !=
'.') {
6127 $amount = str_replace(
',',
'.', $amount);
6130 $amount = str_replace(
' ',
'', $amount);
6131 $amount = str_replace($thousand,
'', $amount);
6132 $amount = str_replace($dec,
'.', $amount);
6134 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
6152function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round = -1, $forceunitoutput =
'no', $use_short_label = 0)
6154 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
6156 if (($forceunitoutput ==
'no' && $dimension < 1 / 10000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -6)) {
6157 $dimension = $dimension * 1000000;
6159 } elseif (($forceunitoutput ==
'no' && $dimension < 1 / 10 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -3)) {
6160 $dimension = $dimension * 1000;
6162 } elseif (($forceunitoutput ==
'no' && $dimension > 100000000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 6)) {
6163 $dimension = $dimension / 1000000;
6165 } elseif (($forceunitoutput ==
'no' && $dimension > 100000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 3)) {
6166 $dimension = $dimension / 1000;
6182 $ret =
price($dimension, 0, $outputlangs, 0, 0, $round);
6183 $ret .=
' '.measuringUnitString(0, $type, $unit, $use_short_label, $outputlangs);
6201function get_localtax($vatrate, $local, $thirdparty_buyer =
"", $thirdparty_seller =
"", $vatnpr = 0)
6203 global $db, $conf, $mysoc;
6205 if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) {
6206 $thirdparty_seller = $mysoc;
6209 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);
6211 $vatratecleaned = $vatrate;
6213 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
6214 $vatratecleaned = trim($reg[1]);
6215 $vatratecode = $reg[2];
6224 if ($mysoc->country_code ==
'ES') {
6226 if (!$mysoc->localtax1_assuj || (
string) $vatratecleaned ==
"0") {
6229 if ($thirdparty_seller->id == $mysoc->id) {
6230 if (!$thirdparty_buyer->localtax1_assuj) {
6234 if (!$thirdparty_seller->localtax1_assuj) {
6242 if (!$mysoc->localtax2_assuj) {
6245 if ($thirdparty_seller->id == $mysoc->id) {
6246 if (!$thirdparty_buyer->localtax2_assuj) {
6250 if (!$thirdparty_seller->localtax2_assuj) {
6256 if ($local == 1 && !$thirdparty_seller->localtax1_assuj) {
6259 if ($local == 2 && !$thirdparty_seller->localtax2_assuj) {
6265 if (in_array($mysoc->country_code, array(
'ES'))) {
6266 $conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY = 1;
6270 if (!empty($conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY)) {
6272 if ($thirdparty_seller != $mysoc) {
6274 return $thirdparty_seller->localtax1_value;
6278 return $conf->global->MAIN_INFO_VALUE_LOCALTAX1;
6283 if ($thirdparty_seller != $mysoc) {
6286 return $thirdparty_seller->localtax2_value;
6289 if (in_array($mysoc->country_code, array(
'ES'))) {
6290 return $thirdparty_buyer->localtax2_value;
6292 return $conf->global->MAIN_INFO_VALUE_LOCALTAX2;
6299 $sql =
"SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
6300 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
6301 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($thirdparty_seller->country_code).
"'";
6302 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
6303 if (!empty($vatratecode)) {
6304 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
6306 $sql .=
" AND t.recuperableonly = '".$db->escape($vatnpr).
"'";
6309 $resql = $db->query($sql);
6312 $obj = $db->fetch_object($resql);
6315 return $obj->localtax1;
6316 } elseif ($local == 2) {
6317 return $obj->localtax2;
6338 $valors = explode(
":", $tax);
6340 if (count($valors) > 1) {
6357 $sql =
" SELECT t.localtax".$local.
" as localtax";
6358 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t INNER JOIN ".MAIN_DB_PREFIX.
"c_country as c ON c.rowid = t.fk_pays";
6359 $sql .=
" WHERE c.code = '".$db->escape($mysoc->country_code).
"' AND t.active = 1 AND t.taux = (";
6360 $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";
6361 $sql .=
" WHERE c.code = '".$db->escape($mysoc->country_code).
"' AND tt.active = 1)";
6362 $sql .=
" AND t.localtax".$local.
"_type <> '0'";
6363 $sql .=
" ORDER BY t.rowid DESC";
6365 $resql = $db->query($sql);
6367 $obj = $db->fetch_object($resql);
6369 return $obj->localtax;
6394 dol_syslog(
"getTaxesFromId vat id or rate = ".$vatrate);
6397 $sql =
"SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy,";
6398 $sql .=
" t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type";
6399 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t";
6400 if ($firstparamisid) {
6401 $sql .=
" WHERE t.rowid = ".(int) $vatrate;
6403 $vatratecleaned = $vatrate;
6406 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
6407 $vatratecleaned = $reg[1];
6408 $vatratecode = $reg[2];
6411 $sql .=
", ".MAIN_DB_PREFIX.
"c_country as c";
6414 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($seller->country_code).
"'";
6415 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
6417 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
6421 $resql = $db->query($sql);
6423 $obj = $db->fetch_object($resql);
6426 'rowid'=>$obj->rowid,
6429 'localtax1'=>$obj->localtax1,
6430 'localtax1_type'=>$obj->localtax1_type,
6431 'localtax2'=>$obj->localtax2,
6432 'localtax2_type'=>$obj->localtax2_type,
6434 'accountancy_code_sell'=>$obj->accountancy_code_sell,
6435 'accountancy_code_buy'=>$obj->accountancy_code_buy
6467 dol_syslog(
"getLocalTaxesFromRate vatrate=".$vatrate.
" local=".$local);
6470 $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";
6471 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t";
6472 if ($firstparamisid) {
6473 $sql .=
" WHERE t.rowid = ".(int) $vatrate;
6475 $vatratecleaned = $vatrate;
6478 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
6479 $vatratecleaned = $reg[1];
6480 $vatratecode = $reg[2];
6483 $sql .=
", ".MAIN_DB_PREFIX.
"c_country as c";
6484 if (!empty($mysoc) && $mysoc->country_code ==
'ES') {
6485 $countrycodetouse = ((empty($buyer) || empty($buyer->country_code)) ? $mysoc->country_code : $buyer->country_code);
6486 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($countrycodetouse).
"'";
6488 $countrycodetouse = ((empty($seller) || empty($seller->country_code)) ? $mysoc->country_code : $seller->country_code);
6489 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($countrycodetouse).
"'";
6491 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
6493 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
6497 $resql = $db->query($sql);
6499 $obj = $db->fetch_object($resql);
6502 $vateratestring = $obj->rate.($obj->code ?
' ('.$obj->code.
')' :
'');
6505 return array($obj->localtax1_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
6506 } elseif ($local == 2) {
6507 return array($obj->localtax2_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
6509 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);
6529 global $db, $conf, $mysoc;
6531 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
6539 $product->fetch($idprod);
6541 if ($mysoc->country_code == $thirdpartytouse->country_code) {
6543 if ($idprodfournprice > 0) {
6544 $result = $product->get_buyprice($idprodfournprice, 0, 0, 0);
6546 $ret = $product->vatrate_supplier;
6547 if ($product->default_vat_code_supplier) {
6548 $ret .=
' ('.$product->default_vat_code_supplier.
')';
6554 $ret = $product->tva_tx;
6555 if ($product->default_vat_code) {
6556 $ret .=
' ('.$product->default_vat_code.
')';
6567 if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS)) {
6569 $sql =
"SELECT t.taux as vat_rate, t.code as default_vat_code";
6570 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
6571 $sql .=
" WHERE t.active = 1 AND t.fk_pays = c.rowid AND c.code = '".$db->escape($thirdpartytouse->country_code).
"'";
6572 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
6573 $sql .= $db->plimit(1);
6575 $resql = $db->query($sql);
6577 $obj = $db->fetch_object($resql);
6579 $ret = $obj->vat_rate;
6580 if ($obj->default_vat_code) {
6581 $ret .=
' ('.$obj->default_vat_code.
')';
6593 if ($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS !=
'none') {
6594 $defaulttx = $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;
6605 dol_syslog(
"get_product_vat_for_country: ret=".$ret);
6622 if (!class_exists(
'Product')) {
6623 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
6632 $result = $product->fetch($idprod);
6634 if ($mysoc->country_code == $thirdpartytouse->country_code) {
6648 $sql =
"SELECT taux as vat_rate, localtax1, localtax2";
6649 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
6650 $sql .=
" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$db->escape($thirdpartytouse->country_code).
"'";
6651 $sql .=
" ORDER BY t.taux DESC, t.recuperableonly ASC";
6652 $sql .= $db->plimit(1);
6654 $resql = $db->query($sql);
6656 $obj = $db->fetch_object($resql);
6659 $ret = $obj->localtax1;
6660 } elseif ($local == 2) {
6661 $ret = $obj->localtax2;
6669 dol_syslog(
"get_product_localtax_for_country: ret=".$ret);
6693 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
6696 $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;
6698 $seller_country_code = $thirdparty_seller->country_code;
6699 $seller_in_cee =
isInEEC($thirdparty_seller);
6701 $buyer_country_code = $thirdparty_buyer->country_code;
6702 $buyer_in_cee =
isInEEC($thirdparty_buyer);
6704 dol_syslog(
"get_default_tva: seller use vat=".$seller_use_vat.
", seller country=".$seller_country_code.
", seller in cee=".$seller_in_cee.
", buyer vat number=".$thirdparty_buyer->tva_intra.
" buyer country=".$buyer_country_code.
", buyer in cee=".$buyer_in_cee.
", idprod=".$idprod.
", idprodfournprice=".$idprodfournprice.
", SERVICE_ARE_ECOMMERCE_200238EC=".(!empty($conf->global->SERVICES_ARE_ECOMMERCE_200238EC) ? $conf->global->SERVICES_ARE_ECOMMERCE_200238EC :
''));
6708 if (!empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC)) {
6709 if ($seller_in_cee && $buyer_in_cee) {
6710 $isacompany = $thirdparty_buyer->
isACompany();
6711 if ($isacompany &&
getDolGlobalString(
'MAIN_USE_VAT_COMPANIES_IN_EEC_WITH_INVALID_VAT_ID_ARE_INDIVIDUAL')) {
6712 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
6726 if (!$seller_use_vat) {
6732 if (($seller_country_code == $buyer_country_code)
6733 || (in_array($seller_country_code, array(
'FR',
'MC')) && in_array($buyer_country_code, array(
'FR',
'MC')))) {
6737 if ($seller_country_code ==
'IN' &&
getDolGlobalString(
'MAIN_SALETAX_AUTOSWITCH_I_CS_FOR_INDIA')) {
6741 if (preg_match(
'/C+S-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id != $thirdparty_buyer->state_id) {
6743 $tmpvat = str_replace(
"C+S",
"I", $tmpvat);
6744 } elseif (preg_match(
'/I-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id == $thirdparty_buyer->state_id) {
6746 $tmpvat = str_replace(
"I",
"C+S", $tmpvat);
6758 if (($seller_in_cee && $buyer_in_cee)) {
6759 $isacompany = $thirdparty_buyer->
isACompany();
6760 if ($isacompany &&
getDolGlobalString(
'MAIN_USE_VAT_COMPANIES_IN_EEC_WITH_INVALID_VAT_ID_ARE_INDIVIDUAL')) {
6761 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
6778 if (!empty($conf->global->MAIN_USE_VAT_OF_PRODUCT_FOR_INDIVIDUAL_CUSTOMER_OUT_OF_EEC) && empty($buyer_in_cee)) {
6779 $isacompany = $thirdparty_buyer->
isACompany();
6807 if ($idprodfournprice > 0) {
6808 if (!class_exists(
'ProductFournisseur')) {
6809 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
6812 $prodprice->fetch_product_fournisseur_price($idprodfournprice);
6813 return $prodprice->fourn_tva_npr;
6814 } elseif ($idprod > 0) {
6815 if (!class_exists(
'Product')) {
6816 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
6819 $prod->fetch($idprod);
6820 return $prod->tva_npr;
6843 if (!is_object($thirdparty_seller)) {
6846 if (!is_object($thirdparty_buyer)) {
6851 if ($mysoc->country_code ==
'ES') {
6852 if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) {
6857 if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) {
6860 if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj ==
'localtax1off') {
6864 } elseif ($local == 2) {
6866 if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) {
6869 if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj ==
'localtax2off') {
6874 if ($thirdparty_seller->country_code == $thirdparty_buyer->country_code) {
6889function yn($yesno, $case = 1, $color = 0)
6893 $result =
'unknown';
6895 if ($yesno == 1 || (isset($yesno) && (strtolower($yesno) ==
'yes' || strtolower($yesno) ==
'true'))) {
6896 $result = $langs->trans(
'yes');
6897 if ($case == 1 || $case == 3) {
6898 $result = $langs->trans(
"Yes");
6901 $result =
'<input type="checkbox" value="1" checked disabled>';
6904 $result =
'<input type="checkbox" value="1" checked disabled> '.$result;
6908 } elseif ($yesno == 0 || strtolower($yesno) ==
'no' || strtolower($yesno) ==
'false') {
6909 $result = $langs->trans(
"no");
6910 if ($case == 1 || $case == 3) {
6911 $result = $langs->trans(
"No");
6914 $result =
'<input type="checkbox" value="0" disabled>';
6917 $result =
'<input type="checkbox" value="0" disabled> '.$result;
6923 $classname =
'error';
6927 return '<span class="'.$classname.
'">'.$result.
'</span>';
6947function get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart =
'')
6951 if (empty($modulepart) && !empty($object->module)) {
6952 $modulepart = $object->module;
6957 $arrayforoldpath = array(
'cheque',
'category',
'holiday',
'supplier_invoice',
'invoice_supplier',
'mailing',
'supplier_payment');
6959 $arrayforoldpath[] =
'product';
6961 if (!empty($level) && in_array($modulepart, $arrayforoldpath)) {
6963 if (empty($alpha)) {
6964 $num = preg_replace(
'/([^0-9])/i',
'', $num);
6966 $num = preg_replace(
'/^.*\-/i',
'', $num);
6968 $num = substr(
"000".$num, -$level);
6970 $path = substr($num, 0, 1);
6973 $path = substr($num, 1, 1).
'/'.substr($num, 0, 1);
6976 $path = substr($num, 2, 1).
'/'.substr($num, 1, 1).
'/'.substr($num, 0, 1);
6986 if (empty($withoutslash) && !empty($path)) {
7005 dol_syslog(
"functions.lib::dol_mkdir: dir=".$dir, LOG_INFO);
7008 if (@is_dir($dir_osencoded)) {
7016 if (!empty($dataroot)) {
7018 $dir = str_replace($dataroot.
'/',
'', $dir);
7019 $ccdir = $dataroot.
'/';
7022 $cdir = explode(
"/", $dir);
7023 $num = count($cdir);
7024 for ($i = 0; $i < $num; $i++) {
7026 $ccdir .=
'/'.$cdir[$i];
7028 $ccdir .= $cdir[$i];
7031 if (preg_match(
"/^.:$/", $ccdir, $regs)) {
7039 if (!@is_dir($ccdir_osencoded)) {
7040 dol_syslog(
"functions.lib::dol_mkdir: Directory '".$ccdir.
"' does not exists or is outside open_basedir PHP setting.", LOG_DEBUG);
7043 $dirmaskdec = octdec((
string) $newmask);
7044 if (empty($newmask)) {
7045 $dirmaskdec = empty($conf->global->MAIN_UMASK) ? octdec(
'0755') : octdec($conf->global->MAIN_UMASK);
7047 $dirmaskdec |= octdec(
'0111');
7048 if (!@mkdir($ccdir_osencoded, $dirmaskdec)) {
7050 dol_syslog(
"functions.lib::dol_mkdir: Fails to create directory '".$ccdir.
"' or directory already exists.", LOG_WARNING);
7053 dol_syslog(
"functions.lib::dol_mkdir: Directory '".$ccdir.
"' created", LOG_DEBUG);
7062 return ($nberr ? -$nberr : $nbcreated);
7077 if (!empty($newmask)) {
7078 @chmod($filepath, octdec($newmask));
7079 } elseif (!empty($conf->global->MAIN_UMASK)) {
7080 @chmod($filepath, octdec($conf->global->MAIN_UMASK));
7092 return '<span class="fieldrequired">*</span>';
7112function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto =
'UTF-8', $strip_tags = 0, $removedoublespaces = 1)
7114 if (is_null($stringtoclean)) {
7118 if ($removelinefeed == 2) {
7119 $stringtoclean = preg_replace(
'/<br[^>]*>(\n|\r)+/ims',
'<br>', $stringtoclean);
7121 $temp = preg_replace(
'/<br[^>]*>/i',
"\n", $stringtoclean);
7126 $temp = str_replace(
'< ',
'__ltspace__', $temp);
7129 $temp = strip_tags($temp);
7132 $pattern =
"/<[^<>]+>/";
7139 $tempbis = str_replace(
'<>',
'', $temp);
7140 $tempbis = preg_replace($pattern,
'', $tempbis);
7142 }
while ($tempbis != $temp);
7147 $temp = preg_replace(
'/<+([a-z]+)/i',
'\1', $temp);
7153 if ($removelinefeed == 1) {
7154 $temp = str_replace(array(
"\r\n",
"\r",
"\n"),
" ", $temp);
7158 if ($removedoublespaces) {
7159 while (strpos($temp,
" ")) {
7160 $temp = str_replace(
" ",
" ", $temp);
7164 $temp = str_replace(
'__ltspace__',
'< ', $temp);
7184function dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles = 1, $removeclassattribute = 1, $cleanalsojavascript = 0, $allowiframe = 0, $allowed_tags = array(), $allowlink = 0)
7186 if (empty($allowed_tags)) {
7187 $allowed_tags = array(
7188 "html",
"head",
"meta",
"body",
"article",
"a",
"abbr",
"b",
"blockquote",
"br",
"cite",
"div",
"dl",
"dd",
"dt",
"em",
"font",
"img",
"ins",
"hr",
"i",
"li",
7189 "ol",
"p",
"q",
"s",
"section",
"span",
"strike",
"strong",
"title",
"table",
"tr",
"th",
"td",
"u",
"ul",
"sup",
"sub",
"blockquote",
"pre",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6"
7192 $allowed_tags[] =
"comment";
7194 if (!in_array(
'iframe', $allowed_tags)) {
7195 $allowed_tags[] =
"iframe";
7199 if (!in_array(
'link', $allowed_tags)) {
7200 $allowed_tags[] =
"link";
7204 $allowed_tags_string = join(
"><", $allowed_tags);
7205 $allowed_tags_string =
'<'.$allowed_tags_string.
'>';
7207 $stringtoclean = str_replace(
'<!DOCTYPE html>',
'__!DOCTYPE_HTML__', $stringtoclean);
7212 $stringtoclean = preg_replace(
'/<!--([^>]*)-->/',
'<comment>\1</comment>', $stringtoclean);
7214 $stringtoclean = preg_replace(
'/:/i',
':', $stringtoclean);
7215 $stringtoclean = preg_replace(
'/:|�+58|:/i',
'', $stringtoclean);
7217 $temp = strip_tags($stringtoclean, $allowed_tags_string);
7219 if ($cleanalsosomestyles) {
7220 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)\s*!\s*important/i',
'', $temp);
7222 if ($removeclassattribute) {
7223 $temp = preg_replace(
'/(<[^>]+)\s+class=((["\']).*?\\3|\\w*)/i',
'\\1', $temp);
7228 if ($cleanalsojavascript) {
7229 $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);
7232 $temp = str_replace(
'__!DOCTYPE_HTML__',
'<!DOCTYPE html>', $temp);
7234 $temp = preg_replace(
'/<comment>([^>]*)<\/comment>/',
'<!--\1-->', $temp);
7252function dol_string_onlythesehtmlattributes($stringtoclean, $allowed_attributes = array(
"allow",
"allowfullscreen",
"alt",
"class",
"contenteditable",
"data-html",
"frameborder",
"height",
"href",
"id",
"name",
"src",
"style",
"target",
"title",
"width"))
7254 if (class_exists(
'DOMDocument') && !empty($stringtoclean)) {
7255 $stringtoclean =
'<?xml encoding="UTF-8"><html><body>'.$stringtoclean.
'</body></html>';
7257 $dom =
new DOMDocument(
null,
'UTF-8');
7258 $dom->loadHTML($stringtoclean, LIBXML_ERR_NONE|LIBXML_HTML_NOIMPLIED|LIBXML_HTML_NODEFDTD|LIBXML_NONET|LIBXML_NOWARNING|LIBXML_NOXMLDECL);
7260 if (is_object($dom)) {
7261 for ($els = $dom->getElementsByTagname(
'*'), $i = $els->length - 1; $i >= 0; $i--) {
7262 for ($attrs = $els->item($i)->attributes, $ii = $attrs->length - 1; $ii >= 0; $ii--) {
7264 if (!empty($attrs->item($ii)->name)) {
7265 if (! in_array($attrs->item($ii)->name, $allowed_attributes)) {
7267 $els->item($i)->removeAttribute($attrs->item($ii)->name);
7268 } elseif (in_array($attrs->item($ii)->name, array(
'style'))) {
7270 $valuetoclean = $attrs->item($ii)->value;
7272 if (isset($valuetoclean)) {
7274 $oldvaluetoclean = $valuetoclean;
7275 $valuetoclean = preg_replace(
'/\/\*.*\*\//m',
'', $valuetoclean);
7276 $valuetoclean = preg_replace(
'/position\s*:\s*[a-z]+/mi',
'', $valuetoclean);
7277 if ($els->item($i)->tagName ==
'a') {
7278 $valuetoclean = preg_replace(
'/display\s*:/mi',
'', $valuetoclean);
7279 $valuetoclean = preg_replace(
'/z-index\s*:/mi',
'', $valuetoclean);
7280 $valuetoclean = preg_replace(
'/\s+(top|left|right|bottom)\s*:/mi',
'', $valuetoclean);
7284 $valuetoclean = preg_replace(
'/(logout|passwordforgotten)\.php/mi',
'', $valuetoclean);
7285 $valuetoclean = preg_replace(
'/action=/mi',
'', $valuetoclean);
7286 }
while ($oldvaluetoclean != $valuetoclean);
7289 $attrs->item($ii)->value = $valuetoclean;
7296 $return = $dom->saveHTML();
7299 $return = preg_replace(
'/^'.preg_quote(
'<?xml encoding="UTF-8">',
'/').
'/',
'', $return);
7300 $return = preg_replace(
'/^'.preg_quote(
'<html><body>',
'/').
'/',
'', $return);
7301 $return = preg_replace(
'/'.preg_quote(
'</body></html>',
'/').
'$/',
'', $return);
7302 return trim($return);
7304 return $stringtoclean;
7321 $temp = $stringtoclean;
7322 foreach ($disallowed_tags as $tagtoremove) {
7323 $temp = preg_replace(
'/<\/?'.$tagtoremove.
'>/',
'', $temp);
7324 $temp = preg_replace(
'/<\/?'.$tagtoremove.
'\s+[^>]*>/',
'', $temp);
7327 if ($cleanalsosomestyles) {
7328 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)\s*!\s*important/',
'', $temp);
7346 if ($nboflines == 1) {
7348 $firstline = preg_replace(
'/<br[^>]*>.*$/s',
'', $text);
7349 $firstline = preg_replace(
'/<div[^>]*>.*$/s',
'', $firstline);
7352 $firstline = preg_replace(
'/[\n\r].*/',
'', $text);
7357 return $firstline.(isset($firstline) && isset($text) && (strlen($firstline) != strlen($text)) ?
'...' :
'');
7361 $text = preg_replace(
'/\n/',
'', $text);
7363 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
7365 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
7368 $text = strtr($text, $repTable);
7369 if ($charset ==
'UTF-8') {
7370 $pattern =
'/(<br[^>]*>)/Uu';
7373 $pattern =
'/(<br[^>]*>)/U';
7375 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
7380 while (($i < $nba) && ($i < ($nboflines * 2))) {
7382 $firstline .= $a[$i];
7383 } elseif (($i < (($nboflines * 2) - 1)) && ($i < ($nba - 1))) {
7384 $firstline .= ($ishtml ?
"<br>\n" :
"\n");
7389 return $firstline.(($i < $nba) ?
'...' :
'');
7405function dol_nl2br($stringtoencode, $nl2brmode = 0, $forxml =
false)
7407 if (is_null($stringtoencode)) {
7412 return nl2br($stringtoencode, $forxml);
7414 $ret = preg_replace(
'/(\r\n|\r|\n)/i', ($forxml ?
'<br />' :
'<br>'), $stringtoencode);
7431 if (empty($nouseofiframesandbox) && !empty($conf->global->MAIN_SECURITY_USE_SANDBOX_FOR_HTMLWITHNOJS)) {
7436 return $stringtoencode;
7438 $out = $stringtoencode;
7441 $oldstringtoclean = $out;
7443 if (!empty($out) && !empty($conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML) && $check !=
'restricthtmlallowunvalid') {
7445 libxml_use_internal_errors(
false);
7447 $dom =
new DOMDocument;
7451 $out =
'<div class="tricktoremove">'.$out.
'</div>';
7452 $dom->loadHTML($out, LIBXML_HTML_NODEFDTD|LIBXML_ERR_NONE|LIBXML_HTML_NOIMPLIED|LIBXML_NONET|LIBXML_NOWARNING|LIBXML_NOXMLDECL);
7453 $out = trim($dom->saveHTML());
7456 $out = preg_replace(
'/^<div class="tricktoremove">/',
'', $out);
7457 $out = preg_replace(
'/<\/div>$/',
'', $out);
7461 $out =
'InvalidHTMLStringCantBeCleaned';
7466 $out = preg_replace(
'/&(tab|newline);/i',
' ', $out);
7470 $out = preg_replace(
'/'/i',
''', $out);
7475 $out = preg_replace_callback(
'/&#(x?[0-9][0-9a-f]+;?)/i',
function ($m) {
7480 $out = preg_replace(
'/&#x?[0-9]+/i',
'', $out);
7486 if (!empty($conf->global->MAIN_RESTRICTHTML_REMOVE_ALSO_BAD_ATTRIBUTES)) {
7491 $out = preg_replace(
'/'/i',
"'", $out);
7492 }
while ($oldstringtoclean != $out);
7499 preg_match_all(
'/(<img|url\(|<link)/i', $out, $reg);
7500 $nbextlink = count($reg[0]);
7501 if ($nbextlink >
getDolGlobalInt(
"MAIN_SECURITY_MAX_IMG_IN_HTML_CONTENT", 1000)) {
7502 $out =
'TooManyLinksIntoHTMLString';
7505 if (!empty($conf->global->MAIN_DISALLOW_EXT_URL_INTO_DESCRIPTIONS) || $check ==
'restricthtmlnolink') {
7506 if ($nbextlink > 0) {
7507 $out =
'ExternalLinksNotAllowed';
7536function dol_htmlentitiesbr($stringtoencode, $nl2brmode = 0, $pagecodefrom =
'UTF-8', $removelasteolbr = 1)
7538 if (is_null($stringtoencode)) {
7542 $newstring = $stringtoencode;
7544 $newstring = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
'<br>', $newstring);
7545 if ($removelasteolbr) {
7546 $newstring = preg_replace(
'/<br>$/i',
'', $newstring);
7548 $newstring = strtr($newstring, array(
'&'=>
'__and__',
'<'=>
'__lt__',
'>'=>
'__gt__',
'"'=>
'__dquot__'));
7550 $newstring = strtr($newstring, array(
'__and__'=>
'&',
'__lt__'=>
'<',
'__gt__'=>
'>',
'__dquot__'=>
'"'));
7552 if ($removelasteolbr) {
7553 $newstring = preg_replace(
'/(\r\n|\r|\n)$/i',
'', $newstring);
7572 $ret = preg_replace(
'/'.
"\r\n".
'<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"<br>", $ret);
7573 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>'.
"\r\n".
'/i',
"\r\n", $ret);
7574 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>'.
"\n".
'/i',
"\n", $ret);
7575 $ret = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
"\n", $ret);
7587 $ret = preg_replace(
'/ $/i',
"", $stringtodecode);
7588 $ret = preg_replace(
'/(<br>|<br(\s[\sa-zA-Z_="]*)?\/?>|'.
"\n".
'|'.
"\r".
')+$/i',
"", $ret);
7604 if ($keepsomeentities) {
7605 $newstring = strtr($newstring, array(
'&'=>
'__andamp__',
'<'=>
'__andlt__',
'>'=>
'__andgt__',
'"'=>
'__dquot__'));
7607 $newstring = html_entity_decode((
string) $newstring, (
int) $b, (
string) $c);
7608 if ($keepsomeentities) {
7609 $newstring = strtr($newstring, array(
'__andamp__'=>
'&',
'__andlt__'=>
'<',
'__andgt__'=>
'>',
'__dquot__'=>
'"'));
7624function dol_htmlentities($string, $flags = ENT_QUOTES|ENT_SUBSTITUTE, $encoding =
'UTF-8', $double_encode =
false)
7626 return htmlentities($string, $flags, $encoding, $double_encode);
7645 for ($scursor = 0; $scursor < $len; $scursor++) {
7646 $ordchar = ord($s[$scursor]);
7648 if ($ordchar < 32 && $ordchar != 13 && $ordchar != 10) {
7651 } elseif ($ordchar > 126 && $ordchar < 160) {
7655 $out .= $s[$scursor];
7677 $arraystring = explode(
"\n", $s);
7678 $nb = count($arraystring);
7695 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
7697 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
7700 $text = strtr($text, $repTable);
7701 if ($charset ==
'UTF-8') {
7702 $pattern =
'/(<br[^>]*>)/Uu';
7705 $pattern =
'/(<br[^>]*>)/U';
7707 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
7709 $nblines = (int) floor((count($a) + 1) / 2);
7712 foreach ($a as $line) {
7715 $line_dec = html_entity_decode($line);
7717 $line_dec = wordwrap($line_dec, $maxlinesize,
'\n',
true);
7718 $nblines += substr_count($line_dec,
'\n');
7738 if (is_null($msg)) {
7743 if (preg_match(
'/<html/i', $msg)) {
7745 } elseif (preg_match(
'/<body/i', $msg)) {
7747 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
7749 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
7751 } elseif (preg_match(
'/<br/i', $msg)) {
7757 $msg = preg_replace(
'/https?:\/\/[^"\'\s]+/i',
'', $msg);
7758 if (preg_match(
'/<html/i', $msg)) {
7760 } elseif (preg_match(
'/<body/i', $msg)) {
7762 } elseif (preg_match(
'/<\/textarea/i', $msg)) {
7764 } elseif (preg_match(
'/<(b|em|i|u)(\s+[^>]+)?>/i', $msg)) {
7766 } elseif (preg_match(
'/<(br|hr)\/>/i', $msg)) {
7768 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)>/i', $msg)) {
7770 } elseif (preg_match(
'/<(br|hr|div|font|li|p|span|strong|table)\s+[^<>\/]*\/?>/i', $msg)) {
7772 } elseif (preg_match(
'/<img\s+[^<>]*src[^<>]*>/i', $msg)) {
7774 } elseif (preg_match(
'/<a\s+[^<>]*href[^<>]*>/i', $msg)) {
7776 } elseif (preg_match(
'/<h[0-9]>/i', $msg)) {
7778 } elseif (preg_match(
'/&[A-Z0-9]{1,6};/i', $msg)) {
7781 } elseif (preg_match(
'/&#[0-9]{2,3};/i', $msg)) {
7805 if (!empty($invert)) {
7813 $ret .= (!empty($text1) && !empty($text2)) ? ((
dol_textishtml($text1) ||
dol_textishtml($text2)) ? ($forxml ?
"<br >\n" :
"<br>\n") :
"\n") :
"";
7833 global $db, $conf, $mysoc, $user, $extrafields;
7835 $substitutionarray = array();
7837 if ((empty($exclude) || !in_array(
'user', $exclude)) && (empty($include) || in_array(
'user', $include))) {
7841 $emailsendersignature = $user->signature;
7842 $usersignature = $user->signature;
7843 $substitutionarray = array_merge($substitutionarray, array(
7844 '__SENDEREMAIL_SIGNATURE__' => (
string) ((empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ?
dol_trunc(
'SignatureFromTheSelectedSenderProfile', 30) : $emailsendersignature) :
''),
7845 '__USER_SIGNATURE__' => (
string) (($usersignature && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? ($onlykey == 2 ?
dol_trunc(
dol_string_nohtmltag($usersignature), 30) : $usersignature) :
'')
7848 if (is_object($user)) {
7849 $substitutionarray = array_merge($substitutionarray, array(
7850 '__USER_ID__' => (
string) $user->id,
7851 '__USER_LOGIN__' => (
string) $user->login,
7852 '__USER_EMAIL__' => (
string) $user->email,
7853 '__USER_PHONE__' => (
string)
dol_print_phone($user->office_phone,
'', 0, 0,
'',
" ",
'',
'', -1),
7854 '__USER_PHONEPRO__' => (
string)
dol_print_phone($user->user_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
7855 '__USER_PHONEMOBILE__' => (
string)
dol_print_phone($user->personal_mobile,
'', 0, 0,
'',
" ",
'',
'', -1),
7856 '__USER_FAX__' => (
string) $user->office_fax,
7857 '__USER_LASTNAME__' => (
string) $user->lastname,
7858 '__USER_FIRSTNAME__' => (
string) $user->firstname,
7859 '__USER_FULLNAME__' => (
string) $user->getFullName($outputlangs),
7860 '__USER_SUPERVISOR_ID__' => (
string) ($user->fk_user ? $user->fk_user :
'0'),
7861 '__USER_JOB__' => (
string) $user->job,
7863 '__USER_VCARD_URL__' => (string) $user->getOnlineVirtualCardUrl(
'',
'external')
7867 if ((empty($exclude) || !in_array(
'mycompany', $exclude)) && is_object($mysoc) && (empty($include) || in_array(
'mycompany', $include))) {
7868 $substitutionarray = array_merge($substitutionarray, array(
7869 '__MYCOMPANY_NAME__' => $mysoc->name,
7870 '__MYCOMPANY_EMAIL__' => $mysoc->email,
7871 '__MYCOMPANY_PHONE__' =>
dol_print_phone($mysoc->phone,
'', 0, 0,
'',
" ",
'',
'', -1),
7872 '__MYCOMPANY_FAX__' =>
dol_print_phone($mysoc->fax,
'', 0, 0,
'',
" ",
'',
'', -1),
7873 '__MYCOMPANY_PROFID1__' => $mysoc->idprof1,
7874 '__MYCOMPANY_PROFID2__' => $mysoc->idprof2,
7875 '__MYCOMPANY_PROFID3__' => $mysoc->idprof3,
7876 '__MYCOMPANY_PROFID4__' => $mysoc->idprof4,
7877 '__MYCOMPANY_PROFID5__' => $mysoc->idprof5,
7878 '__MYCOMPANY_PROFID6__' => $mysoc->idprof6,
7879 '__MYCOMPANY_CAPITAL__' => $mysoc->capital,
7880 '__MYCOMPANY_FULLADDRESS__' => (method_exists($mysoc,
'getFullAddress') ? $mysoc->getFullAddress(1,
', ') :
''),
7881 '__MYCOMPANY_ADDRESS__' => $mysoc->address,
7882 '__MYCOMPANY_ZIP__' => $mysoc->zip,
7883 '__MYCOMPANY_TOWN__' => $mysoc->town,
7884 '__MYCOMPANY_COUNTRY__' => $mysoc->country,
7885 '__MYCOMPANY_COUNTRY_ID__' => $mysoc->country_id,
7886 '__MYCOMPANY_COUNTRY_CODE__' => $mysoc->country_code,
7887 '__MYCOMPANY_CURRENCY_CODE__' => $conf->currency
7891 if (($onlykey || is_object($object)) && (empty($exclude) || !in_array(
'object', $exclude)) && (empty($include) || in_array(
'object', $include))) {
7893 $substitutionarray[
'__ID__'] =
'__ID__';
7894 $substitutionarray[
'__REF__'] =
'__REF__';
7895 $substitutionarray[
'__NEWREF__'] =
'__NEWREF__';
7896 $substitutionarray[
'__LABEL__'] =
'__LABEL__';
7897 $substitutionarray[
'__REF_CLIENT__'] =
'__REF_CLIENT__';
7898 $substitutionarray[
'__REF_SUPPLIER__'] =
'__REF_SUPPLIER__';
7899 $substitutionarray[
'__NOTE_PUBLIC__'] =
'__NOTE_PUBLIC__';
7900 $substitutionarray[
'__NOTE_PRIVATE__'] =
'__NOTE_PRIVATE__';
7901 $substitutionarray[
'__EXTRAFIELD_XXX__'] =
'__EXTRAFIELD_XXX__';
7903 if (isModEnabled(
"societe")) {
7904 $substitutionarray[
'__THIRDPARTY_ID__'] =
'__THIRDPARTY_ID__';
7905 $substitutionarray[
'__THIRDPARTY_NAME__'] =
'__THIRDPARTY_NAME__';
7906 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] =
'__THIRDPARTY_NAME_ALIAS__';
7907 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] =
'__THIRDPARTY_CODE_CLIENT__';
7908 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] =
'__THIRDPARTY_CODE_FOURNISSEUR__';
7909 $substitutionarray[
'__THIRDPARTY_EMAIL__'] =
'__THIRDPARTY_EMAIL__';
7910 $substitutionarray[
'__THIRDPARTY_PHONE__'] =
'__THIRDPARTY_PHONE__';
7911 $substitutionarray[
'__THIRDPARTY_FAX__'] =
'__THIRDPARTY_FAX__';
7912 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] =
'__THIRDPARTY_ADDRESS__';
7913 $substitutionarray[
'__THIRDPARTY_ZIP__'] =
'__THIRDPARTY_ZIP__';
7914 $substitutionarray[
'__THIRDPARTY_TOWN__'] =
'__THIRDPARTY_TOWN__';
7915 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] =
'__THIRDPARTY_IDPROF1__';
7916 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] =
'__THIRDPARTY_IDPROF2__';
7917 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] =
'__THIRDPARTY_IDPROF3__';
7918 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] =
'__THIRDPARTY_IDPROF4__';
7919 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] =
'__THIRDPARTY_IDPROF5__';
7920 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] =
'__THIRDPARTY_IDPROF6__';
7921 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] =
'__THIRDPARTY_TVAINTRA__';
7922 $substitutionarray[
'__THIRDPARTY_NOTE_PUBLIC__'] =
'__THIRDPARTY_NOTE_PUBLIC__';
7923 $substitutionarray[
'__THIRDPARTY_NOTE_PRIVATE__'] =
'__THIRDPARTY_NOTE_PRIVATE__';
7925 if (isModEnabled(
'adherent') && (!is_object($object) || $object->element ==
'adherent') && (empty($exclude) || !in_array(
'member', $exclude)) && (empty($include) || in_array(
'member', $include))) {
7926 $substitutionarray[
'__MEMBER_ID__'] =
'__MEMBER_ID__';
7927 $substitutionarray[
'__MEMBER_CIVILITY__'] =
'__MEMBER_CIVILITY__';
7928 $substitutionarray[
'__MEMBER_FIRSTNAME__'] =
'__MEMBER_FIRSTNAME__';
7929 $substitutionarray[
'__MEMBER_LASTNAME__'] =
'__MEMBER_LASTNAME__';
7930 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'Login and pass of the external user account';
7935 if (isModEnabled(
'ticket') && (!is_object($object) || $object->element ==
'ticket') && (empty($exclude) || !in_array(
'ticket', $exclude)) && (empty($include) || in_array(
'ticket', $include))) {
7936 $substitutionarray[
'__TICKET_TRACKID__'] =
'__TICKET_TRACKID__';
7937 $substitutionarray[
'__TICKET_SUBJECT__'] =
'__TICKET_SUBJECT__';
7938 $substitutionarray[
'__TICKET_TYPE__'] =
'__TICKET_TYPE__';
7939 $substitutionarray[
'__TICKET_SEVERITY__'] =
'__TICKET_SEVERITY__';
7940 $substitutionarray[
'__TICKET_CATEGORY__'] =
'__TICKET_CATEGORY__';
7941 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] =
'__TICKET_ANALYTIC_CODE__';
7942 $substitutionarray[
'__TICKET_MESSAGE__'] =
'__TICKET_MESSAGE__';
7943 $substitutionarray[
'__TICKET_PROGRESSION__'] =
'__TICKET_PROGRESSION__';
7944 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
'__TICKET_USER_ASSIGN__';
7947 if (isModEnabled(
'recruitment') && (!is_object($object) || $object->element ==
'recruitmentcandidature') && (empty($exclude) || !in_array(
'recruitment', $exclude)) && (empty($include) || in_array(
'recruitment', $include))) {
7948 $substitutionarray[
'__CANDIDATE_FULLNAME__'] =
'__CANDIDATE_FULLNAME__';
7949 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] =
'__CANDIDATE_FIRSTNAME__';
7950 $substitutionarray[
'__CANDIDATE_LASTNAME__'] =
'__CANDIDATE_LASTNAME__';
7952 if (isModEnabled(
'project') && (empty($exclude) || !in_array(
'project', $exclude)) && (empty($include) || in_array(
'project', $include))) {
7953 $substitutionarray[
'__PROJECT_ID__'] =
'__PROJECT_ID__';
7954 $substitutionarray[
'__PROJECT_REF__'] =
'__PROJECT_REF__';
7955 $substitutionarray[
'__PROJECT_NAME__'] =
'__PROJECT_NAME__';
7959 if (isModEnabled(
'contrat') && (!is_object($object) || $object->element ==
'contract') && (empty($exclude) || !in_array(
'contract', $exclude)) && (empty($include) || in_array(
'contract', $include))) {
7960 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
'Highest date planned for a service start';
7961 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
'Highest date and hour planned for service start';
7962 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
'Lowest data for planned expiration of service';
7963 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
'Lowest date and hour for planned expiration of service';
7965 if (isModEnabled(
"propal") && (!is_object($object) || $object->element ==
'propal') && (empty($exclude) || !in_array(
'propal', $exclude)) && (empty($include) || in_array(
'propal', $include))) {
7966 $substitutionarray[
'__ONLINE_SIGN_URL__'] =
'ToOfferALinkForOnlineSignature';
7968 if (isModEnabled(
"ficheinter") && (!is_object($object) || $object->element ==
'fichinter') && (empty($exclude) || !in_array(
'intervention', $exclude)) && (empty($include) || in_array(
'intervention', $include))) {
7969 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] =
'ToOfferALinkForOnlineSignature';
7971 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] =
'UrlToPayOnlineIfApplicable';
7972 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'TextAndUrlToPayOnlineIfApplicable';
7973 $substitutionarray[
'__SECUREKEYPAYMENT__'] =
'Security key (if key is not unique per record)';
7974 $substitutionarray[
'__SECUREKEYPAYMENT_MEMBER__'] =
'Security key for payment on a member subscription (one key per member)';
7975 $substitutionarray[
'__SECUREKEYPAYMENT_ORDER__'] =
'Security key for payment on an order';
7976 $substitutionarray[
'__SECUREKEYPAYMENT_INVOICE__'] =
'Security key for payment on an invoice';
7977 $substitutionarray[
'__SECUREKEYPAYMENT_CONTRACTLINE__'] =
'Security key for payment on a service of a contract';
7979 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'Direct download url of a proposal';
7980 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'Direct download url of an order';
7981 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'Direct download url of an invoice';
7982 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'Direct download url of a contract';
7983 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'Direct download url of a supplier proposal';
7985 if (isModEnabled(
"expedition") && (!is_object($object) || $object->element ==
'shipping')) {
7986 $substitutionarray[
'__SHIPPINGTRACKNUM__'] =
'Shipping tracking number';
7987 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] =
'Shipping tracking url';
7989 if (isModEnabled(
"reception") && (!is_object($object) || $object->element ==
'reception')) {
7990 $substitutionarray[
'__RECEPTIONTRACKNUM__'] =
'Shippin tracking number of shipment';
7991 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] =
'Shipping tracking url';
7994 $substitutionarray[
'__ID__'] = $object->id;
7995 $substitutionarray[
'__REF__'] = $object->ref;
7996 $substitutionarray[
'__NEWREF__'] = $object->newref;
7997 $substitutionarray[
'__LABEL__'] = (isset($object->label) ? $object->label : (isset($object->title) ? $object->title :
null));
7998 $substitutionarray[
'__REF_CLIENT__'] = (isset($object->ref_client) ? $object->ref_client : (isset($object->ref_customer) ? $object->ref_customer :
null));
7999 $substitutionarray[
'__REF_SUPPLIER__'] = (isset($object->ref_supplier) ? $object->ref_supplier :
null);
8000 $substitutionarray[
'__NOTE_PUBLIC__'] = (isset($object->note_public) ? $object->note_public :
null);
8001 $substitutionarray[
'__NOTE_PRIVATE__'] = (isset($object->note_private) ? $object->note_private :
null);
8002 if ($object->element ==
"shipping") {
8003 $substitutionarray[
'__DATE_DELIVERY__'] = (isset($object->date_delivery) ?
dol_print_date($object->date_delivery,
'day', 0, $outputlangs) :
'');
8005 $substitutionarray[
'__DATE_DELIVERY__'] = (isset($object->date_livraison) ?
dol_print_date($object->date_livraison,
'day', 0, $outputlangs) :
'');
8007 $substitutionarray[
'__DATE_DELIVERY_DAY__'] = (isset($object->date_livraison) ?
dol_print_date($object->date_livraison,
"%d") :
'');
8008 $substitutionarray[
'__DATE_DELIVERY_DAY_TEXT__'] = (isset($object->date_livraison) ?
dol_print_date($object->date_livraison,
"%A") :
'');
8009 $substitutionarray[
'__DATE_DELIVERY_MON__'] = (isset($object->date_livraison) ?
dol_print_date($object->date_livraison,
"%m") :
'');
8010 $substitutionarray[
'__DATE_DELIVERY_MON_TEXT__'] = (isset($object->date_livraison) ?
dol_print_date($object->date_livraison,
"%b") :
'');
8011 $substitutionarray[
'__DATE_DELIVERY_YEAR__'] = (isset($object->date_livraison) ?
dol_print_date($object->date_livraison,
"%Y") :
'');
8012 $substitutionarray[
'__DATE_DELIVERY_HH__'] = (isset($object->date_livraison) ?
dol_print_date($object->date_livraison,
"%H") :
'');
8013 $substitutionarray[
'__DATE_DELIVERY_MM__'] = (isset($object->date_livraison) ?
dol_print_date($object->date_livraison,
"%M") :
'');
8014 $substitutionarray[
'__DATE_DELIVERY_SS__'] = (isset($object->date_livraison) ?
dol_print_date($object->date_livraison,
"%S") :
'');
8017 $substitutionarray[
'__REFCLIENT__'] = (isset($object->ref_client) ? $object->ref_client : (isset($object->ref_customer) ? $object->ref_customer :
null));
8018 $substitutionarray[
'__REFSUPPLIER__'] = (isset($object->ref_supplier) ? $object->ref_supplier :
null);
8019 $substitutionarray[
'__SUPPLIER_ORDER_DATE_DELIVERY__'] = (isset($object->date_livraison) ?
dol_print_date($object->date_livraison,
'day', 0, $outputlangs) :
'');
8020 $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 :
'')) :
'');
8022 if (is_object($object) && ($object->element ==
'adherent' || $object->element ==
'member') && $object->id > 0) {
8023 $birthday = (empty($object->birth) ?
'' :
dol_print_date($object->birth,
'day'));
8025 $substitutionarray[
'__MEMBER_ID__'] = (isset($object->id) ? $object->id :
'');
8026 if (method_exists($object,
'getCivilityLabel')) {
8027 $substitutionarray[
'__MEMBER_CIVILITY__'] = $object->getCivilityLabel();
8029 $substitutionarray[
'__MEMBER_FIRSTNAME__'] = (isset($object->firstname) ? $object->firstname :
'');
8030 $substitutionarray[
'__MEMBER_LASTNAME__'] = (isset($object->lastname) ? $object->lastname :
'');
8031 $substitutionarray[
'__MEMBER_USER_LOGIN_INFORMATION__'] =
'';
8032 if (method_exists($object,
'getFullName')) {
8033 $substitutionarray[
'__MEMBER_FULLNAME__'] = $object->getFullName($outputlangs);
8035 $substitutionarray[
'__MEMBER_COMPANY__'] = (isset($object->societe) ? $object->societe :
'');
8036 $substitutionarray[
'__MEMBER_ADDRESS__'] = (isset($object->address) ? $object->address :
'');
8037 $substitutionarray[
'__MEMBER_ZIP__'] = (isset($object->zip) ? $object->zip :
'');
8038 $substitutionarray[
'__MEMBER_TOWN__'] = (isset($object->town) ? $object->town :
'');
8039 $substitutionarray[
'__MEMBER_COUNTRY__'] = (isset($object->country) ? $object->country :
'');
8040 $substitutionarray[
'__MEMBER_EMAIL__'] = (isset($object->email) ? $object->email :
'');
8041 $substitutionarray[
'__MEMBER_BIRTH__'] = (isset($birthday) ? $birthday :
'');
8042 $substitutionarray[
'__MEMBER_PHOTO__'] = (isset($object->photo) ? $object->photo :
'');
8043 $substitutionarray[
'__MEMBER_LOGIN__'] = (isset($object->login) ? $object->login :
'');
8044 $substitutionarray[
'__MEMBER_PASSWORD__'] = (isset($object->pass) ? $object->pass :
'');
8045 $substitutionarray[
'__MEMBER_PHONE__'] = (isset($object->phone) ?
dol_print_phone($object->phone) :
'');
8046 $substitutionarray[
'__MEMBER_PHONEPRO__'] = (isset($object->phone_perso) ?
dol_print_phone($object->phone_perso) :
'');
8047 $substitutionarray[
'__MEMBER_PHONEMOBILE__'] = (isset($object->phone_mobile) ?
dol_print_phone($object->phone_mobile) :
'');
8048 $substitutionarray[
'__MEMBER_TYPE__'] = (isset($object->type) ? $object->type :
'');
8049 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE__'] =
dol_print_date($object->first_subscription_date,
'day');
8050 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_START__'] = (isset($object->first_subscription_date_start) ?
dol_print_date($object->first_subscription_date_start,
'day') :
'');
8051 $substitutionarray[
'__MEMBER_FIRST_SUBSCRIPTION_DATE_END__'] = (isset($object->first_subscription_date_end) ?
dol_print_date($object->first_subscription_date_end,
'day') :
'');
8052 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE__'] =
dol_print_date($object->last_subscription_date,
'day');
8053 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_START__'] =
dol_print_date($object->last_subscription_date_start,
'day');
8054 $substitutionarray[
'__MEMBER_LAST_SUBSCRIPTION_DATE_END__'] =
dol_print_date($object->last_subscription_date_end,
'day');
8057 if (is_object($object) && $object->element ==
'societe') {
8058 $substitutionarray[
'__THIRDPARTY_ID__'] = (is_object($object) ? $object->id :
'');
8059 $substitutionarray[
'__THIRDPARTY_NAME__'] = (is_object($object) ? $object->name :
'');
8060 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] = (is_object($object) ? $object->name_alias :
'');
8061 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] = (is_object($object) ? $object->code_client :
'');
8062 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] = (is_object($object) ? $object->code_fournisseur :
'');
8063 $substitutionarray[
'__THIRDPARTY_EMAIL__'] = (is_object($object) ? $object->email :
'');
8064 $substitutionarray[
'__THIRDPARTY_PHONE__'] = (is_object($object) ?
dol_print_phone($object->phone) :
'');
8065 $substitutionarray[
'__THIRDPARTY_FAX__'] = (is_object($object) ?
dol_print_phone($object->fax) :
'');
8066 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] = (is_object($object) ? $object->address :
'');
8067 $substitutionarray[
'__THIRDPARTY_ZIP__'] = (is_object($object) ? $object->zip :
'');
8068 $substitutionarray[
'__THIRDPARTY_TOWN__'] = (is_object($object) ? $object->town :
'');
8069 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (is_object($object) ? $object->country_id :
'');
8070 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] = (is_object($object) ? $object->country_code :
'');
8071 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] = (is_object($object) ? $object->idprof1 :
'');
8072 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] = (is_object($object) ? $object->idprof2 :
'');
8073 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] = (is_object($object) ? $object->idprof3 :
'');
8074 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] = (is_object($object) ? $object->idprof4 :
'');
8075 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] = (is_object($object) ? $object->idprof5 :
'');
8076 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] = (is_object($object) ? $object->idprof6 :
'');
8077 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] = (is_object($object) ? $object->tva_intra :
'');
8078 $substitutionarray[
'__THIRDPARTY_NOTE_PUBLIC__'] = (is_object($object) ?
dol_htmlentitiesbr($object->note_public) :
'');
8079 $substitutionarray[
'__THIRDPARTY_NOTE_PRIVATE__'] = (is_object($object) ?
dol_htmlentitiesbr($object->note_private) :
'');
8080 } elseif (is_object($object->thirdparty)) {
8081 $substitutionarray[
'__THIRDPARTY_ID__'] = (is_object($object->thirdparty) ? $object->thirdparty->id :
'');
8082 $substitutionarray[
'__THIRDPARTY_NAME__'] = (is_object($object->thirdparty) ? $object->thirdparty->name :
'');
8083 $substitutionarray[
'__THIRDPARTY_NAME_ALIAS__'] = (is_object($object->thirdparty) ? $object->thirdparty->name_alias :
'');
8084 $substitutionarray[
'__THIRDPARTY_CODE_CLIENT__'] = (is_object($object->thirdparty) ? $object->thirdparty->code_client :
'');
8085 $substitutionarray[
'__THIRDPARTY_CODE_FOURNISSEUR__'] = (is_object($object->thirdparty) ? $object->thirdparty->code_fournisseur :
'');
8086 $substitutionarray[
'__THIRDPARTY_EMAIL__'] = (is_object($object->thirdparty) ? $object->thirdparty->email :
'');
8087 $substitutionarray[
'__THIRDPARTY_PHONE__'] = (is_object($object->thirdparty) ?
dol_print_phone($object->thirdparty->phone) :
'');
8088 $substitutionarray[
'__THIRDPARTY_FAX__'] = (is_object($object->thirdparty) ?
dol_print_phone($object->thirdparty->fax) :
'');
8089 $substitutionarray[
'__THIRDPARTY_ADDRESS__'] = (is_object($object->thirdparty) ? $object->thirdparty->address :
'');
8090 $substitutionarray[
'__THIRDPARTY_ZIP__'] = (is_object($object->thirdparty) ? $object->thirdparty->zip :
'');
8091 $substitutionarray[
'__THIRDPARTY_TOWN__'] = (is_object($object->thirdparty) ? $object->thirdparty->town :
'');
8092 $substitutionarray[
'__THIRDPARTY_COUNTRY_ID__'] = (is_object($object->thirdparty) ? $object->thirdparty->country_id :
'');
8093 $substitutionarray[
'__THIRDPARTY_COUNTRY_CODE__'] = (is_object($object->thirdparty) ? $object->thirdparty->country_code :
'');
8094 $substitutionarray[
'__THIRDPARTY_IDPROF1__'] = (is_object($object->thirdparty) ? $object->thirdparty->idprof1 :
'');
8095 $substitutionarray[
'__THIRDPARTY_IDPROF2__'] = (is_object($object->thirdparty) ? $object->thirdparty->idprof2 :
'');
8096 $substitutionarray[
'__THIRDPARTY_IDPROF3__'] = (is_object($object->thirdparty) ? $object->thirdparty->idprof3 :
'');
8097 $substitutionarray[
'__THIRDPARTY_IDPROF4__'] = (is_object($object->thirdparty) ? $object->thirdparty->idprof4 :
'');
8098 $substitutionarray[
'__THIRDPARTY_IDPROF5__'] = (is_object($object->thirdparty) ? $object->thirdparty->idprof5 :
'');
8099 $substitutionarray[
'__THIRDPARTY_IDPROF6__'] = (is_object($object->thirdparty) ? $object->thirdparty->idprof6 :
'');
8100 $substitutionarray[
'__THIRDPARTY_TVAINTRA__'] = (is_object($object->thirdparty) ? $object->thirdparty->tva_intra :
'');
8101 $substitutionarray[
'__THIRDPARTY_NOTE_PUBLIC__'] = (is_object($object->thirdparty) ?
dol_htmlentitiesbr($object->thirdparty->note_public) :
'');
8102 $substitutionarray[
'__THIRDPARTY_NOTE_PRIVATE__'] = (is_object($object->thirdparty) ?
dol_htmlentitiesbr($object->thirdparty->note_private) :
'');
8105 if (is_object($object) && $object->element ==
'recruitmentcandidature') {
8106 $substitutionarray[
'__CANDIDATE_FULLNAME__'] = $object->getFullName($outputlangs);
8107 $substitutionarray[
'__CANDIDATE_FIRSTNAME__'] = isset($object->firstname) ? $object->firstname :
'';
8108 $substitutionarray[
'__CANDIDATE_LASTNAME__'] = isset($object->lastname) ? $object->lastname :
'';
8110 if (is_object($object) && $object->element ==
'conferenceorboothattendee') {
8111 $substitutionarray[
'__ATTENDEE_FULLNAME__'] = $object->getFullName($outputlangs);
8112 $substitutionarray[
'__ATTENDEE_FIRSTNAME__'] = isset($object->firstname) ? $object->firstname :
'';
8113 $substitutionarray[
'__ATTENDEE_LASTNAME__'] = isset($object->lastname) ? $object->lastname :
'';
8117 if (is_object($object->project)) {
8118 $project = $object->project;
8119 } elseif (is_object($object->projet)) {
8120 $project = $object->projet;
8123 $substitutionarray[
'__PROJECT_ID__'] = $project->id;
8124 $substitutionarray[
'__PROJECT_REF__'] = $project->ref;
8125 $substitutionarray[
'__PROJECT_NAME__'] = $project->title;
8127 if (is_object($object) && $object->element ==
'project') {
8128 $substitutionarray[
'__PROJECT_NAME__'] = $object->title;
8131 if (is_object($object) && $object->element ==
'shipping') {
8132 $substitutionarray[
'__SHIPPINGTRACKNUM__'] = $object->tracking_number;
8133 $substitutionarray[
'__SHIPPINGTRACKNUMURL__'] = $object->tracking_url;
8135 if (is_object($object) && $object->element ==
'reception') {
8136 $substitutionarray[
'__RECEPTIONTRACKNUM__'] = $object->tracking_number;
8137 $substitutionarray[
'__RECEPTIONTRACKNUMURL__'] = $object->tracking_url;
8140 if (is_object($object) && $object->element ==
'contrat' && $object->id > 0 && is_array($object->lines)) {
8141 $dateplannedstart =
'';
8142 $datenextexpiration =
'';
8143 foreach ($object->lines as $line) {
8144 if ($line->date_start > $dateplannedstart) {
8145 $dateplannedstart = $line->date_start;
8147 if ($line->statut == 4 && $line->date_end && (!$datenextexpiration || $line->date_end < $datenextexpiration)) {
8148 $datenextexpiration = $line->date_end;
8151 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATE__'] =
dol_print_date($dateplannedstart,
'day');
8152 $substitutionarray[
'__CONTRACT_HIGHEST_PLANNED_START_DATETIME__'] =
dol_print_date($dateplannedstart,
'standard');
8153 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATE__'] =
dol_print_date($datenextexpiration,
'day');
8154 $substitutionarray[
'__CONTRACT_LOWEST_EXPIRATION_DATETIME__'] =
dol_print_date($datenextexpiration,
'standard');
8157 if (is_object($object) && $object->element ==
'ticket') {
8158 $substitutionarray[
'__TICKET_TRACKID__'] = $object->track_id;
8159 $substitutionarray[
'__REF__'] = $object->ref;
8160 $substitutionarray[
'__TICKET_SUBJECT__'] = $object->subject;
8161 $substitutionarray[
'__TICKET_TYPE__'] = $object->type_code;
8162 $substitutionarray[
'__TICKET_SEVERITY__'] = $object->severity_code;
8163 $substitutionarray[
'__TICKET_CATEGORY__'] = $object->category_code;
8164 $substitutionarray[
'__TICKET_ANALYTIC_CODE__'] = $object->category_code;
8165 $substitutionarray[
'__TICKET_MESSAGE__'] = $object->message;
8166 $substitutionarray[
'__TICKET_PROGRESSION__'] = $object->progress;
8167 $userstat =
new User($db);
8168 if ($object->fk_user_assign > 0) {
8169 $userstat->fetch($object->fk_user_assign);
8170 $substitutionarray[
'__TICKET_USER_ASSIGN__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
8173 if ($object->fk_user_create > 0) {
8174 $userstat->fetch($object->fk_user_create);
8175 $substitutionarray[
'__USER_CREATE__'] =
dolGetFirstLastname($userstat->firstname, $userstat->lastname);
8180 if ($object->table_element && $object->id > 0) {
8181 if (!is_object($extrafields)) {
8184 $extrafields->fetch_name_optionals_label($object->table_element,
true);
8186 if ($object->fetch_optionals() > 0) {
8187 if (is_array($extrafields->attributes[$object->table_element][
'label']) && count($extrafields->attributes[$object->table_element][
'label']) > 0) {
8188 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $label) {
8189 if ($extrafields->attributes[$object->table_element][
'type'][$key] ==
'date') {
8190 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'__'] =
dol_print_date($object->array_options[
'options_'.$key],
'day');
8191 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_LOCALE__'] =
dol_print_date($object->array_options[
'options_'.$key],
'day',
'tzserver', $outputlangs);
8192 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_RFC__'] =
dol_print_date($object->array_options[
'options_'.$key],
'dayrfc');
8193 } elseif ($extrafields->attributes[$object->table_element][
'type'][$key] ==
'datetime') {
8194 $datetime = $object->array_options[
'options_'.$key];
8195 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour') :
'');
8196 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhour',
'tzserver', $outputlangs) :
'');
8197 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_DAY_LOCALE__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'day',
'tzserver', $outputlangs) :
'');
8198 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_RFC__'] = ($datetime !=
"0000-00-00 00:00:00" ?
dol_print_date($datetime,
'dayhourrfc') :
'');
8199 } elseif ($extrafields->attributes[$object->table_element][
'type'][$key] ==
'phone') {
8200 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'__'] =
dol_print_phone($object->array_options[
'options_'.$key]);
8201 } elseif ($extrafields->attributes[$object->table_element][
'type'][$key] ==
'price') {
8202 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'__'] = $object->array_options[
'options_'.$key];
8203 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'_FORMATED__'] =
price($object->array_options[
'options_'.$key]);
8204 } elseif ($extrafields->attributes[$object->table_element][
'type'][$key] !=
'separator') {
8205 $substitutionarray[
'__EXTRAFIELD_'.strtoupper($key).
'__'] = !empty($object->array_options[
'options_'.$key]) ? $object->array_options[
'options_'.$key] :
'';
8214 if (empty($substitutionarray[
'__REF__'])) {
8218 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
8219 $outputlangs->loadLangs(array(
'paypal',
'other'));
8222 $typeforonlinepayment =
'free';
8223 if (is_object($object) && $object->element ==
'commande') {
8224 $typeforonlinepayment =
'order';
8226 if (is_object($object) && $object->element ==
'facture') {
8227 $typeforonlinepayment =
'invoice';
8229 if (is_object($object) && $object->element ==
'member') {
8230 $typeforonlinepayment =
'member';
8231 if (!empty($object->last_subscription_amount)) {
8232 $amounttouse = $object->last_subscription_amount;
8235 if (is_object($object) && $object->element ==
'contrat') {
8236 $typeforonlinepayment =
'contract';
8238 if (is_object($object) && $object->element ==
'fichinter') {
8239 $typeforonlinepayment =
'ficheinter';
8242 $url = getOnlinePaymentUrl(0, $typeforonlinepayment, $substitutionarray[
'__REF__'], $amounttouse);
8246 if ($object->id > 0) {
8247 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] = ($paymenturl ?str_replace(
'\n',
"\n", $outputlangs->trans(
"PredefinedMailContentLink", $paymenturl)) :
'');
8248 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] = $paymenturl;
8250 if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD) && is_object($object) && $object->element ==
'propal') {
8251 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] = $object->getLastMainDocLink($object->element);
8253 $substitutionarray[
'__DIRECTDOWNLOAD_URL_PROPOSAL__'] =
'';
8255 if (!empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD) && is_object($object) && $object->element ==
'commande') {
8256 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] = $object->getLastMainDocLink($object->element);
8258 $substitutionarray[
'__DIRECTDOWNLOAD_URL_ORDER__'] =
'';
8260 if (!empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD) && is_object($object) && $object->element ==
'facture') {
8261 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] = $object->getLastMainDocLink($object->element);
8263 $substitutionarray[
'__DIRECTDOWNLOAD_URL_INVOICE__'] =
'';
8265 if (!empty($conf->global->CONTRACT_ALLOW_EXTERNAL_DOWNLOAD) && is_object($object) && $object->element ==
'contrat') {
8266 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] = $object->getLastMainDocLink($object->element);
8268 $substitutionarray[
'__DIRECTDOWNLOAD_URL_CONTRACT__'] =
'';
8270 if (!empty($conf->global->FICHINTER_ALLOW_EXTERNAL_DOWNLOAD) && is_object($object) && $object->element ==
'fichinter') {
8271 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] = $object->getLastMainDocLink($object->element);
8273 $substitutionarray[
'__DIRECTDOWNLOAD_URL_FICHINTER__'] =
'';
8275 if (!empty($conf->global->SUPPLIER_PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD) && is_object($object) && $object->element ==
'supplier_proposal') {
8276 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] = $object->getLastMainDocLink($object->element);
8278 $substitutionarray[
'__DIRECTDOWNLOAD_URL_SUPPLIER_PROPOSAL__'] =
'';
8281 if (is_object($object) && $object->element ==
'propal') {
8282 $substitutionarray[
'__URL_PROPOSAL__'] = DOL_MAIN_URL_ROOT.
"/comm/propal/card.php?id=".$object->id;
8283 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
8284 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'proposal', $object->ref);
8286 if (is_object($object) && $object->element ==
'commande') {
8287 $substitutionarray[
'__URL_ORDER__'] = DOL_MAIN_URL_ROOT.
"/commande/card.php?id=".$object->id;
8289 if (is_object($object) && $object->element ==
'facture') {
8290 $substitutionarray[
'__URL_INVOICE__'] = DOL_MAIN_URL_ROOT.
"/compta/facture/card.php?id=".$object->id;
8292 if (is_object($object) && $object->element ==
'contrat') {
8293 $substitutionarray[
'__URL_CONTRACT__'] = DOL_MAIN_URL_ROOT.
"/contrat/card.php?id=".$object->id;
8294 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
8295 $substitutionarray[
'__ONLINE_SIGN_URL__'] = getOnlineSignatureUrl(0,
'contract', $object->ref);
8297 if (is_object($object) && $object->element ==
'fichinter') {
8298 $substitutionarray[
'__URL_FICHINTER__'] = DOL_MAIN_URL_ROOT.
"/fichinter/card.php?id=".$object->id;
8299 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
8300 $substitutionarray[
'__ONLINE_SIGN_FICHINTER_URL__'] = getOnlineSignatureUrl(0,
'fichinter', $object->ref);
8302 if (is_object($object) && $object->element ==
'supplier_proposal') {
8303 $substitutionarray[
'__URL_SUPPLIER_PROPOSAL__'] = DOL_MAIN_URL_ROOT.
"/supplier_proposal/card.php?id=".$object->id;
8305 if (is_object($object) && $object->element ==
'shipping') {
8306 $substitutionarray[
'__URL_SHIPMENT__'] = DOL_MAIN_URL_ROOT.
"/expedition/card.php?id=".$object->id;
8310 if (is_object($object) && $object->element ==
'action') {
8311 $substitutionarray[
'__EVENT_LABEL__'] = $object->label;
8312 $substitutionarray[
'__EVENT_DATE__'] =
dol_print_date($object->datep,
'%A %d %b %Y');
8313 $substitutionarray[
'__EVENT_TIME__'] =
dol_print_date($object->datep,
'%H:%M:%S');
8317 if ((empty($exclude) || !in_array(
'objectamount', $exclude)) && (empty($include) || in_array(
'objectamount', $include))) {
8318 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functionsnumtoword.lib.php';
8320 $substitutionarray[
'__DATE_YMD__'] = is_object($object) ? (isset($object->date) ?
dol_print_date($object->date,
'day', 0, $outputlangs) :
null) :
'';
8321 $substitutionarray[
'__DATE_DUE_YMD__'] = is_object($object) ? (isset($object->date_lim_reglement) ?
dol_print_date($object->date_lim_reglement,
'day', 0, $outputlangs) :
null) :
'';
8323 $already_payed_all = 0;
8324 if (is_object($object) && ($object instanceof
Facture)) {
8325 $already_payed_all = $object->sumpayed + $object->sumdeposit + $object->sumcreditnote;
8328 $substitutionarray[
'__AMOUNT_EXCL_TAX__'] = is_object($object) ? $object->total_ht :
'';
8330 $substitutionarray[
'__AMOUNT__'] = is_object($object) ? $object->total_ttc :
'';
8331 $substitutionarray[
'__AMOUNT_TEXT__'] = is_object($object) ?
dol_convertToWord($object->total_ttc, $outputlangs,
'',
true) :
'';
8332 $substitutionarray[
'__AMOUNT_TEXTCURRENCY__'] = is_object($object) ?
dol_convertToWord($object->total_ttc, $outputlangs, $conf->currency,
true) :
'';
8334 $substitutionarray[
'__AMOUNT_REMAIN__'] = is_object($object) ?
price2num($object->total_ttc - $already_payed_all,
'MT') :
'';
8336 $substitutionarray[
'__AMOUNT_VAT__'] = is_object($object) ? (isset($object->total_vat) ? $object->total_vat : $object->total_tva) :
'';
8337 $substitutionarray[
'__AMOUNT_VAT_TEXT__'] = is_object($object) ? (isset($object->total_vat) ?
dol_convertToWord($object->total_vat, $outputlangs,
'',
true) :
dol_convertToWord($object->total_tva, $outputlangs,
'',
true)) :
'';
8338 $substitutionarray[
'__AMOUNT_VAT_TEXTCURRENCY__'] = is_object($object) ? (isset($object->total_vat) ?
dol_convertToWord($object->total_vat, $outputlangs, $conf->currency,
true) :
dol_convertToWord($object->total_tva, $outputlangs, $conf->currency,
true)) :
'';
8340 if ($onlykey != 2 || $mysoc->useLocalTax(1)) {
8341 $substitutionarray[
'__AMOUNT_TAX2__'] = is_object($object) ? $object->total_localtax1 :
'';
8343 if ($onlykey != 2 || $mysoc->useLocalTax(2)) {
8344 $substitutionarray[
'__AMOUNT_TAX3__'] = is_object($object) ? $object->total_localtax2 :
'';
8348 $substitutionarray[
'__AMOUNT_EXCL_TAX_FORMATED__'] = is_object($object) ? ($object->total_ht ?
price($object->total_ht, 0, $outputlangs, 0, -1, -1, $conf->currency) :
null) :
'';
8349 $substitutionarray[
'__AMOUNT_FORMATED__'] = is_object($object) ? ($object->total_ttc ?
price($object->total_ttc, 0, $outputlangs, 0, -1, -1, $conf->currency) :
null) :
'';
8350 $substitutionarray[
'__AMOUNT_REMAIN_FORMATED__'] = is_object($object) ? ($object->total_ttc ?
price($object->total_ttc - $already_payed_all, 0, $outputlangs, 0, -1, -1, $conf->currency) :
null) :
'';
8351 $substitutionarray[
'__AMOUNT_VAT_FORMATED__'] = 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)) :
'';
8352 if ($onlykey != 2 || $mysoc->useLocalTax(1)) {
8353 $substitutionarray[
'__AMOUNT_TAX2_FORMATED__'] = is_object($object) ? ($object->total_localtax1 ?
price($object->total_localtax1, 0, $outputlangs, 0, -1, -1, $conf->currency) :
null) :
'';
8355 if ($onlykey != 2 || $mysoc->useLocalTax(2)) {
8356 $substitutionarray[
'__AMOUNT_TAX3_FORMATED__'] = is_object($object) ? ($object->total_localtax2 ?
price($object->total_localtax2, 0, $outputlangs, 0, -1, -1, $conf->currency) :
null) :
'';
8359 $substitutionarray[
'__AMOUNT_MULTICURRENCY__'] = (is_object($object) && isset($object->multicurrency_total_ttc)) ? $object->multicurrency_total_ttc :
'';
8360 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXT__'] = (is_object($object) && isset($object->multicurrency_total_ttc)) ?
dol_convertToWord($object->multicurrency_total_ttc, $outputlangs,
'',
true) :
'';
8361 $substitutionarray[
'__AMOUNT_MULTICURRENCY_TEXTCURRENCY__'] = (is_object($object) && isset($object->multicurrency_total_ttc)) ?
dol_convertToWord($object->multicurrency_total_ttc, $outputlangs, $object->multicurrency_code,
true) :
'';
8365 if ($onlykey != 2) {
8366 $substitutionarray[
'__TOTAL_TTC__'] = is_object($object) ? $object->total_ttc :
'';
8367 $substitutionarray[
'__TOTAL_HT__'] = is_object($object) ? $object->total_ht :
'';
8368 $substitutionarray[
'__TOTAL_VAT__'] = is_object($object) ? (isset($object->total_vat) ? $object->total_vat : $object->total_tva) :
'';
8373 if ((empty($exclude) || !in_array(
'date', $exclude)) && (empty($include) || in_array(
'date', $include))) {
8374 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
8384 $daytext = $outputlangs->trans(
'Day'.$tmp[
'wday']);
8386 $substitutionarray = array_merge($substitutionarray, array(
8387 '__NOW_TMS__' => (
int) $now,
8388 '__NOW_TMS_YMD__' =>
dol_print_date($now,
'day', 0, $outputlangs),
8389 '__DAY__' => (
string) $tmp[
'mday'],
8390 '__DAY_TEXT__' => $daytext,
8391 '__DAY_TEXT_SHORT__' =>
dol_trunc($daytext, 3,
'right',
'UTF-8', 1),
8392 '__DAY_TEXT_MIN__' =>
dol_trunc($daytext, 1,
'right',
'UTF-8', 1),
8393 '__MONTH__' => (
string) $tmp[
'mon'],
8394 '__MONTH_TEXT__' => $outputlangs->trans(
'Month'.sprintf(
"%02d", $tmp[
'mon'])),
8395 '__MONTH_TEXT_SHORT__' => $outputlangs->trans(
'MonthShort'.sprintf(
"%02d", $tmp[
'mon'])),
8396 '__MONTH_TEXT_MIN__' => $outputlangs->trans(
'MonthVeryShort'.sprintf(
"%02d", $tmp[
'mon'])),
8397 '__YEAR__' => (
string) $tmp[
'year'],
8398 '__PREVIOUS_DAY__' => (
string) $tmp2[
'day'],
8399 '__PREVIOUS_MONTH__' => (
string) $tmp3[
'month'],
8400 '__PREVIOUS_YEAR__' => (
string) ($tmp[
'year'] - 1),
8401 '__NEXT_DAY__' => (
string) $tmp4[
'day'],
8402 '__NEXT_MONTH__' => (
string) $tmp5[
'month'],
8403 '__NEXT_YEAR__' => (
string) ($tmp[
'year'] + 1),
8407 if (isModEnabled(
'multicompany')) {
8408 $substitutionarray = array_merge($substitutionarray, array(
'__ENTITY_ID__' => $conf->entity));
8410 if ((empty($exclude) || !in_array(
'system', $exclude)) && (empty($include) || in_array(
'user', $include))) {
8411 $substitutionarray[
'__DOL_MAIN_URL_ROOT__'] = DOL_MAIN_URL_ROOT;
8412 $substitutionarray[
'__(AnyTranslationKey)__'] = $outputlangs->trans(
'TranslationOfKey');
8413 $substitutionarray[
'__(AnyTranslationKey|langfile)__'] = $outputlangs->trans(
'TranslationOfKey').
' (load also language file before)';
8414 $substitutionarray[
'__[AnyConstantKey]__'] = $outputlangs->trans(
'ValueOfConstantKey');
8417 return $substitutionarray;
8436function make_substitutions($text, $substitutionarray, $outputlangs =
null, $converttextinhtmlifnecessary = 0)
8438 global $conf, $langs;
8440 if (!is_array($substitutionarray)) {
8441 return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
8444 if (empty($outputlangs)) {
8445 $outputlangs = $langs;
8455 if (is_object($outputlangs)) {
8457 while (preg_match(
'/__\(([^\)]+)\)__/', $text, $reg)) {
8459 $tmp = explode(
'|', $reg[1]);
8460 if (!empty($tmp[1])) {
8461 $outputlangs->load($tmp[1]);
8464 $value = $outputlangs->transnoentitiesnoconv($reg[1]);
8466 if (empty($converttextinhtmlifnecessary)) {
8468 $text = preg_replace(
'/__\('.preg_quote($reg[1],
'/').
'\)__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
8482 $text = preg_replace(
'/__\('.preg_quote($reg[1],
'/').
'\)__/', $value, $text);
8490 while (preg_match(
'/__\[([^\]]+)\]__/', $text, $reg)) {
8491 $keyfound = $reg[1];
8493 $value =
'*****forbidden*****';
8495 $value = empty($conf->global->$keyfound) ?
'' : $conf->global->$keyfound;
8498 if (empty($converttextinhtmlifnecessary)) {
8500 $text = preg_replace(
'/__\['.preg_quote($keyfound,
'/').
'\]__/', $msgishtml ?
dol_htmlentitiesbr($value) : $value, $text);
8513 $text = preg_replace(
'/__\['.preg_quote($keyfound,
'/').
'\]__/', $value, $text);
8518 foreach ($substitutionarray as $key => $value) {
8519 if (!isset($value)) {
8523 if (($key ==
'__USER_SIGNATURE__' || $key ==
'__SENDEREMAIL_SIGNATURE__') && (!empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))) {
8527 if (empty($converttextinhtmlifnecessary)) {
8528 $text = str_replace(
"$key",
"$value", $text);
8540 $text = str_replace(
"$key",
"$value", $text);
8561 global $conf, $user;
8563 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
8568 $dirsubstitutions = array_merge(array(), (array) $conf->modules_parts[
'substitutions']);
8570 foreach ($dirsubstitutions as $reldir) {
8578 $substitfiles =
dol_dir_list($dir,
'files', 0,
'functions_');
8579 foreach ($substitfiles as $substitfile) {
8581 if (preg_match(
'/functions_(.*)\.lib\.php/i', $substitfile[
'name'], $reg)) {
8584 dol_syslog(
"Library ".$substitfile[
'name'].
" found into ".$dir);
8586 require_once $dir.$substitfile[
'name'];
8588 $function_name = $module.
"_".$callfunc;
8589 if (function_exists($function_name)) {
8590 $function_name($substitutionarray, $outputlangs, $object, $parameters);
8595 if (!empty($conf->global->ODT_ENABLE_ALL_TAGS_IN_SUBSTITUTIONS)) {
8598 foreach ($substitutionarray as $key => $value) {
8599 $tags .=
'{'.$key.
'} => '.$value.
"\n";
8601 $substitutionarray = array_merge($substitutionarray, array(
'__ALL_TAGS__' => $tags));
8616 print
get_date_range($date_start, $date_end, $format, $outputlangs);
8629function get_date_range($date_start, $date_end, $format =
'', $outputlangs =
'', $withparenthesis = 1)
8635 if (!is_object($outputlangs)) {
8636 $outputlangs = $langs;
8639 if ($date_start && $date_end) {
8640 $out .= ($withparenthesis ?
' (' :
'').$outputlangs->transnoentitiesnoconv(
'DateFromTo',
dol_print_date($date_start, $format,
false, $outputlangs),
dol_print_date($date_end, $format,
false, $outputlangs)).($withparenthesis ?
')' :
'');
8642 if ($date_start && !$date_end) {
8643 $out .= ($withparenthesis ?
' (' :
'').$outputlangs->transnoentitiesnoconv(
'DateFrom',
dol_print_date($date_start, $format,
false, $outputlangs)).($withparenthesis ?
')' :
'');
8645 if (!$date_start && $date_end) {
8646 $out .= ($withparenthesis ?
' (' :
'').$outputlangs->transnoentitiesnoconv(
'DateUntil',
dol_print_date($date_end, $format,
false, $outputlangs)).($withparenthesis ?
')' :
'');
8666 if ($nameorder < 0) {
8667 $nameorder = (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION) ? 1 : 0);
8669 if ($nameorder == 1) {
8671 if ($firstname && $lastname) {
8675 } elseif ($nameorder == 2 || $nameorder == 3) {
8677 if (empty($ret) && $nameorder == 3) {
8682 if (empty($ret) && $nameorder == 5) {
8685 if ($nameorder == 0) {
8686 if ($firstname && $lastname) {
8710 if (!is_array($mesgs)) {
8713 if (!empty($noduplicate) && isset($_SESSION[
'dol_events'][$style]) && in_array($mesgs, $_SESSION[
'dol_events'][$style])) {
8716 $_SESSION[
'dol_events'][$style][] = $mesgs;
8720 foreach ($mesgs as $mesg) {
8722 if (!empty($noduplicate) && isset($_SESSION[
'dol_events'][$style]) && in_array($mesg, $_SESSION[
'dol_events'][$style])) {
8725 $_SESSION[
'dol_events'][$style][] = $mesg;
8745 if (empty($mesg) && empty($mesgs)) {
8746 dol_syslog(
"Try to add a message in stack, but value to add is empty message", LOG_WARNING);
8753 if (empty($messagekey) || empty($_COOKIE[
"DOLHIDEMESSAGE".$messagekey])) {
8754 if (!in_array((
string) $style, array(
'mesgs',
'warnings',
'errors'))) {
8755 dol_print_error(
'',
'Bad parameter style='.$style.
' for setEventMessages');
8757 if (empty($mesgs)) {
8760 if (!empty($mesg) && !in_array($mesg, $mesgs)) {
8781 if (isset($_SESSION[
'dol_events'][
'mesgs'])) {
8782 if (empty($disabledoutputofmessages)) {
8785 unset($_SESSION[
'dol_events'][
'mesgs']);
8788 if (isset($_SESSION[
'dol_events'][
'errors'])) {
8789 if (empty($disabledoutputofmessages)) {
8792 unset($_SESSION[
'dol_events'][
'errors']);
8796 if (isset($_SESSION[
'dol_events'][
'warnings'])) {
8797 if (empty($disabledoutputofmessages)) {
8800 unset($_SESSION[
'dol_events'][
'warnings']);
8820 global $conf, $langs;
8825 $divstart = $divend =
'';
8828 if ((empty($conf->use_javascript_ajax) || !empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) || $keepembedded) && !preg_match(
'/<div class=".*">/i', $out)) {
8829 $divstart =
'<div class="'.$style.
' clearboth">';
8833 if ((is_array($mesgarray) && count($mesgarray)) || $mesgstring) {
8834 $langs->load(
"errors");
8836 if (is_array($mesgarray) && count($mesgarray)) {
8837 foreach ($mesgarray as $message) {
8839 $out .= $langs->trans($message);
8840 if ($ret < count($mesgarray)) {
8847 $out .= $langs->trans($mesgstring);
8853 if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_DISABLE_JQUERY_JNOTIFY) && empty($keepembedded)) {
8854 $return =
'<script nonce="'.getNonce().
'">
8855 $(document).ready(function() {
8856 var block = '.(!empty($conf->global->MAIN_USE_JQUERY_BLOCKUI) ?
"true" :
"false").
'
8860 /* jnotify(message, preset of message type, keepmessage) */
8862 "'.($style ==
"ok" ? 3000 : $style).
'",
8863 '.($style ==
"ok" ?
"false" :
"true").
',
8864 { remove: function (){} } );
8907 if (empty($mesgstring) && (!is_array($mesgarray) || count($mesgarray) == 0)) {
8913 if (is_array($mesgarray)) {
8914 foreach ($mesgarray as $val) {
8915 if ($val && preg_match(
'/class="error"/i', $val)) {
8919 if ($val && preg_match(
'/class="warning"/i', $val)) {
8924 } elseif ($mesgstring && preg_match(
'/class="error"/i', $mesgstring)) {
8926 } elseif ($mesgstring && preg_match(
'/class="warning"/i', $mesgstring)) {
8929 if ($style ==
'error') {
8932 if ($style ==
'warning') {
8936 if ($iserror || $iswarning) {
8938 $mesgstring = preg_replace(
'/<\/div><div class="(error|warning)">/',
'<br>', $mesgstring);
8939 $mesgstring = preg_replace(
'/<div class="(error|warning)">/',
'', $mesgstring);
8940 $mesgstring = preg_replace(
'/<\/div>/',
'', $mesgstring);
8942 if (is_array($mesgarray)) {
8943 $newmesgarray = array();
8944 foreach ($mesgarray as $val) {
8945 if (is_string($val)) {
8946 $tmpmesgstring = preg_replace(
'/<\/div><div class="(error|warning)">/',
'<br>', $val);
8947 $tmpmesgstring = preg_replace(
'/<div class="(error|warning)">/',
'', $tmpmesgstring);
8948 $tmpmesgstring = preg_replace(
'/<\/div>/',
'', $tmpmesgstring);
8949 $newmesgarray[] = $tmpmesgstring;
8951 dol_syslog(
"Error call of dol_htmloutput_mesg with an array with a value that is not a string", LOG_WARNING);
8954 $mesgarray = $newmesgarray;
8956 print
get_htmloutput_mesg($mesgstring, $mesgarray, ($iserror ?
'error' :
'warning'), $keepembedded);
8992function dol_sort_array(&$array, $index, $order =
'asc', $natsort = 0, $case_sensitive = 0, $keepindex = 0)
8995 $order = strtolower($order);
8997 if (is_array($array)) {
8998 $sizearray = count($array);
8999 if ($sizearray > 0) {
9001 foreach (array_keys($array) as $key) {
9002 if (is_object($array[$key])) {
9003 $temp[$key] = empty($array[$key]->$index) ? 0 : $array[$key]->$index;
9005 $temp[$key] = empty($array[$key][$index]) ? 0 : $array[$key][$index];
9007 if ($natsort == -1) {
9008 $temp[$key] =
'___'.$temp[$key];
9012 if (empty($natsort) || $natsort == -1) {
9013 if ($order ==
'asc') {
9019 if ($case_sensitive) {
9024 if ($order !=
'asc') {
9025 $temp = array_reverse($temp,
true);
9031 foreach (array_keys($temp) as $key) {
9032 (is_numeric($key) && empty($keepindex)) ? $sorted[] = $array[$key] : $sorted[$key] = $array[$key];
9050 $str = (string) $str;
9054 for ($i = 0; $i < $strLength; $i++) {
9055 if (ord($str[$i]) < 0x80) {
9057 } elseif ((ord($str[$i]) & 0xE0) == 0xC0) {
9059 } elseif ((ord($str[$i]) & 0xF0) == 0xE0) {
9061 } elseif ((ord($str[$i]) & 0xF8) == 0xF0) {
9063 } elseif ((ord($str[$i]) & 0xFC) == 0xF8) {
9065 } elseif ((ord($str[$i]) & 0xFE) == 0xFC) {
9070 for ($j = 0; $j < $n; $j++) {
9071 if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80)) {
9091 return preg_match(
'//u', $str) ? true :
false;
9103 if (function_exists(
'mb_check_encoding')) {
9105 if (!mb_check_encoding($str,
'ASCII')) {
9109 if (preg_match(
'/[^\x00-\x7f]/', $str)) {
9129 $tmp = ini_get(
"unicode.filesystem_encoding");
9130 if (empty($tmp) && !empty($_SERVER[
"WINDIR"])) {
9131 $tmp =
'iso-8859-1';
9136 if (!empty($conf->global->MAIN_FILESYSTEM_ENCODING)) {
9137 $tmp = $conf->global->MAIN_FILESYSTEM_ENCODING;
9140 if ($tmp ==
'iso-8859-1') {
9141 return mb_convert_encoding($str,
'ISO-8859-1',
'UTF-8');
9162function dol_getIdFromCode($db, $key, $tablename, $fieldkey =
'code', $fieldid =
'id', $entityfilter = 0, $filters =
'', $useCache =
true)
9164 global $cache_codes;
9172 if ($useCache && isset($cache_codes[$tablename][$fieldkey][$fieldid][$entityfilter][$filters][$key])) {
9173 return $cache_codes[$tablename][$fieldkey][$fieldid][$entityfilter][$filters][$key];
9176 dol_syslog(
'dol_getIdFromCode (value for field '.$fieldid.
' from key '.$key.
' not found into cache)', LOG_DEBUG);
9178 $sql =
"SELECT ".$fieldid.
" as valuetoget";
9179 $sql .=
" FROM ".MAIN_DB_PREFIX.$tablename;
9180 $sql .=
" WHERE ".$fieldkey.
" = '".$db->escape($key).
"'";
9181 if (!empty($entityfilter)) {
9182 $sql .=
" AND entity IN (".getEntity($tablename).
")";
9188 $resql = $db->query($sql);
9190 $obj = $db->fetch_object($resql);
9193 $valuetoget = $obj->valuetoget;
9197 $cache_codes[$tablename][$fieldkey][$fieldid][$entityfilter][$filters][$key] = $valuetoget;
9213 global $user, $conf, $langs;
9219 if (isset($strToEvaluate) && $strToEvaluate !==
'') {
9222 $rep =
dol_eval($strToEvaluate, 1, 1,
'1');
9223 $rights = $rep && (!is_string($rep) || strpos($rep,
'Bad string syntax to evaluate') ===
false);
9239function dol_eval($s, $returnvalue = 0, $hideerrors = 1, $onlysimplestring =
'1')
9242 global $db, $langs, $user, $conf, $website, $websitepage;
9243 global $action, $mainmenu, $leftmenu;
9245 global $objectoffield;
9255 if ($onlysimplestring ==
'1') {
9259 if (preg_match(
'/[^a-z0-9\s'.preg_quote(
'^$_+-.*>&|=!?():"\',/@',
'/').
']/i', $s)) {
9261 return 'Bad string syntax to evaluate (found chars that are not chars for simplestring): '.$s;
9263 dol_syslog(
'Bad string syntax to evaluate (found chars that are not chars for simplestring): '.$s);
9270 } elseif ($onlysimplestring ==
'2') {
9272 if (preg_match(
'/[^a-z0-9\s'.preg_quote(
'^$_+-.*>&|=!?():"\',/@[]',
'/').
']/i', $s)) {
9274 return 'Bad string syntax to evaluate (found chars that are not chars for simplestring): '.$s;
9276 dol_syslog(
'Bad string syntax to evaluate (found chars that are not chars for simplestring): '.$s);
9284 if (is_array($s) || $s ===
'Array') {
9285 return 'Bad string syntax to evaluate (value is Array) '.var_export($s,
true);
9287 if (strpos($s,
'::') !==
false) {
9289 return 'Bad string syntax to evaluate (double : char is forbidden): '.$s;
9291 dol_syslog(
'Bad string syntax to evaluate (double : char is forbidden): '.$s);
9295 if (strpos($s,
'`') !==
false) {
9297 return 'Bad string syntax to evaluate (backtick char is forbidden): '.$s;
9299 dol_syslog(
'Bad string syntax to evaluate (backtick char is forbidden): '.$s);
9303 if (preg_match(
'/[^0-9]+\.[^0-9]+/', $s)) {
9305 return 'Bad string syntax to evaluate (dot char is forbidden): '.$s;
9307 dol_syslog(
'Bad string syntax to evaluate (dot char is forbidden): '.$s);
9313 $forbiddenphpstrings = array(
'$$');
9314 $forbiddenphpstrings = array_merge($forbiddenphpstrings, array(
'_ENV',
'_SESSION',
'_COOKIE',
'_GET',
'_POST',
'_REQUEST',
'ReflectionFunction'));
9316 $forbiddenphpfunctions = array(
"exec",
"passthru",
"shell_exec",
"system",
"proc_open",
"popen");
9317 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"dol_eval",
"executeCLI",
"verifCond"));
9318 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"base64_decode",
"rawurldecode",
"urldecode",
"str_rot13",
"hex2bin"));
9319 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"fopen",
"file_put_contents",
"fputs",
"fputscsv",
"fwrite",
"fpassthru",
"require",
"include",
"mkdir",
"rmdir",
"symlink",
"touch",
"unlink",
"umask"));
9320 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"get_defined_functions",
"get_defined_vars",
"get_defined_constants",
"get_declared_classes"));
9321 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"function",
"call_user_func"));
9322 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"require",
"include",
"require_once",
"include_once"));
9323 $forbiddenphpfunctions = array_merge($forbiddenphpfunctions, array(
"eval",
"create_function",
"assert",
"mb_ereg_replace"));
9325 $forbiddenphpmethods = array(
'invoke',
'invokeArgs');
9327 $forbiddenphpregex =
'global\s+\$|\b('.implode(
'|', $forbiddenphpfunctions).
')\b';
9329 $forbiddenphpmethodsregex =
'->('.implode(
'|', $forbiddenphpmethods).
')';
9332 $oldstringtoclean = $s;
9333 $s = str_ireplace($forbiddenphpstrings,
'__forbiddenstring__', $s);
9334 $s = preg_replace(
'/'.$forbiddenphpregex.
'/i',
'__forbiddenstring__', $s);
9335 $s = preg_replace(
'/'.$forbiddenphpmethodsregex.
'/i',
'__forbiddenstring__', $s);
9337 }
while ($oldstringtoclean != $s);
9339 if (strpos($s,
'__forbiddenstring__') !==
false) {
9340 dol_syslog(
'Bad string syntax to evaluate: '.$s, LOG_WARNING);
9342 return 'Bad string syntax to evaluate: '.$s;
9344 dol_syslog(
'Bad string syntax to evaluate: '.$s);
9352 return @eval(
'return '.$s.
';');
9354 return eval(
'return '.$s.
';');
9363 }
catch (Error $e) {
9364 $error =
'dol_eval try/catch error : ';
9365 $error .= $e->getMessage();
9378 return (trim($element) !=
'');
9391 if (empty($codelang)) {
9395 if ($codelang ==
'auto') {
9396 return '<span class="fa fa-language"></span>';
9399 $langtocountryflag = array(
9401 'ca_ES' =>
'catalonia',
9405 'sw_SW' =>
'unknown',
9415 if (isset($langtocountryflag[$codelang])) {
9416 $flagImage = $langtocountryflag[$codelang];
9418 $tmparray = explode(
'_', $codelang);
9419 $flagImage = empty($tmparray[1]) ? $tmparray[0] : $tmparray[1];
9422 return img_picto_common($codelang,
'flags/'.strtolower($flagImage).
'.png', $moreatt, 0, $notitlealt);
9436 if (empty($countrycode)) {
9440 if (strtoupper($countrycode) ==
'MQ') {
9443 if (strtoupper($countrycode) ==
'SE') {
9446 if (strtoupper($countrycode) ==
'CH') {
9447 if ($mysoc->country_code ==
'FR') {
9450 if ($mysoc->country_code ==
'DE') {
9453 if ($mysoc->country_code ==
'IT') {
9635 $buildprimarykeytotest = strtolower($countrycode).
'-'.strtoupper($countrycode);
9636 if (in_array($buildprimarykeytotest, $locales)) {
9637 return strtolower($countrycode).
'_'.strtoupper($countrycode);
9640 if (function_exists(
'locale_get_primary_language') && function_exists(
'locale_get_region')) {
9641 foreach ($locales as $locale) {
9642 $locale_language = locale_get_primary_language($locale);
9643 $locale_region = locale_get_region($locale);
9644 if (strtoupper($countrycode) == $locale_region) {
9646 return strtolower($locale_language).
'_'.strtoupper($locale_region);
9650 dol_syslog(
"Warning Exention php-intl is not available", LOG_WARNING);
9688 global $hookmanager, $db;
9690 if (isset($conf->modules_parts[
'tabs'][$type]) && is_array($conf->modules_parts[
'tabs'][$type])) {
9691 foreach ($conf->modules_parts[
'tabs'][$type] as $value) {
9692 $values = explode(
':', $value);
9695 if ($mode ==
'add' && !preg_match(
'/^\-/', $values[1])) {
9696 if (count($values) == 6) {
9700 if ($values[0] != $type) {
9706 if ($filterorigmodule) {
9707 if (strpos($values[3],
'@')) {
9708 if ($filterorigmodule !=
'external') {
9712 if ($filterorigmodule !=
'core') {
9717 $langs->load($values[3]);
9719 if (preg_match(
'/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
9721 $substitutionarray = array();
9726 $labeltemp = explode(
',', $values[2]);
9727 $label = $langs->trans($labeltemp[0]);
9729 if (!empty($labeltemp[1]) && is_object($object) && !empty($object->id)) {
9731 $classtoload = $labeltemp[1];
9732 if (class_exists($classtoload)) {
9733 $obj =
new $classtoload($db);
9734 $function = $labeltemp[3];
9735 if ($obj && $function && method_exists($obj, $function)) {
9736 $nbrec = $obj->$function($object->id, $obj);
9737 if (!empty($nbrec)) {
9738 $label .=
'<span class="badge marginleftonlyshort">'.$nbrec.
'</span>';
9745 $head[$h][0] =
dol_buildpath(preg_replace(
'/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id :
''), $values[5]), 1);
9746 $head[$h][1] = $label;
9747 $head[$h][2] = str_replace(
'+',
'', $values[1]);
9750 } elseif (count($values) == 5) {
9751 dol_syslog(
'Passing 5 values in tabs module_parts is deprecated. Please update to 6 with permissions.', LOG_WARNING);
9753 if ($values[0] != $type) {
9757 if ($filterorigmodule) {
9758 if (strpos($values[3],
'@')) {
9759 if ($filterorigmodule !=
'external') {
9763 if ($filterorigmodule !=
'core') {
9768 $langs->load($values[3]);
9770 if (preg_match(
'/SUBSTITUTION_([^_]+)/i', $values[2], $reg)) {
9771 $substitutionarray = array();
9775 $label = $langs->trans($values[2]);
9778 $head[$h][0] =
dol_buildpath(preg_replace(
'/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id :
''), $values[4]), 1);
9779 $head[$h][1] = $label;
9780 $head[$h][2] = str_replace(
'+',
'', $values[1]);
9783 } elseif ($mode ==
'remove' && preg_match(
'/^\-/', $values[1])) {
9784 if ($values[0] != $type) {
9787 $tabname = str_replace(
'-',
'', $values[1]);
9788 foreach ($head as $key => $val) {
9789 $condition = (!empty($values[3]) ?
verifCond($values[3]) : 1);
9791 if ($head[$key][2] == $tabname && $condition) {
9801 if (!empty($hookmanager)) {
9802 $parameters = array(
'object' => $object,
'mode' => $mode,
'head' => &$head,
'filterorigmodule' => $filterorigmodule);
9803 $reshook = $hookmanager->executeHooks(
'completeTabsHead', $parameters);
9805 $head = $hookmanager->resArray;
9807 $head = array_merge($head, $hookmanager->resArray);
9826 global $conf, $hookmanager, $user, $debugbar;
9828 global $micro_start_time;
9830 if ($zone ==
'private') {
9831 print
"\n".
'<!-- Common footer for private page -->'.
"\n";
9833 print
"\n".
'<!-- Common footer for public page -->'.
"\n";
9837 print
"\n<!-- A div to store page_y POST parameter -->\n";
9838 print
'<div id="page_y" style="display: none;">'.(GETPOST(
'page_y') ?
GETPOST(
'page_y') :
'').
'</div>'.
"\n";
9840 $parameters = array();
9841 $reshook = $hookmanager->executeHooks(
'printCommonFooter', $parameters);
9842 if (empty($reshook)) {
9843 if (!empty($conf->global->MAIN_HTML_FOOTER)) {
9844 print $conf->global->MAIN_HTML_FOOTER.
"\n";
9848 if (!empty($conf->use_javascript_ajax)) {
9849 print
"\n<!-- A script section to add menuhider handler on backoffice, manage focus and madatory fields, tuning info, ... -->\n";
9850 print
'<script>'.
"\n";
9851 print
'jQuery(document).ready(function() {'.
"\n";
9853 if ($zone ==
'private' && empty($conf->dol_use_jmobile)) {
9855 print
'/* JS CODE TO ENABLE to manage handler to switch left menu page (menuhider) */'.
"\n";
9856 print
'jQuery("li.menuhider").click(function(event) {';
9857 print
' if (!$( "body" ).hasClass( "sidebar-collapse" )){ event.preventDefault(); }'.
"\n";
9858 print
' console.log("We click on .menuhider");'.
"\n";
9859 print
' $("body").toggleClass("sidebar-collapse")'.
"\n";
9864 if ($action ==
'create' || $action ==
'edit' || (empty($action) && (preg_match(
'/new\.php/', $_SERVER[
"PHP_SELF"]))) || ((empty($action) || $action ==
'addline') && (preg_match(
'/card\.php/', $_SERVER[
"PHP_SELF"])))) {
9865 print
'/* JS CODE TO ENABLE to manage focus and mandatory form fields */'.
"\n";
9866 $relativepathstring = $_SERVER[
"PHP_SELF"];
9868 if (constant(
'DOL_URL_ROOT')) {
9869 $relativepathstring = preg_replace(
'/^'.preg_quote(constant(
'DOL_URL_ROOT'),
'/').
'/',
'', $relativepathstring);
9871 $relativepathstring = preg_replace(
'/^\//',
'', $relativepathstring);
9872 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
9874 if (!empty($user->default_values[$relativepathstring][
'focus'])) {
9875 foreach ($user->default_values[$relativepathstring][
'focus'] as $defkey => $defval) {
9877 if ($defkey !=
'_noquery_') {
9878 $tmpqueryarraytohave = explode(
'&', $defkey);
9880 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
9881 $tmpquerytohaveparam = explode(
'=', $tmpquerytohave);
9883 if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] !=
GETPOST($tmpquerytohaveparam[0]))) {
9896 foreach ($defval as $paramkey => $paramval) {
9898 print
'jQuery("input[name=\''.$paramkey.
'\']
").focus();'."\n
";
9899 print 'jQuery("textarea[
name=\
''.$paramkey.
'\']
").focus();'."\n
";
9900 print 'jQuery("select[
name=\
''.$paramkey.
'\']
").focus();'."\n
"; // Not really usefull, but we keep it in case of.
9905 if (!empty($user->default_values[$relativepathstring]['mandatory'])) {
9906 foreach ($user->default_values[$relativepathstring]['mandatory'] as $defkey => $defval) {
9908 if ($defkey != '_noquery_') {
9909 $tmpqueryarraytohave = explode('&', $defkey);
9911 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
9912 $tmpquerytohaveparam = explode('=', $tmpquerytohave);
9913 //print "console.log(
'".$tmpquerytohaveparam[0]." ".$tmpquerytohaveparam[1]." ".GETPOST($tmpquerytohaveparam[0])."');
";
9914 if (!GETPOSTISSET($tmpquerytohaveparam[0]) || ($tmpquerytohaveparam[1] != GETPOST($tmpquerytohaveparam[0]))) {
9921 //var_dump($defkey.'-'.$qualified);
9927 foreach ($defval as $paramkey => $paramval) {
9928 // Add property 'required' on input
9929 print 'jQuery("input[
name=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";
9930 print 'jQuery("textarea[
name=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";
9931 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
";
9932 print 'jQuery("select[
name=\
''.$paramkey.
'\']
").prop(\'required\',true);'."\n
";
9933 print 'jQuery("select[
name=\
''.$paramkey.
'\'] option[value=\
'-1\']").prop(\'value\', \'\');'.
"\n";
9934 print
'jQuery("select[name=\''.$paramkey.
'\'] option[value=\
'0\']").prop(\'value\', \'\');'.
"\n";
9937 print
'jQuery(":input[name=\'' . $paramkey .
'\']
").closest("tr
").find("td:first
").addClass("fieldrequired
");' . "\n
";
9947 if (!empty($_SERVER['MAIN_SHOW_TUNING_INFO']) || !empty($conf->global->MAIN_SHOW_TUNING_INFO)) {
9950 print 'window.console && console.log("';
9951 if (!empty($conf->global->MEMCACHED_SERVER)) {
9952 print 'MEMCACHED_SERVER=
'.$conf->global->MEMCACHED_SERVER.' -
';
9954 print 'MAIN_OPTIMIZE_SPEED=
'.(isset($conf->global->MAIN_OPTIMIZE_SPEED) ? $conf->global->MAIN_OPTIMIZE_SPEED : 'off
');
9955 if (!empty($micro_start_time)) { // Works only if MAIN_SHOW_TUNING_INFO is defined at $_SERVER level. Not in global variable.
9956 $micro_end_time = microtime(true);
9957 print ' - Build time:
'.ceil(1000 * ($micro_end_time - $micro_start_time)).' ms
';
9960 if (function_exists("memory_get_usage")) {
9961 print ' - Mem:
'.memory_get_usage(); // Do not use true here, it seems it takes the peak amount
9963 if (function_exists("memory_get_peak_usage")) {
9964 print ' - Real mem peak:
'.memory_get_peak_usage(true);
9966 if (function_exists("zend_loader_file_encoded")) {
9967 print ' - Zend encoded file:
'.(zend_loader_file_encoded() ? 'yes
' : 'no
');
9972 print "\n
".'</script>'."\n
";
9975 // TODO Add a hook here
9976 if (isModEnabled('google') && !empty($conf->global->MAIN_GOOGLE_AN_ID)) {
9977 $tmptagarray = explode(',', $conf->global->MAIN_GOOGLE_AN_ID);
9978 foreach ($tmptagarray as $tmptag) {
9980 print "<!-- JS CODE TO ENABLE
for google analtics tag -->\n
";
9982 <!-- Global site tag (gtag.js) - Google Analytics -->
9983 <script nonce="'.getNonce().'" async src="https:
9985 window.dataLayer = window.dataLayer || [];
9986 function gtag(){dataLayer.push(arguments);}
9987 gtag(\
'js\', new Date());
9989 gtag(\'config\', \''.trim($tmptag).
'\');
9996 // Add Xdebug coverage of code
9997 if (defined('XDEBUGCOVERAGE
')) {
9998 print_r(xdebug_get_code_coverage());
10001 // Add DebugBar data
10002 if (!empty($user->rights->debugbar->read) && is_object($debugbar)) {
10003 $debugbar['time
']->stopMeasure('pageaftermaster
');
10004 print '<!-- Output debugbar data -->
'."\n";
10005 $renderer = $debugbar->getRenderer();
10006 print $debugbar->getRenderer()->render();
10007 } elseif (count($conf->logbuffer)) { // If there is some logs in buffer to show
10009 print "<!-- Start of log output\n";
10010 //print '<div
class=
"hidden">
'."\n";
10011 foreach ($conf->logbuffer as $logline) {
10012 print $logline."<br>\n";
10014 //print '</div>
'."\n";
10015 print "End of log output -->\n";
10029function dolExplodeIntoArray($string, $delimiter = ';
', $kv = '=
')
10031 if (is_null($string)) {
10035 if (preg_match('/^\[.*\]$/sm
', $delimiter) || preg_match('/^\(.*\)$/sm
', $delimiter)) {
10036 // This is a regex string
10037 $newdelimiter = $delimiter;
10039 // This is a simple string
10040 $newdelimiter = preg_quote($delimiter, '/
');
10043 if ($a = preg_split('/
'.$newdelimiter.'/
', $string)) {
10045 foreach ($a as $s) { // each part
10047 if ($pos = strpos($s, $kv)) { // key/value delimiter
10048 $ka[trim(substr($s, 0, $pos))] = trim(substr($s, $pos + strlen($kv)));
10049 } else { // key delimiter not found
10067function dol_set_focus($selector)
10069 print "\n".'<!-- Set focus onto a specific field -->
'."\n";
10070 print '<script nonce=
"'.getNonce().'">jQuery(document).ready(
function() { jQuery(
"'.dol_escape_js($selector).'").focus(); });</script>
'."\n";
10081function dol_getmypid()
10083 if (!function_exists('getmypid
')) {
10084 return mt_rand(99900000, 99965535);
10086 return getmypid(); // May be a number on 64 bits (depending on OS)
10108function natural_search($fields, $value, $mode = 0, $nofirstand = 0)
10110 global $db, $langs;
10112 $value = trim($value);
10115 $value = preg_replace('/\*/
', '%
', $value); // Replace * with %
10118 $value = preg_replace('/([!<>=]+)\s+([0-9
'.preg_quote($langs->trans("DecimalSeparator"), '/
').'\-])/
', '\1\2
', $value); // Clean string '< 10
' into '<10
' so we can then explode on space to get all tests to do
10121 $value = preg_replace('/\s*\|\s*/
', '|
', $value);
10123 //natural mode search type 3 allow spaces into search ...
10124 if ($mode == 3 || $mode == -3) {
10125 $crits = explode(',
', $value);
10127 $crits = explode(' ', $value);
10130 if (!is_array($fields)) {
10131 $fields = array($fields);
10134 $i1 = 0; // count the nb of and criteria added (all fields / criterias)
10135 foreach ($crits as $crit) { // Loop on each AND criteria
10136 $crit = trim($crit);
10137 $i2 = 0; // count the nb of valid criteria added for this this first criteria
10139 foreach ($fields as $field) {
10141 $tmpcrits = explode('|
', $crit);
10142 $i3 = 0; // count the nb of valid criteria added for this current field
10143 foreach ($tmpcrits as $tmpcrit) {
10144 if ($tmpcrit !== '0
' && empty($tmpcrit)) {
10147 $tmpcrit = trim($tmpcrit);
10149 $newres .= (($i2 > 0 || $i3 > 0) ? ' OR
' : '');
10152 $newcrit = preg_replace('/([!<>=]+)/
', '', $tmpcrit);
10155 preg_match('/([!<>=]+)/
', $tmpcrit, $reg);
10156 if (!empty($reg[1])) {
10157 $operator = $reg[1];
10159 if ($newcrit != '') {
10160 $numnewcrit = price2num($newcrit);
10161 if (is_numeric($numnewcrit)) {
10162 $newres .= $field.' '.$operator.' '.((float) $numnewcrit); // should be a numeric
10164 $newres .= '1 = 2
'; // force false, we received a corrupted data
10166 $i3++; // a criteria was added to string
10169 $i2++; // a criteria for 1 more field was added to string
10170 } elseif ($mode == 2 || $mode == -2) {
10171 $crit = preg_replace('/[^0-9,]/
', '', $crit); // ID are always integer
10172 $newres .= ($i2 > 0 ? ' OR
' : '').$field." ".($mode == -2 ? 'NOT
' : '');
10173 $newres .= $crit ? "IN (".$db->sanitize($db->escape($crit)).")" : "IN (0)";
10175 $newres .= ' OR
'.$field.' IS NULL
';
10177 $i2++; // a criteria for 1 more field was added to string
10178 } elseif ($mode == 3 || $mode == -3) {
10179 $tmparray = explode(',
', $crit);
10180 if (count($tmparray)) {
10182 foreach ($tmparray as $val) {
10185 $listofcodes .= ($listofcodes ? ',
' : '');
10186 $listofcodes .= "'".$db->escape($val)."'";
10189 $newres .= ($i2 > 0 ? ' OR
' : '').$field." ".($mode == -3 ? 'NOT
' : '')."IN (".$db->sanitize($listofcodes, 1, 0, 1).")";
10190 $i2++; // a criteria for 1 more field was added to string
10193 $newres .= ' OR
'.$field.' IS NULL
';
10195 } elseif ($mode == 4) {
10196 $tmparray = explode(',
', $crit);
10197 if (count($tmparray)) {
10199 foreach ($tmparray as $val) {
10202 $newres .= ($i2 > 0 ? " OR (" : "(").$field." LIKE '".$db->escape($val).",%
'";
10203 $newres .= ' OR
'.$field." = '".$db->escape($val)."'";
10204 $newres .= ' OR
'.$field." LIKE '%,
".$db->escape($val)."'";
10205 $newres .= ' OR
'.$field." LIKE '%,
".$db->escape($val).",%
'";
10207 $i2++; // a criteria for 1 more field was added to string (we can add several citeria for the same field as it is a multiselect search criteria)
10211 } else { // $mode=0
10212 $tmpcrits = explode('|
', $crit);
10213 $i3 = 0; // count the nb of valid criteria added for the current couple criteria/field
10214 foreach ($tmpcrits as $tmpcrit) { // loop on each OR criteria
10215 if ($tmpcrit !== '0
' && empty($tmpcrit)) {
10218 $tmpcrit = trim($tmpcrit);
10220 if ($tmpcrit == '^$
' || strpos($crit, '!
') === 0) { // If we search empty, we must combined different OR fields with AND
10221 $newres .= (($i2 > 0 || $i3 > 0) ? ' AND
' : '');
10223 $newres .= (($i2 > 0 || $i3 > 0) ? ' OR
' : '');
10226 if (preg_match('/\.(
id|
rowid)$/
', $field)) { // Special case for rowid that is sometimes a ref so used as a search field
10227 $newres .= $field." = ".(is_numeric($tmpcrit) ? ((float) $tmpcrit) : '0
');
10229 $tmpcrit2 = $tmpcrit;
10234 if (preg_match('/^!/
', $tmpcrit)) {
10235 $tmps .= $field." NOT LIKE "; // ! as exclude character
10236 $tmpcrit2 = preg_replace('/^!/
', '', $tmpcrit2);
10238 $tmps .= $field." LIKE ";
10242 if (preg_match('/^[\^\$]/', $tmpcrit)) {
10244 $tmpcrit2 = preg_replace('/^[\^\$]/', '', $tmpcrit2);
10246 if (preg_match('/[\^\$]$/', $tmpcrit)) {
10248 $tmpcrit2 = preg_replace('/[\^\$]$/', '', $tmpcrit2);
10251 if ($tmpcrit2 == '' || preg_match('/^!/', $tmpcrit)) {
10255 $newres .= $tmpbefore;
10256 $newres .= $db->escape($tmpcrit2);
10257 $newres .= $tmpafter;
10259 if ($tmpcrit2 == '' || preg_match('/^!/
', $tmpcrit)) {
10260 $newres .= " OR ".$field." IS NULL)";
10267 $i2++; // a criteria for 1 more field was added to string
10272 $res = $res.($res ? ' AND
' : '').($i2 > 1 ? '(
' : '').$newres.($i2 > 1 ? ')
' : '');
10276 $res = ($nofirstand ? "" : " AND ")."(".$res.")";
10287function showDirectDownloadLink($object)
10289 global $conf, $langs;
10292 $url = $object->getLastMainDocLink($object->element);
10294 $out .= img_picto($langs->trans("PublicDownloadLinkDesc"), 'globe
').' <span
class=
"opacitymedium">
'.$langs->trans("DirectDownloadLink").'</span><br>
';
10296 $out .= '<div
class=
"urllink"><input
type=
"text" id=
"directdownloadlink" class=
"quatrevingtpercent" value=
"'.$url.'"></div>
';
10297 $out .= ajax_autoselect("directdownloadlink", 0);
10299 $out .= '<div
class=
"urllink">
'.$langs->trans("FileNotShared").'</div>
';
10313function getImageFileNameForSize($file, $extName, $extImgTarget = '
')
10315 $dirName = dirname($file);
10316 if ($dirName == '.
') {
10320 $fileName = preg_replace('/(\.gif|\.jpeg|\.jpg|\.png|\.bmp|\.webp)$/i
', '', $file); // We remove extension, whatever is its case
10321 $fileName = basename($fileName);
10323 if (empty($extImgTarget)) {
10324 $extImgTarget = (preg_match('/\.jpg$/i
', $file) ? '.jpg
' : '');
10326 if (empty($extImgTarget)) {
10327 $extImgTarget = (preg_match('/\.jpeg$/i
', $file) ? '.jpeg
' : '');
10329 if (empty($extImgTarget)) {
10330 $extImgTarget = (preg_match('/\.gif$/i
', $file) ? '.gif
' : '');
10332 if (empty($extImgTarget)) {
10333 $extImgTarget = (preg_match('/\.png$/i
', $file) ? '.png
' : '');
10335 if (empty($extImgTarget)) {
10336 $extImgTarget = (preg_match('/\.bmp$/i
', $file) ? '.bmp
' : '');
10338 if (empty($extImgTarget)) {
10339 $extImgTarget = (preg_match('/\.webp$/i
', $file) ? '.webp
' : '');
10342 if (!$extImgTarget) {
10348 $subdir = 'thumbs/
';
10351 return ($dirName ? $dirName.'/
' : '').$subdir.$fileName.$extName.$extImgTarget; // New filename for thumb
10364function getAdvancedPreviewUrl($modulepart, $relativepath, $alldata = 0, $param = '
')
10366 global $conf, $langs;
10368 if (empty($conf->use_javascript_ajax)) {
10372 $isAllowedForPreview = dolIsAllowedForPreview($relativepath);
10374 if ($alldata == 1) {
10375 if ($isAllowedForPreview) {
10376 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));
10382 // old behavior, return a string
10383 if ($isAllowedForPreview) {
10384 $tmpurl = DOL_URL_ROOT.'/document.php?modulepart=
'.urlencode($modulepart).'&attachment=0&file=
'.urlencode($relativepath).($param ? '&
'.$param : '');
10385 $title = $langs->transnoentities("Preview");
10386 //$title = '%27-alert(document.domain)-%27
';
10387 //$tmpurl = 'file=
'.urlencode("'-alert(document.domain)-
'_small.jpg");
10389 // We need to urlencode the parameter after the dol_escape_js($tmpurl) because $tmpurl may contain n url with param file=abc%27def if file has a ' inside.
10406function ajax_autoselect($htmlname, $addlink = '
', $textonlink = 'Link')
10409 $out = '<script nonce=
"'.getNonce().'">
10410 jQuery(document).ready(
function () {
10411 jQuery(
"'.((strpos($htmlname, '.') === 0 ? '' : '#').$htmlname).'").click(
function() { jQuery(
this).select(); } );
10415 if ($textonlink === 'image
') {
10416 $out .= ' <a href=
"'.$addlink.'" target=
"_blank" rel=
"noopener noreferrer">
'.img_picto('', 'globe
').'</a>
';
10418 $out .= ' <a href=
"'.$addlink.'" target=
"_blank" rel=
"noopener noreferrer">
'.$langs->trans("Link").'</a>
';
10431function dolIsAllowedForPreview($file)
10435 // Check .noexe extension in filename
10436 if (preg_match('/\.noexe$/i
', $file)) {
10440 // Check mime types
10441 $mime_preview = array('bmp
', 'jpeg
', 'png
', 'gif
', 'tiff
', 'pdf
', 'plain
', 'css
', 'webp
');
10442 if (!empty($conf->global->MAIN_ALLOW_SVG_FILES_AS_IMAGES)) {
10443 $mime_preview[] = 'svg+xml
';
10445 //$mime_preview[]='vnd.oasis.opendocument.presentation
';
10446 //$mime_preview[]='archive
';
10447 $num_mime = array_search(dol_mimetype($file, '', 1), $mime_preview);
10448 if ($num_mime !== false) {
10452 // By default, not allowed for preview
10466function dol_mimetype($file, $default = 'application/octet-stream
', $mode = 0)
10469 $imgmime = 'other.png
';
10470 $famime = 'file-o
';
10473 $tmpfile = preg_replace('/\.noexe$/
', '', $file);
10475 // Plain text files
10476 if (preg_match('/\.txt$/i
', $tmpfile)) {
10477 $mime = 'text/plain
';
10478 $imgmime = 'text.png
';
10479 $famime = 'file-text-o
';
10481 if (preg_match('/\.rtx$/i
', $tmpfile)) {
10482 $mime = 'text/richtext
';
10483 $imgmime = 'text.png
';
10484 $famime = 'file-text-o
';
10486 if (preg_match('/\.csv$/i
', $tmpfile)) {
10487 $mime = 'text/csv
';
10488 $imgmime = 'text.png
';
10489 $famime = 'file-text-o
';
10491 if (preg_match('/\.tsv$/i
', $tmpfile)) {
10492 $mime = 'text/tab-separated-values
';
10493 $imgmime = 'text.png
';
10494 $famime = 'file-text-o
';
10496 if (preg_match('/\.(cf|
conf|log)$/i
', $tmpfile)) {
10497 $mime = 'text/plain
';
10498 $imgmime = 'text.png
';
10499 $famime = 'file-text-o
';
10501 if (preg_match('/\.ini$/i
', $tmpfile)) {
10502 $mime = 'text/plain
';
10503 $imgmime = 'text.png
';
10505 $famime = 'file-text-o
';
10507 if (preg_match('/\.md$/i
', $tmpfile)) {
10508 $mime = 'text/plain
';
10509 $imgmime = 'text.png
';
10511 $famime = 'file-text-o
';
10513 if (preg_match('/\.css$/i
', $tmpfile)) {
10514 $mime = 'text/css
';
10515 $imgmime = 'css.png
';
10517 $famime = 'file-text-o
';
10519 if (preg_match('/\.lang$/i
', $tmpfile)) {
10520 $mime = 'text/plain
';
10521 $imgmime = 'text.png
';
10523 $famime = 'file-text-o
';
10525 // Certificate files
10526 if (preg_match('/\.(crt|cer|key|pub)$/i
', $tmpfile)) {
10527 $mime = 'text/plain
';
10528 $imgmime = 'text.png
';
10529 $famime = 'file-text-o
';
10531 // XML based (HTML/XML/XAML)
10532 if (preg_match('/\.(html|htm|shtml)$/i
', $tmpfile)) {
10533 $mime = 'text/html
';
10534 $imgmime = 'html.png
';
10536 $famime = 'file-text-o
';
10538 if (preg_match('/\.(xml|xhtml)$/i
', $tmpfile)) {
10539 $mime = 'text/xml
';
10540 $imgmime = 'other.png
';
10542 $famime = 'file-text-o
';
10544 if (preg_match('/\.xaml$/i
', $tmpfile)) {
10545 $mime = 'text/xml
';
10546 $imgmime = 'other.png
';
10548 $famime = 'file-text-o
';
10551 if (preg_match('/\.bas$/i
', $tmpfile)) {
10552 $mime = 'text/plain
';
10553 $imgmime = 'text.png
';
10555 $famime = 'file-code-o
';
10557 if (preg_match('/\.(c)$/i
', $tmpfile)) {
10558 $mime = 'text/plain
';
10559 $imgmime = 'text.png
';
10561 $famime = 'file-code-o
';
10563 if (preg_match('/\.(cpp)$/i
', $tmpfile)) {
10564 $mime = 'text/plain
';
10565 $imgmime = 'text.png
';
10567 $famime = 'file-code-o
';
10569 if (preg_match('/\.cs$/i
', $tmpfile)) {
10570 $mime = 'text/plain
';
10571 $imgmime = 'text.png
';
10573 $famime = 'file-code-o
';
10575 if (preg_match('/\.(h)$/i
', $tmpfile)) {
10576 $mime = 'text/plain
';
10577 $imgmime = 'text.png
';
10579 $famime = 'file-code-o
';
10581 if (preg_match('/\.(java|jsp)$/i
', $tmpfile)) {
10582 $mime = 'text/plain
';
10583 $imgmime = 'text.png
';
10585 $famime = 'file-code-o
';
10587 if (preg_match('/\.php([0-9]{1})?$/i
', $tmpfile)) {
10588 $mime = 'text/plain
';
10589 $imgmime = 'php.png
';
10591 $famime = 'file-code-o
';
10593 if (preg_match('/\.phtml$/i
', $tmpfile)) {
10594 $mime = 'text/plain
';
10595 $imgmime = 'php.png
';
10597 $famime = 'file-code-o
';
10599 if (preg_match('/\.(pl|pm)$/i
', $tmpfile)) {
10600 $mime = 'text/plain
';
10601 $imgmime = 'pl.png
';
10603 $famime = 'file-code-o
';
10605 if (preg_match('/\.sql$/i
', $tmpfile)) {
10606 $mime = 'text/plain
';
10607 $imgmime = 'text.png
';
10609 $famime = 'file-code-o
';
10611 if (preg_match('/\.js$/i
', $tmpfile)) {
10612 $mime = 'text/x-javascript
';
10613 $imgmime = 'jscript.png
';
10615 $famime = 'file-code-o
';
10618 if (preg_match('/\.odp$/i
', $tmpfile)) {
10619 $mime = 'application/vnd.oasis.opendocument.presentation
';
10620 $imgmime = 'ooffice.png
';
10621 $famime = 'file-powerpoint-o
';
10623 if (preg_match('/\.ods$/i
', $tmpfile)) {
10624 $mime = 'application/vnd.oasis.opendocument.spreadsheet
';
10625 $imgmime = 'ooffice.png
';
10626 $famime = 'file-excel-o
';
10628 if (preg_match('/\.odt$/i
', $tmpfile)) {
10629 $mime = 'application/vnd.oasis.opendocument.text
';
10630 $imgmime = 'ooffice.png
';
10631 $famime = 'file-word-o
';
10634 if (preg_match('/\.mdb$/i
', $tmpfile)) {
10635 $mime = 'application/msaccess
';
10636 $imgmime = 'mdb.png
';
10637 $famime = 'file-o
';
10639 if (preg_match('/\.doc[xm]?$/i
', $tmpfile)) {
10640 $mime = 'application/msword
';
10641 $imgmime = 'doc.png
';
10642 $famime = 'file-word-o
';
10644 if (preg_match('/\.dot[xm]?$/i
', $tmpfile)) {
10645 $mime = 'application/msword
';
10646 $imgmime = 'doc.png
';
10647 $famime = 'file-word-o
';
10649 if (preg_match('/\.xlt(x)?$/i
', $tmpfile)) {
10650 $mime = 'application/vnd.ms-excel
';
10651 $imgmime = 'xls.png
';
10652 $famime = 'file-excel-o
';
10654 if (preg_match('/\.xla(m)?$/i
', $tmpfile)) {
10655 $mime = 'application/vnd.ms-excel
';
10656 $imgmime = 'xls.png
';
10657 $famime = 'file-excel-o
';
10659 if (preg_match('/\.xls$/i
', $tmpfile)) {
10660 $mime = 'application/vnd.ms-excel
';
10661 $imgmime = 'xls.png
';
10662 $famime = 'file-excel-o
';
10664 if (preg_match('/\.xls[bmx]$/i
', $tmpfile)) {
10665 $mime = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
';
10666 $imgmime = 'xls.png
';
10667 $famime = 'file-excel-o
';
10669 if (preg_match('/\.pps[mx]?$/i
', $tmpfile)) {
10670 $mime = 'application/vnd.ms-powerpoint
';
10671 $imgmime = 'ppt.png
';
10672 $famime = 'file-powerpoint-o
';
10674 if (preg_match('/\.ppt[mx]?$/i
', $tmpfile)) {
10675 $mime = 'application/x-mspowerpoint
';
10676 $imgmime = 'ppt.png
';
10677 $famime = 'file-powerpoint-o
';
10680 if (preg_match('/\.pdf$/i
', $tmpfile)) {
10681 $mime = 'application/pdf
';
10682 $imgmime = 'pdf.png
';
10683 $famime = 'file-pdf-o
';
10686 if (preg_match('/\.bat$/i
', $tmpfile)) {
10687 $mime = 'text/x-bat
';
10688 $imgmime = 'script.png
';
10690 $famime = 'file-code-o
';
10692 if (preg_match('/\.sh$/i
', $tmpfile)) {
10693 $mime = 'text/x-sh
';
10694 $imgmime = 'script.png
';
10696 $famime = 'file-code-o
';
10698 if (preg_match('/\.ksh$/i
', $tmpfile)) {
10699 $mime = 'text/x-ksh
';
10700 $imgmime = 'script.png
';
10702 $famime = 'file-code-o
';
10704 if (preg_match('/\.bash$/i
', $tmpfile)) {
10705 $mime = 'text/x-bash
';
10706 $imgmime = 'script.png
';
10708 $famime = 'file-code-o
';
10711 if (preg_match('/\.ico$/i
', $tmpfile)) {
10712 $mime = 'image/x-icon
';
10713 $imgmime = 'image.png
';
10714 $famime = 'file-image-o
';
10716 if (preg_match('/\.(jpg|jpeg)$/i
', $tmpfile)) {
10717 $mime = 'image/jpeg
';
10718 $imgmime = 'image.png
';
10719 $famime = 'file-image-o
';
10721 if (preg_match('/\.png$/i
', $tmpfile)) {
10722 $mime = 'image/png
';
10723 $imgmime = 'image.png
';
10724 $famime = 'file-image-o
';
10726 if (preg_match('/\.gif$/i
', $tmpfile)) {
10727 $mime = 'image/gif
';
10728 $imgmime = 'image.png
';
10729 $famime = 'file-image-o
';
10731 if (preg_match('/\.bmp$/i
', $tmpfile)) {
10732 $mime = 'image/bmp
';
10733 $imgmime = 'image.png
';
10734 $famime = 'file-image-o
';
10736 if (preg_match('/\.(tif|tiff)$/i
', $tmpfile)) {
10737 $mime = 'image/tiff
';
10738 $imgmime = 'image.png
';
10739 $famime = 'file-image-o
';
10741 if (preg_match('/\.svg$/i
', $tmpfile)) {
10742 $mime = 'image/svg+xml
';
10743 $imgmime = 'image.png
';
10744 $famime = 'file-image-o
';
10746 if (preg_match('/\.webp$/i
', $tmpfile)) {
10747 $mime = 'image/webp
';
10748 $imgmime = 'image.png
';
10749 $famime = 'file-image-o
';
10752 if (preg_match('/\.vcs$/i
', $tmpfile)) {
10753 $mime = 'text/calendar
';
10754 $imgmime = 'other.png
';
10755 $famime = 'file-text-o
';
10757 if (preg_match('/\.ics$/i
', $tmpfile)) {
10758 $mime = 'text/calendar
';
10759 $imgmime = 'other.png
';
10760 $famime = 'file-text-o
';
10763 if (preg_match('/\.torrent$/i
', $tmpfile)) {
10764 $mime = 'application/x-bittorrent
';
10765 $imgmime = 'other.png
';
10766 $famime = 'file-o
';
10769 if (preg_match('/\.(mp3|ogg|au|wav|wma|mid)$/i
', $tmpfile)) {
10771 $imgmime = 'audio.png
';
10772 $famime = 'file-audio-o
';
10775 if (preg_match('/\.mp4$/i
', $tmpfile)) {
10776 $mime = 'video/mp4
';
10777 $imgmime = 'video.png
';
10778 $famime = 'file-video-o
';
10780 if (preg_match('/\.ogv$/i
', $tmpfile)) {
10781 $mime = 'video/ogg
';
10782 $imgmime = 'video.png
';
10783 $famime = 'file-video-o
';
10785 if (preg_match('/\.webm$/i
', $tmpfile)) {
10786 $mime = 'video/webm
';
10787 $imgmime = 'video.png
';
10788 $famime = 'file-video-o
';
10790 if (preg_match('/\.avi$/i
', $tmpfile)) {
10791 $mime = 'video/x-msvideo
';
10792 $imgmime = 'video.png
';
10793 $famime = 'file-video-o
';
10795 if (preg_match('/\.divx$/i
', $tmpfile)) {
10796 $mime = 'video/divx
';
10797 $imgmime = 'video.png
';
10798 $famime = 'file-video-o
';
10800 if (preg_match('/\.xvid$/i
', $tmpfile)) {
10801 $mime = 'video/xvid
';
10802 $imgmime = 'video.png
';
10803 $famime = 'file-video-o
';
10805 if (preg_match('/\.(wmv|mpg|mpeg)$/i
', $tmpfile)) {
10807 $imgmime = 'video.png
';
10808 $famime = 'file-video-o
';
10811 if (preg_match('/\.(zip|rar|gz|tgz|z|cab|bz2|7z|tar|lzh|zst)$/i
', $tmpfile)) {
10813 $imgmime = 'archive.png
';
10814 $famime = 'file-archive-o
';
10815 } // application/xxx where zzz is zip, ...
10817 if (preg_match('/\.(exe|com)$/i
', $tmpfile)) {
10818 $mime = 'application/octet-stream
';
10819 $imgmime = 'other.png
';
10820 $famime = 'file-o
';
10823 if (preg_match('/\.(dll|lib|o|so|a)$/i
', $tmpfile)) {
10825 $imgmime = 'library.png
';
10826 $famime = 'file-o
';
10829 if (preg_match('/\.err$/i
', $tmpfile)) {
10831 $imgmime = 'error.png
';
10832 $famime = 'file-text-o
';
10837 $tmp = explode('/
', $mime);
10838 return (!empty($tmp[1]) ? $tmp[1] : $tmp[0]);
10863function getDictionaryValue($tablename, $field, $id, $checkentity = false, $rowidfield = '
rowid')
10867 $tablename = preg_replace('/^
'.preg_quote(MAIN_DB_PREFIX, '/
').'/
', '', $tablename); // Clean name of table for backward compatibility.
10869 $dictvalues = (isset($conf->cache['dictvalues_
'.$tablename]) ? $conf->cache['dictvalues_
'.$tablename] : null);
10871 if (is_null($dictvalues)) {
10872 $dictvalues = array();
10874 $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
10875 if ($checkentity) {
10876 $sql .=
' AND entity IN (0,'.getEntity($tablename).
')';
10879 $resql = $db->query($sql);
10881 while ($obj = $db->fetch_object($resql)) {
10882 $dictvalues[$obj->{$rowidfield}] = $obj;
10888 $conf->cache[
'dictvalues_'.$tablename] = $dictvalues;
10891 if (!empty($dictvalues[$id])) {
10893 $tmp = $dictvalues[$id];
10894 return (property_exists($tmp, $field) ? $tmp->$field :
'');
10909 $stringcolor = str_replace(
'#',
'', $stringcolor);
10911 if (!empty($stringcolor)) {
10913 $tmp = explode(
',', $stringcolor);
10914 if (count($tmp) > 1) {
10919 $hexr = $stringcolor[0].$stringcolor[1];
10920 $hexg = $stringcolor[2].$stringcolor[3];
10921 $hexb = $stringcolor[4].$stringcolor[5];
10922 $r = hexdec($hexr);
10923 $g = hexdec($hexg);
10924 $b = hexdec($hexb);
10926 $bright = (max($r, $g, $b) + min($r, $g, $b)) / 510.0;
10927 if ($bright > 0.6) {
10948 if (empty($menuentry[
'enabled'])) {
10951 if ($type_user && $menuentry[
'module']) {
10952 $tmploops = explode(
'|', $menuentry[
'module']);
10954 foreach ($tmploops as $tmploop) {
10955 if (in_array($tmploop, $listofmodulesforexternal)) {
10964 if (!$menuentry[
'perms'] && $type_user) {
10967 if (!$menuentry[
'perms'] && !empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED)) {
10970 if (!$menuentry[
'perms']) {
10985 return (ceil($n) % $x === 0) ? ceil($n) : round(($n + $x / 2) / $x) * $x;
10999function dolGetBadge($label, $html =
'', $type =
'primary', $mode =
'', $url =
'', $params = array())
11002 'class'=>
'badge '.(!empty($mode) ?
' badge-'.$mode :
'').(!empty($type) ?
' badge-'.$type :
'').(empty($params[
'css']) ?
'' :
' '.$params[
'css'])
11005 if (empty($html)) {
11009 if (!empty($url)) {
11010 $attr[
'href'] = $url;
11013 if ($mode ===
'dot') {
11014 $attr[
'class'] .=
' classfortooltip';
11015 $attr[
'title'] = $html;
11016 $attr[
'aria-label'] = $label;
11021 if (!empty($params[
'attr']) && is_array($params[
'attr'])) {
11022 foreach ($params[
'attr'] as $key => $value) {
11023 if ($key ==
'class') {
11024 $attr[
'class'] .=
' '.$value;
11025 } elseif ($key ==
'classOverride') {
11026 $attr[
'class'] = $value;
11028 $attr[$key] = $value;
11036 $attr = array_map(
'dol_escape_htmltag', $attr);
11038 $TCompiledAttr = array();
11039 foreach ($attr as $key => $value) {
11040 $TCompiledAttr[] = $key.
'="'.$value.
'"';
11043 $compiledAttributes = !empty($TCompiledAttr) ?implode(
' ', $TCompiledAttr) :
'';
11045 $tag = !empty($url) ?
'a' :
'span';
11047 return '<'.$tag.
' '.$compiledAttributes.
'>'.$html.
'</'.$tag.
'>';
11063function dolGetStatus($statusLabel =
'', $statusLabelShort =
'', $html =
'', $statusType =
'status0', $displayMode = 0, $url =
'', $params = array())
11068 $dolGetBadgeParams = array();
11070 if (!empty($params[
'badgeParams'])) {
11071 $dolGetBadgeParams = $params[
'badgeParams'];
11075 if ($displayMode == 0) {
11076 $return = !empty($html) ? $html : (empty($conf->dol_optimize_smallscreen) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort));
11077 } elseif ($displayMode == 1) {
11078 $return = !empty($html) ? $html : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort);
11079 } elseif (!empty($conf->global->MAIN_STATUS_USES_IMAGES)) {
11082 $htmlLabel = (in_array($displayMode, array(1, 2, 5)) ?
'<span class="hideonsmartphone">' :
'').(!empty($html) ? $html : $statusLabel).(in_array($displayMode, array(1, 2, 5)) ?
'</span>' :
'');
11083 $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>' :
'');
11086 if (!empty($conf->dol_optimize_smallscreen)) {
11087 if ($displayMode == 0) {
11089 } elseif ($displayMode == 4) {
11091 } elseif ($displayMode == 6) {
11097 $statusImg = array(
11098 'status0' =>
'statut0',
11099 'status1' =>
'statut1',
11100 'status2' =>
'statut2',
11101 'status3' =>
'statut3',
11102 'status4' =>
'statut4',
11103 'status5' =>
'statut5',
11104 'status6' =>
'statut6',
11105 'status7' =>
'statut7',
11106 'status8' =>
'statut8',
11107 'status9' =>
'statut9'
11110 if (!empty($statusImg[$statusType])) {
11111 $htmlImg =
img_picto($statusLabel, $statusImg[$statusType]);
11113 $htmlImg =
img_picto($statusLabel, $statusType);
11116 if ($displayMode === 2) {
11117 $return = $htmlImg.
' '.$htmlLabelShort;
11118 } elseif ($displayMode === 3) {
11119 $return = $htmlImg;
11120 } elseif ($displayMode === 4) {
11121 $return = $htmlImg.
' '.$htmlLabel;
11122 } elseif ($displayMode === 5) {
11123 $return = $htmlLabelShort.
' '.$htmlImg;
11125 $return = $htmlLabel.
' '.$htmlImg;
11127 } elseif (empty($conf->global->MAIN_STATUS_USES_IMAGES) && !empty($displayMode)) {
11129 $statusLabelShort = (empty($statusLabelShort) ? $statusLabel : $statusLabelShort);
11131 $dolGetBadgeParams[
'attr'][
'class'] =
'badge-status';
11132 $dolGetBadgeParams[
'attr'][
'title'] = empty($params[
'tooltip']) ? $statusLabel : ($params[
'tooltip'] !=
'no' ? $params[
'tooltip'] :
'');
11134 if ($displayMode == 3) {
11135 $return = dolGetBadge((empty($conf->dol_optimize_smallscreen) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort)),
'', $statusType,
'dot', $url, $dolGetBadgeParams);
11136 } elseif ($displayMode === 5) {
11137 $return = dolGetBadge($statusLabelShort, $html, $statusType,
'', $url, $dolGetBadgeParams);
11139 $return = dolGetBadge((empty($conf->dol_optimize_smallscreen) ? $statusLabel : (empty($statusLabelShort) ? $statusLabel : $statusLabelShort)), $html, $statusType,
'', $url, $dolGetBadgeParams);
11181function dolGetButtonAction($label, $text =
'', $actionType =
'default', $url =
'', $id =
'', $userRight = 1, $params = array())
11183 global $hookmanager, $action, $object, $langs;
11186 if (is_array($url)) {
11187 $out =
'<div class="dropdown inline-block dropdown-holder">';
11188 $out .=
'<a style="margin-right: auto;" class="dropdown-toggle butAction" data-toggle="dropdown">'.$label.
'</a>';
11189 $out .=
'<div class="dropdown-content">';
11190 foreach ($url as $subbutton) {
11191 if ($subbutton[
'enabled'] && $subbutton[
'perm']) {
11192 if (!empty($subbutton[
'lang'])) {
11193 $langs->load($subbutton[
'lang']);
11195 $out .=
dolGetButtonAction(
'', $langs->trans($subbutton[
'label']),
'default', DOL_URL_ROOT.$subbutton[
'url'].(empty($params[
'backtopage']) ?
'' :
'&backtopage='.urlencode($params[
'backtopage'])),
'', 1, array(
'isDropDown' =>
true));
11205 if (!empty($params[
'isDropdown']))
11206 $class =
"dropdown-item";
11208 $class =
'butAction';
11209 if ($actionType ==
'danger' || $actionType ==
'delete') {
11210 $class =
'butActionDelete';
11211 if (!empty($url) && strpos($url,
'token=') ===
false) $url .=
'&token='.
newToken();
11216 'href' => empty($url) ?
'' : $url,
11220 if (empty($text)) {
11222 $attr[
'title'] =
'';
11224 $attr[
'title'] = $label;
11225 $attr[
'aria-label'] = $label;
11228 if (empty($userRight)) {
11229 $attr[
'class'] =
'butActionRefused';
11230 $attr[
'href'] =
'';
11231 $attr[
'title'] = (($label && $text && $label != $text) ? $label : $langs->trans(
'NotEnoughPermissions'));
11239 if (!empty($params[
'attr']) && is_array($params[
'attr'])) {
11240 foreach ($params[
'attr'] as $key => $value) {
11241 if ($key ==
'class') {
11242 $attr[
'class'] .=
' '.$value;
11243 } elseif ($key ==
'classOverride') {
11244 $attr[
'class'] = $value;
11246 $attr[$key] = $value;
11252 if (!empty($attr[
'title']) && !empty($attr[
'class']) && strpos($attr[
'class'],
'classfortooltip') ===
false) {
11253 $attr[
'class'].=
' classfortooltip';
11257 if ($userRight && !empty($params[
'confirm'])) {
11258 if (!is_array($params[
'confirm'])) {
11259 $params[
'confirm'] = array();
11262 if (empty($params[
'confirm'][
'url'])) {
11263 $params[
'confirm'][
'url'] = $url . (strpos($url,
'?') > 0 ?
'&' :
'?') .
'confirm=yes';
11267 $attr[
'data-confirm-url'] = $params[
'confirm'][
'url'];
11268 $attr[
'data-confirm-title'] = !empty($params[
'confirm'][
'title']) ? $params[
'confirm'][
'title'] : $langs->trans(
'ConfirmBtnCommonTitle', $label);
11269 $attr[
'data-confirm-content'] = !empty($params[
'confirm'][
'content']) ? $params[
'confirm'][
'content'] : $langs->trans(
'ConfirmBtnCommonContent', $label);
11270 $attr[
'data-confirm-content'] = preg_replace(
"/\r|\n/",
"", $attr[
'data-confirm-content']);
11271 $attr[
'data-confirm-action-btn-label'] = !empty($params[
'confirm'][
'action-btn-label']) ? $params[
'confirm'][
'action-btn-label'] : $langs->trans(
'Confirm');
11272 $attr[
'data-confirm-cancel-btn-label'] = !empty($params[
'confirm'][
'cancel-btn-label']) ? $params[
'confirm'][
'cancel-btn-label'] : $langs->trans(
'CloseDialog');
11273 $attr[
'data-confirm-modal'] = !empty($params[
'confirm'][
'modal']) ? $params[
'confirm'][
'modal'] :
true;
11275 $attr[
'class'].=
' butActionConfirm';
11278 if (isset($attr[
'href']) && empty($attr[
'href'])) {
11279 unset($attr[
'href']);
11283 $attr = array_map(
'dol_escape_htmltag', $attr);
11285 $TCompiledAttr = array();
11286 foreach ($attr as $key => $value) {
11287 $TCompiledAttr[] = $key.
'= "'.$value.
'"';
11290 $compiledAttributes = empty($TCompiledAttr) ?
'' : implode(
' ', $TCompiledAttr);
11292 $tag = !empty($attr[
'href']) ?
'a' :
'span';
11295 $parameters = array(
11296 'TCompiledAttr' => $TCompiledAttr,
11297 'compiledAttributes' => $compiledAttributes,
11302 'actionType' => $actionType,
11305 'userRight' => $userRight,
11306 'params' => $params
11309 $reshook = $hookmanager->executeHooks(
'dolGetButtonAction', $parameters, $object, $action);
11310 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
11312 if (empty($reshook)) {
11314 return '<' . $tag .
' ' . $compiledAttributes .
'>' . $text .
'</' . $tag .
'>';
11316 return '<' . $tag .
' ' . $compiledAttributes .
'>' .
dol_escape_htmltag($text) .
'</' . $tag .
'>';
11319 return $hookmanager->resPrint;
11331 return '<span class="button-title-separator '.$moreClass.
'" ></span>';
11343 if (!empty($fieldValidationErrorMsg)) {
11344 $out.=
'<span class="field-error-icon classfortooltip" title="'.dol_escape_htmltag($fieldValidationErrorMsg, 1).
'" role="alert" >';
11345 $out.=
'<span class="fa fa-exclamation-circle" aria-hidden="true" ></span>';
11364function dolGetButtonTitle($label, $helpText =
'', $iconClass =
'fa fa-file', $url =
'', $id =
'', $status = 1, $params = array())
11366 global $langs, $conf, $user;
11369 if (!empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED) && (!$user->admin) && $status <= 0) {
11373 $class =
'btnTitle';
11374 if (in_array($iconClass, array(
'fa fa-plus-circle',
'fa fa-plus-circle size15x',
'fa fa-comment-dots',
'fa fa-paper-plane'))) {
11375 $class .=
' btnTitlePlus';
11377 $useclassfortooltip = 1;
11379 if (!empty($params[
'morecss'])) {
11380 $class .=
' '.$params[
'morecss'];
11385 'href' => empty($url) ?
'' : $url
11388 if (!empty($helpText)) {
11390 } elseif (empty($attr[
'title']) && $label) {
11391 $attr[
'title'] = $label;
11392 $useclassfortooltip = 0;
11395 if ($status == 2) {
11396 $attr[
'class'] .=
' btnTitleSelected';
11397 } elseif ($status <= 0) {
11398 $attr[
'class'] .=
' refused';
11400 $attr[
'href'] =
'';
11402 if ($status == -1) {
11403 $attr[
'title'] =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"FeatureDisabled"));
11404 } elseif ($status == 0) {
11405 $attr[
'title'] =
dol_escape_htmltag($langs->transnoentitiesnoconv(
"NotEnoughPermissions"));
11409 if (!empty($attr[
'title']) && $useclassfortooltip) {
11410 $attr[
'class'] .=
' classfortooltip';
11418 if (!empty($params[
'attr']) && is_array($params[
'attr'])) {
11419 foreach ($params[
'attr'] as $key => $value) {
11420 if ($key ==
'class') {
11421 $attr[
'class'] .=
' '.$value;
11422 } elseif ($key ==
'classOverride') {
11423 $attr[
'class'] = $value;
11425 $attr[$key] = $value;
11430 if (isset($attr[
'href']) && empty($attr[
'href'])) {
11431 unset($attr[
'href']);
11437 $attr = array_map(
'dol_escape_htmltag', $attr);
11439 $TCompiledAttr = array();
11440 foreach ($attr as $key => $value) {
11441 $TCompiledAttr[] = $key.
'="'.$value.
'"';
11444 $compiledAttributes = (empty($TCompiledAttr) ?
'' : implode(
' ', $TCompiledAttr));
11446 $tag = (empty($attr[
'href']) ?
'span' :
'a');
11448 $button =
'<'.$tag.
' '.$compiledAttributes.
'>';
11449 $button .=
'<span class="'.$iconClass.
' valignmiddle btnTitle-icon"></span>';
11450 if (!empty($params[
'forcenohideoftext'])) {
11451 $button .=
'<span class="valignmiddle text-plus-circle btnTitle-label'.(empty($params[
'forcenohideoftext']) ?
' hideonsmartphone' :
'').
'">'.$label.
'</span>';
11453 $button .=
'</'.$tag.
'>';
11474 $classfile = $classname = $classpath = $subdir = $dir_output =
'';
11477 $module = $element_type;
11478 $element = $element_type;
11479 $subelement = $element_type;
11482 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $element_type, $regs)) {
11483 $element = $subelement = $regs[1];
11484 $module = $regs[2];
11489 if (preg_match(
'/^([^_]+)_([^_]+)/i', $element, $regs)) {
11490 $module = $element = $regs[1];
11491 $subelement = $regs[2];
11495 if ($element_type ==
"action") {
11496 $classpath =
'comm/action/class';
11497 $subelement =
'Actioncomm';
11498 $module =
'agenda';
11499 } elseif ($element_type ==
'cronjob') {
11500 $classpath =
'cron/class';
11502 } elseif ($element_type ==
'adherent_type') {
11503 $classpath =
'adherents/class';
11504 $classfile =
'adherent_type';
11505 $module =
'adherent';
11506 $subelement =
'adherent_type';
11507 $classname =
'AdherentType';
11508 } elseif ($element_type ==
'bank_account') {
11509 $classpath =
'compta/bank/class';
11511 $classfile =
'account';
11512 $classname =
'Account';
11513 } elseif ($element_type ==
'category') {
11514 $classpath =
'categories/class';
11515 $module =
'categorie';
11516 $subelement =
'categorie';
11517 } elseif ($element_type ==
'contact') {
11518 $classpath =
'contact/class';
11519 $classfile =
'contact';
11520 $module =
'societe';
11521 $subelement =
'contact';
11522 } elseif ($element_type ==
'stock') {
11523 $classpath =
'product/stock/class';
11524 $classfile =
'entrepot';
11525 $classname =
'Entrepot';
11526 } elseif ($element_type ==
'project') {
11527 $classpath =
'projet/class';
11528 $module =
'projet';
11529 } elseif ($element_type ==
'project_task') {
11530 $classpath =
'projet/class';
11531 $module =
'projet';
11532 $subelement =
'task';
11533 } elseif ($element_type ==
'facture' || $element_type ==
'invoice') {
11534 $classpath =
'compta/facture/class';
11535 $module =
'facture';
11536 $subelement =
'facture';
11537 } elseif ($element_type ==
'commande' || $element_type ==
'order') {
11538 $classpath =
'commande/class';
11539 $module =
'commande';
11540 $subelement =
'commande';
11541 } elseif ($element_type ==
'propal') {
11542 $classpath =
'comm/propal/class';
11543 } elseif ($element_type ==
'shipping') {
11544 $classpath =
'expedition/class';
11545 $classfile =
'expedition';
11546 $classname =
'Expedition';
11547 $module =
'expedition';
11548 } elseif ($element_type ==
'supplier_proposal') {
11549 $classpath =
'supplier_proposal/class';
11550 $module =
'supplier_proposal';
11551 $element =
'supplierproposal';
11552 $classfile =
'supplier_proposal';
11553 $subelement =
'supplierproposal';
11554 } elseif ($element_type ==
'shipping') {
11555 $classpath =
'expedition/class';
11556 $subelement =
'expedition';
11557 $module =
'expedition_bon';
11558 } elseif ($element_type ==
'delivery') {
11559 $classpath =
'delivery/class';
11560 $subelement =
'delivery';
11561 $module =
'delivery_note';
11562 } elseif ($element_type ==
'contract') {
11563 $classpath =
'contrat/class';
11564 $module =
'contrat';
11565 $subelement =
'contrat';
11566 } elseif ($element_type ==
'mailing') {
11567 $classpath =
'comm/mailing/class';
11568 $module =
'mailing';
11569 $classfile =
'mailing';
11570 $classname =
'Mailing';
11572 } elseif ($element_type ==
'member') {
11573 $classpath =
'adherents/class';
11574 $module =
'adherent';
11575 $subelement =
'adherent';
11576 } elseif ($element_type ==
'usergroup') {
11577 $classpath =
'user/class';
11579 } elseif ($element_type ==
'mo') {
11580 $classpath =
'mrp/class';
11585 } elseif ($element_type ==
'cabinetmed_cons') {
11586 $classpath =
'cabinetmed/class';
11587 $module =
'cabinetmed';
11588 $subelement =
'cabinetmedcons';
11589 } elseif ($element_type ==
'fichinter') {
11590 $classpath =
'fichinter/class';
11591 $module =
'ficheinter';
11592 $subelement =
'fichinter';
11593 } elseif ($element_type ==
'dolresource' || $element_type ==
'resource') {
11594 $classpath =
'resource/class';
11595 $module =
'resource';
11596 $subelement =
'dolresource';
11597 } elseif ($element_type ==
'propaldet') {
11598 $classpath =
'comm/propal/class';
11599 $module =
'propal';
11600 $subelement =
'propaleligne';
11601 } elseif ($element_type ==
'opensurvey_sondage') {
11602 $classpath =
'opensurvey/class';
11603 $module =
'opensurvey';
11604 $subelement =
'opensurveysondage';
11605 } elseif ($element_type ==
'order_supplier') {
11606 $classpath =
'fourn/class';
11607 $module =
'fournisseur';
11608 $classfile =
'fournisseur.commande';
11609 $element =
'order_supplier';
11611 $classname =
'CommandeFournisseur';
11612 } elseif ($element_type ==
'invoice_supplier') {
11613 $classpath =
'fourn/class';
11614 $module =
'fournisseur';
11615 $classfile =
'fournisseur.facture';
11616 $element =
'invoice_supplier';
11618 $classname =
'FactureFournisseur';
11619 } elseif ($element_type ==
"service") {
11620 $classpath =
'product/class';
11621 $subelement =
'product';
11622 } elseif ($element_type ==
'salary') {
11623 $classpath =
'salaries/class';
11624 $module =
'salaries';
11625 } elseif ($element_type ==
'productlot') {
11626 $module =
'productbatch';
11627 $classpath =
'product/stock/class';
11628 $classfile =
'productlot';
11629 $classname =
'Productlot';
11630 $element =
'productlot';
11632 } elseif ($element_type ==
'websitepage') {
11633 $classpath =
'website/class';
11634 $classfile =
'websitepage';
11635 $classname =
'Websitepage';
11636 $module =
'website';
11637 $subelement =
'websitepage';
11638 } elseif ($element_type ==
'fiscalyear') {
11639 $classpath =
'core/class';
11640 $module =
'accounting';
11641 $subelement =
'fiscalyear';
11642 } elseif ($element_type ==
'chargesociales') {
11643 $classpath =
'compta/sociales/class';
11645 } elseif ($element_type ==
'tva') {
11646 $classpath =
'compta/tva/class';
11651 if (empty($classfile)) {
11652 $classfile = strtolower($subelement);
11654 if (empty($classname)) {
11655 $classname = ucfirst($subelement);
11657 if (empty($classpath)) {
11658 $classpath = $module.
'/class';
11664 if ($module && isset($conf->$module)) {
11665 if (!empty($conf->$module->multidir_output[$conf->entity])) {
11666 $dir_output = $conf->$module->multidir_output[$conf->entity];
11667 } elseif (!empty($conf->$module->output[$conf->entity])) {
11668 $dir_output = $conf->$module->output[$conf->entity];
11669 } elseif (!empty($conf->$module->dir_output)) {
11670 $dir_output = $conf->$module->dir_output;
11675 if ($element ==
'order_supplier') {
11676 $dir_output = $conf->fournisseur->commande->dir_output;
11677 } elseif ($element ==
'invoice_supplier') {
11678 $dir_output = $conf->fournisseur->facture->dir_output;
11680 $dir_output .= $subdir;
11682 $element_properties = array(
11683 'module' => $module,
11684 'element' => $element,
11685 'subelement' => $subelement,
11686 'classpath' => $classpath,
11687 'classfile' => $classfile,
11688 'classname' => $classname,
11689 'dir_output' => $dir_output
11691 return $element_properties;
11711 if (is_array($element_prop) && isModEnabled($element_prop[
'module'])) {
11712 dol_include_once(
'/'.$element_prop[
'classpath'].
'/'.$element_prop[
'classfile'].
'.class.php');
11714 if (class_exists($element_prop[
'classname'])) {
11715 $classname = $element_prop[
'classname'];
11716 $objecttmp =
new $classname($db);
11717 $ret = $objecttmp->fetch($element_id, $element_ref);
11719 if (empty($objecttmp->module)) {
11720 $objecttmp->module = $element_prop[
'module'];
11741 if (preg_match(
'/\.(htm|html|js|phar|php|php\d+|phtml|pht|pl|py|cgi|ksh|sh|shtml|bash|bat|cmd|wpk|exe|dmg)$/i', $filename)) {
11757 return empty($_SESSION[
'newtoken']) ?
'' : $_SESSION[
'newtoken'];
11769 return isset($_SESSION[
'token']) ? $_SESSION[
'token'] :
'';
11781 if (empty($conf->cache[
'nonce'])) {
11785 return $conf->cache[
'nonce'];
11805 print
'<div class="div-table-responsive-no-min">';
11806 print
'<table class="noborder centpercent">';
11807 print
'<tr class="liste_titre">';
11809 print $emptyRows < 1 ?
'<th>' :
'<th colspan="'.($emptyRows + 1).
'">';
11811 print $langs->trans($header);
11814 if ($number > -1) {
11818 if (!empty($link)) {
11819 if (!empty($arguments)) {
11820 print
'<a href="'.DOL_URL_ROOT.
'/'.$link.
'?'.$arguments.
'">';
11822 print
'<a href="'.DOL_URL_ROOT.
'/'.$link.
'">';
11826 if ($number > -1) {
11827 print
'<span class="badge">'.$number.
'</span>';
11830 if (!empty($link)) {
11836 if ($number < 0 && !empty($link)) {
11837 print
'<th class="right">';
11839 if (!empty($arguments)) {
11840 print
'<a class="commonlink" href="'.DOL_URL_ROOT.
'/'.$link.
'?'.$arguments.
'">';
11842 print
'<a class="commonlink" href="'.DOL_URL_ROOT.
'/'.$link.
'">';
11845 print $langs->trans(
"FullList");
11866 if ($addLineBreak) {
11882function addSummaryTableLine($tableColumnCount, $num, $nbofloop = 0, $total = 0, $noneWord =
"None", $extraRightColumn =
false)
11887 print
'<tr class="oddeven">';
11888 print
'<td colspan="'.$tableColumnCount.
'" class="opacitymedium">'.$langs->trans($noneWord).
'</td>';
11893 if ($nbofloop === 0) {
11899 $colspan = $tableColumnCount;
11900 } elseif ($num > $nbofloop) {
11901 $colspan = $tableColumnCount;
11903 $colspan = $tableColumnCount - 1;
11906 if ($extraRightColumn) {
11910 print
'<tr class="liste_total">';
11912 if ($nbofloop > 0 && $num > $nbofloop) {
11913 print
'<td colspan="'.$colspan.
'" class="right">'.$langs->trans(
"XMoreLines", ($num - $nbofloop)).
'</td>';
11915 print
'<td colspan="'.$colspan.
'" class="right"> '.$langs->trans(
"Total").
'</td>';
11916 print
'<td class="right" width="100">'.price($total).
'</td>';
11919 if ($extraRightColumn) {
11938 if ($method == -1) {
11940 if (!empty($conf->global->MAIN_FORCE_READFILE_WITH_FREAD)) {
11943 if (!empty($conf->global->MAIN_FORCE_READFILE_WITH_STREAM_COPY)) {
11949 while (ob_get_level()) {
11954 if ($method == 0) {
11955 readfile($fullpath_original_file_osencoded);
11956 } elseif ($method == 1) {
11958 $handle = fopen($fullpath_original_file_osencoded,
"rb");
11959 while (!feof($handle)) {
11960 print fread($handle, 8192);
11963 } elseif ($method == 2) {
11965 $handle1 = fopen($fullpath_original_file_osencoded,
"rb");
11966 $handle2 = fopen(
"php://output",
"wb");
11967 stream_copy_to_stream($handle1, $handle2);
11992 if ($texttoshow ===
'none') {
11993 $result =
'<span class="clipboardCP'.($showonlyonhover ?
' clipboardCPShowOnHover' :
'').
'"><'.$tag.
' class="clipboardCPValue hidewithsize">'.
dol_escape_htmltag($valuetocopy, 1, 1).
'</'.$tag.
'><span class="clipboardCPValueToPrint"></span><span class="clipboardCPButton far fa-clipboard opacitymedium paddingleft paddingright"></span><span class="clipboardCPText"></span></span>';
11994 } elseif ($texttoshow) {
11995 $result =
'<span class="clipboardCP'.($showonlyonhover ?
' clipboardCPShowOnHover' :
'').
'"><'.$tag.
' class="clipboardCPValue hidewithsize">'.
dol_escape_htmltag($valuetocopy, 1, 1).
'</'.$tag.
'><span class="clipboardCPValueToPrint">'.
dol_escape_htmltag($texttoshow, 1, 1).
'</span><span class="clipboardCPButton far fa-clipboard opacitymedium paddingleft paddingright"></span><span class="clipboardCPText"></span></span>';
11997 $result =
'<span class="clipboardCP'.($showonlyonhover ?
' clipboardCPShowOnHover' :
'').
'"><'.$tag.
' class="clipboardCPValue">'.
dol_escape_htmltag($valuetocopy, 1, 1).
'</'.$tag.
'><span class="clipboardCPButton far fa-clipboard opacitymedium paddingleft paddingright"></span><span class="clipboardCPText"></span></span>';
12012 $result = json_decode($stringtodecode);
12013 if ($result ===
null) {
12014 $result = unserialize($stringtodecode);
12036 if (!preg_match(
'/^\(.*\)$/', $filter)) {
12037 $filter =
'(' . $filter .
')';
12040 $regexstring =
'\(([a-zA-Z0-9_\.]+:[<>!=insotlke]+:[^\(\)]+)\)';
12046 return 'Filter syntax error - '.$errorstr;
12051 $t = preg_replace_callback(
'/'.$regexstring.
'/i',
'dolForgeDummyCriteriaCallback', $filter);
12052 $t = str_replace(array(
'and',
'or',
'AND',
'OR',
' '),
'', $t);
12054 if (preg_match(
'/[^\(\)]/', $t)) {
12055 $errorstr =
'Bad syntax of the search string';
12059 return 'Filter syntax error - '.$errorstr;
12063 return ($noand ?
"" :
" AND ").($nopar ?
"" :
'(').preg_replace_callback(
'/'.$regexstring.
'/i',
'dolForgeCriteriaCallback', $filter).($nopar ?
"" :
')');
12077 $tmp = $sqlfilters;
12078 $i = 0; $nb = strlen($tmp);
12081 if ($tmp[$i] ==
'(') {
12084 if ($tmp[$i] ==
')') {
12087 if ($counter < 0) {
12088 $error =
"Wrond balance of parenthesis in sqlfilters=".$sqlfilters;
12107 if (empty($matches[1])) {
12110 $tmp = explode(
':', $matches[1]);
12111 if (count($tmp) < 3) {
12131 if (empty($matches[1])) {
12134 $tmp = explode(
':', $matches[1]);
12135 if (count($tmp) < 3) {
12139 $operand = preg_replace(
'/[^a-z0-9\._]/i',
'', trim($tmp[0]));
12141 $operator = strtoupper(preg_replace(
'/[^a-z<>!=]/i',
'', trim($tmp[1])));
12143 if ($operator ==
'NOTLIKE') {
12144 $operator =
'NOT LIKE';
12146 if ($operator ==
'ISNOT') {
12147 $operator =
'IS NOT';
12149 if ($operator ==
'!=') {
12153 $tmpescaped = $tmp[2];
12156 if ($operator ==
'IN') {
12158 $tmpescaped =
'('.$db->escape($db->sanitize($tmpescaped, 1, 0)).
')';
12162 } elseif ($operator ==
'LIKE' || $operator ==
'NOT LIKE') {
12163 if (preg_match(
'/^\'(.*)\'$/', $tmpescaped, $regbis)) {
12164 $tmpescaped = $regbis[1];
12167 $tmpescaped =
"'".$db->escape($tmpescaped).
"'";
12168 } elseif (preg_match(
'/^\'(.*)\'$/', $tmpescaped, $regbis)) {
12169 $tmpescaped =
"'".$db->escape($regbis[1]).
"'";
12171 if (strtoupper($tmpescaped) ==
'NULL') {
12172 $tmpescaped =
'NULL';
12173 } elseif (is_int($tmpescaped)) {
12174 $tmpescaped = (int) $tmpescaped;
12176 $tmpescaped = (float) $tmpescaped;
12180 return '('.$db->escape($operand).
' '.strtoupper($operator).
' '.$tmpescaped.
')';
12194 global $conf, $langs;
12195 $out =
'<!-- timeline icon -->'.
"\n";
12196 $iconClass =
'fa fa-comments';
12201 if ($histo[$key][
'percent'] == -1) {
12202 $colorClass =
'timeline-icon-not-applicble';
12203 $pictoTitle = $langs->trans(
'StatusNotApplicable');
12204 } elseif ($histo[$key][
'percent'] == 0) {
12205 $colorClass =
'timeline-icon-todo';
12206 $pictoTitle = $langs->trans(
'StatusActionToDo').
' (0%)';
12207 } elseif ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100) {
12208 $colorClass =
'timeline-icon-in-progress';
12209 $pictoTitle = $langs->trans(
'StatusActionInProcess').
' ('.$histo[$key][
'percent'].
'%)';
12210 } elseif ($histo[$key][
'percent'] >= 100) {
12211 $colorClass =
'timeline-icon-done';
12212 $pictoTitle = $langs->trans(
'StatusActionDone').
' (100%)';
12215 if ($actionstatic->code ==
'AC_TICKET_CREATE') {
12216 $iconClass =
'fa fa-ticket';
12217 } elseif ($actionstatic->code ==
'AC_TICKET_MODIFY') {
12218 $iconClass =
'fa fa-pencilxxx';
12219 } elseif (preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
12220 $iconClass =
'fa fa-comments';
12221 } elseif (preg_match(
'/^TICKET_MSG_PRIVATE/', $actionstatic->code)) {
12222 $iconClass =
'fa fa-mask';
12223 } elseif (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
12224 if ($actionstatic->type_picto) {
12225 $img_picto =
img_picto(
'', $actionstatic->type_picto);
12227 if ($actionstatic->type_code ==
'AC_RDV') {
12228 $iconClass =
'fa fa-handshake';
12229 } elseif ($actionstatic->type_code ==
'AC_TEL') {
12230 $iconClass =
'fa fa-phone';
12231 } elseif ($actionstatic->type_code ==
'AC_FAX') {
12232 $iconClass =
'fa fa-fax';
12233 } elseif ($actionstatic->type_code ==
'AC_EMAIL') {
12234 $iconClass =
'fa fa-envelope';
12235 } elseif ($actionstatic->type_code ==
'AC_INT') {
12236 $iconClass =
'fa fa-shipping-fast';
12237 } elseif ($actionstatic->type_code ==
'AC_OTH_AUTO') {
12238 $iconClass =
'fa fa-robot';
12239 } elseif (!preg_match(
'/_AUTO/', $actionstatic->type_code)) {
12240 $iconClass =
'fa fa-robot';
12245 $out .=
'<i class="'.$iconClass.
' '.$colorClass.
'" title="'.$pictoTitle.
'">'.$img_picto.
'</i>'.
"\n";
12259 $documents = array();
12261 $sql =
'SELECT ecm.rowid as id, ecm.src_object_type, ecm.src_object_id, ecm.filepath, ecm.filename';
12262 $sql .=
' FROM '.MAIN_DB_PREFIX.
'ecm_files ecm';
12263 $sql .=
" WHERE ecm.filepath = 'agenda/".((int) $object->id).
"'";
12265 $sql .=
' ORDER BY ecm.position ASC';
12267 $resql = $db->query($sql);
12269 if ($db->num_rows($resql)) {
12270 while ($obj = $db->fetch_object($resql)) {
12271 $documents[$obj->id] = $obj;
12298function show_actions_messaging($conf, $langs, $db, $filterobj, $objcon =
'', $noprint = 0, $actioncode =
'', $donetodo =
'done', $filters = array(), $sortfield =
'a.datep,a.id', $sortorder =
'DESC')
12300 global $user, $conf;
12303 global $param, $massactionbutton;
12308 if (!is_object($filterobj) && !is_object($objcon)) {
12316 $sortfield_list = explode(
',', $sortfield);
12317 $sortfield_label_list = array(
'a.id' =>
'id',
'a.datep' =>
'dp',
'a.percent' =>
'percent');
12318 $sortfield_new_list = array();
12319 foreach ($sortfield_list as $sortfield_value) {
12320 $sortfield_new_list[] = $sortfield_label_list[trim($sortfield_value)];
12322 $sortfield_new = implode(
',', $sortfield_new_list);
12324 if (isModEnabled(
'agenda')) {
12326 if (is_object($objcon) && $objcon->id > 0) {
12327 $sql =
"SELECT DISTINCT a.id, a.label as label,";
12329 $sql =
"SELECT a.id, a.label as label,";
12331 $sql .=
" a.datep as dp,";
12332 $sql .=
" a.note as message,";
12333 $sql .=
" a.datep2 as dp2,";
12334 $sql .=
" a.percent as percent, 'action' as type,";
12335 $sql .=
" a.fk_element, a.elementtype,";
12336 $sql .=
" a.fk_contact,";
12337 $sql .=
" a.email_from as msg_from,";
12338 $sql .=
" c.code as acode, c.libelle as alabel, c.picto as apicto,";
12339 $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";
12340 if (is_object($filterobj) && get_class($filterobj) ==
'Societe') {
12341 $sql .=
", sp.lastname, sp.firstname";
12342 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
12343 $sql .=
", m.lastname, m.firstname";
12344 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
12346 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
12348 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
12350 } elseif (is_object($filterobj) && get_class($filterobj) ==
'BOM') {
12352 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contrat') {
12355 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
12356 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on u.rowid = a.fk_user_action";
12357 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_actioncomm as c ON a.fk_action = c.id";
12359 $force_filter_contact =
false;
12360 if (is_object($objcon) && $objcon->id > 0) {
12361 $force_filter_contact =
true;
12362 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"actioncomm_resources as r ON a.id = r.fk_actioncomm";
12363 $sql .=
" AND r.element_type = '".$db->escape($objcon->table_element).
"' AND r.fk_element = ".((int) $objcon->id);
12366 if (is_object($filterobj) && get_class($filterobj) ==
'Societe') {
12367 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as sp ON a.fk_contact = sp.rowid";
12368 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Dolresource') {
12369 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"element_resources as er";
12370 $sql .=
" ON er.resource_type = 'dolresource'";
12371 $sql .=
" AND er.element_id = a.id";
12372 $sql .=
" AND er.resource_id = ".((int) $filterobj->id);
12373 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
12374 $sql .=
", ".MAIN_DB_PREFIX.
"adherent as m";
12375 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
12376 $sql .=
", ".MAIN_DB_PREFIX.
"commande_fournisseur as o";
12377 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
12378 $sql .=
", ".MAIN_DB_PREFIX.
"product as o";
12379 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
12380 $sql .=
", ".MAIN_DB_PREFIX.
"ticket as o";
12381 } elseif (is_object($filterobj) && get_class($filterobj) ==
'BOM') {
12382 $sql .=
", ".MAIN_DB_PREFIX.
"bom_bom as o";
12383 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contrat') {
12384 $sql .=
", ".MAIN_DB_PREFIX.
"contrat as o";
12387 $sql .=
" WHERE a.entity IN (".getEntity(
'agenda').
")";
12388 if ($force_filter_contact ===
false) {
12389 if (is_object($filterobj) && in_array(get_class($filterobj), array(
'Societe',
'Client',
'Fournisseur')) && $filterobj->id) {
12390 $sql .=
" AND a.fk_soc = ".((int) $filterobj->id);
12391 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Project' && $filterobj->id) {
12392 $sql .=
" AND a.fk_project = ".((int) $filterobj->id);
12393 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
12394 $sql .=
" AND a.fk_element = m.rowid AND a.elementtype = 'member'";
12395 if ($filterobj->id) {
12396 $sql .=
" AND a.fk_element = ".((int) $filterobj->id);
12398 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
12399 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'order_supplier'";
12400 if ($filterobj->id) {
12401 $sql .=
" AND a.fk_element = ".((int) $filterobj->id);
12403 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
12404 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'product'";
12405 if ($filterobj->id) {
12406 $sql .=
" AND a.fk_element = ".((int) $filterobj->id);
12408 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
12409 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'ticket'";
12410 if ($filterobj->id) {
12411 $sql .=
" AND a.fk_element = ".((int) $filterobj->id);
12413 } elseif (is_object($filterobj) && get_class($filterobj) ==
'BOM') {
12414 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'bom'";
12415 if ($filterobj->id) {
12416 $sql .=
" AND a.fk_element = ".((int) $filterobj->id);
12418 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Contrat') {
12419 $sql .=
" AND a.fk_element = o.rowid AND a.elementtype = 'contract'";
12420 if ($filterobj->id) {
12421 $sql .=
" AND a.fk_element = ".((int) $filterobj->id);
12427 if (!empty($actioncode)) {
12428 if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
12429 if ($actioncode ==
'AC_NON_AUTO') {
12430 $sql .=
" AND c.type != 'systemauto'";
12431 } elseif ($actioncode ==
'AC_ALL_AUTO') {
12432 $sql .=
" AND c.type = 'systemauto'";
12434 if ($actioncode ==
'AC_OTH') {
12435 $sql .=
" AND c.type != 'systemauto'";
12436 } elseif ($actioncode ==
'AC_OTH_AUTO') {
12437 $sql .=
" AND c.type = 'systemauto'";
12441 if ($actioncode ==
'AC_NON_AUTO') {
12442 $sql .=
" AND c.type != 'systemauto'";
12443 } elseif ($actioncode ==
'AC_ALL_AUTO') {
12444 $sql .=
" AND c.type = 'systemauto'";
12446 $sql .=
" AND c.code = '".$db->escape($actioncode).
"'";
12450 if ($donetodo ==
'todo') {
12451 $sql .=
" AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now).
"'))";
12452 } elseif ($donetodo ==
'done') {
12453 $sql .=
" AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now).
"'))";
12455 if (is_array($filters) && $filters[
'search_agenda_label']) {
12456 $sql .=
natural_search(
'a.label', $filters[
'search_agenda_label']);
12461 if (isModEnabled(
'mailing') && !empty($objcon->email)
12462 && (empty($actioncode) || $actioncode ==
'AC_OTH_AUTO' || $actioncode ==
'AC_EMAILING')) {
12463 $langs->load(
"mails");
12465 $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";
12466 $sql2 .=
", null as fk_element, '' as elementtype, null as contact_id";
12467 $sql2 .=
", 'AC_EMAILING' as acode, '' as alabel, '' as apicto";
12468 $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";
12469 if (is_object($filterobj) && get_class($filterobj) ==
'Societe') {
12470 $sql2 .=
", '' as lastname, '' as firstname";
12471 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Adherent') {
12472 $sql2 .=
", '' as lastname, '' as firstname";
12473 } elseif (is_object($filterobj) && get_class($filterobj) ==
'CommandeFournisseur') {
12474 $sql2 .=
", '' as ref";
12475 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Product') {
12476 $sql2 .=
", '' as ref";
12477 } elseif (is_object($filterobj) && get_class($filterobj) ==
'Ticket') {
12478 $sql2 .=
", '' as ref";
12480 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"mailing as m, ".MAIN_DB_PREFIX.
"mailing_cibles as mc, ".MAIN_DB_PREFIX.
"user as u";
12481 $sql2 .=
" WHERE mc.email = '".$db->escape($objcon->email).
"'";
12482 $sql2 .=
" AND mc.statut = 1";
12483 $sql2 .=
" AND u.rowid = m.fk_user_valid";
12484 $sql2 .=
" AND mc.fk_mailing=m.rowid";
12487 if (!empty($sql) && !empty($sql2)) {
12488 $sql = $sql.
" UNION ".$sql2;
12489 } elseif (empty($sql) && !empty($sql2)) {
12495 $sql .= $db->order($sortfield_new, $sortorder);
12497 dol_syslog(
"function.lib::show_actions_messaging", LOG_DEBUG);
12498 $resql = $db->query($sql);
12501 $num = $db->num_rows($resql);
12503 while ($i < $num) {
12504 $obj = $db->fetch_object($resql);
12506 if ($obj->type ==
'action') {
12508 $contactaction->id = $obj->id;
12509 $result = $contactaction->fetchResources();
12512 setEventMessage(
"actions.lib::show_actions_messaging Error fetch ressource",
'errors');
12518 if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && $obj->dp > $now)) {
12519 $tododone =
'todo';
12522 $histo[$numaction] = array(
12523 'type'=>$obj->type,
12524 'tododone'=>$tododone,
12526 'datestart'=>$db->jdate($obj->dp),
12527 'dateend'=>$db->jdate($obj->dp2),
12528 'note'=>$obj->label,
12529 'message'=>$obj->message,
12530 'percent'=>$obj->percent,
12532 'userid'=>$obj->user_id,
12533 'login'=>$obj->user_login,
12534 'userfirstname'=>$obj->user_firstname,
12535 'userlastname'=>$obj->user_lastname,
12536 'userphoto'=>$obj->user_photo,
12537 'msg_from'=>$obj->msg_from,
12539 'contact_id'=>$obj->fk_contact,
12540 'socpeopleassigned' => $contactaction->socpeopleassigned,
12541 'lastname' => (empty($obj->lastname) ?
'' : $obj->lastname),
12542 'firstname' => (empty($obj->firstname) ?
'' : $obj->firstname),
12543 'fk_element'=>$obj->fk_element,
12544 'elementtype'=>$obj->elementtype,
12546 'acode'=>$obj->acode,
12547 'alabel'=>$obj->alabel,
12548 'libelle'=>$obj->alabel,
12549 'apicto'=>$obj->apicto
12552 $histo[$numaction] = array(
12553 'type'=>$obj->type,
12554 'tododone'=>
'done',
12556 'datestart'=>$db->jdate($obj->dp),
12557 'dateend'=>$db->jdate($obj->dp2),
12558 'note'=>$obj->label,
12559 'message'=>$obj->message,
12560 'percent'=>$obj->percent,
12561 'acode'=>$obj->acode,
12563 'userid'=>$obj->user_id,
12564 'login'=>$obj->user_login,
12565 'userfirstname'=>$obj->user_firstname,
12566 'userlastname'=>$obj->user_lastname,
12567 'userphoto'=>$obj->user_photo
12582 if (!isModEnabled(
'agenda')) {
12583 $langs->loadLangs(array(
"admin",
"errors"));
12584 $out =
info_admin($langs->trans(
"WarningModuleXDisabledSoYouMayMissEventHere", $langs->transnoentitiesnoconv(
"Module2400Name")), 0, 0,
'warning');
12587 if (isModEnabled(
'agenda') || (isModEnabled(
'mailing') && !empty($objcon->email))) {
12588 $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
12590 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
12591 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
12592 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
12593 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
12598 $userstatic =
new User($db);
12599 $contactstatic =
new Contact($db);
12600 $userGetNomUrlCache = array();
12601 $contactGetNomUrlCache = array();
12603 $out .=
'<div class="filters-container" >';
12604 $out .=
'<form name="listactionsfilter" class="listactionsfilter" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
12605 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
12607 if ($objcon && get_class($objcon) ==
'Contact' &&
12608 (is_null($filterobj) || get_class($filterobj) ==
'Societe')) {
12609 $out .=
'<input type="hidden" name="id" value="'.$objcon->id.
'" />';
12611 $out .=
'<input type="hidden" name="id" value="'.$filterobj->id.
'" />';
12613 if ($filterobj && get_class($filterobj) ==
'Societe') {
12614 $out .=
'<input type="hidden" name="socid" value="'.$filterobj->id.
'" />';
12619 $out .=
'<div class="div-table-responsive-no-min">';
12620 $out .=
'<table class="noborder borderbottom centpercent">';
12622 $out .=
'<tr class="liste_titre">';
12626 $out .=
'<th class="liste_titre width50 middle">';
12627 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
12628 $out .= $searchpicto;
12632 $out .=
getTitleFieldOfList(
'Date', 0, $_SERVER[
"PHP_SELF"],
'a.datep',
'', $param,
'', $sortfield, $sortorder,
'').
"\n";
12634 $out .=
'<th class="liste_titre"><strong class="hideonsmartphone">'.$langs->trans(
"Search").
' : </strong></th>';
12636 $out .=
'<th class="liste_titre"></th>';
12638 $out .=
'<th class="liste_titre">';
12639 $out .=
'<span class="fas fa-square inline-block fawidth30" style=" color: #ddd;" title="'.$langs->trans(
"ActionType").
'"></span>';
12641 $out .=
$formactions->select_type_actions($actioncode,
"actioncode",
'', empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : -1, 0, 0, 1,
'minwidth200imp');
12643 $out .=
'<th class="liste_titre maxwidth100onsmartphone">';
12644 $out .=
'<input type="text" class="maxwidth100onsmartphone" name="search_agenda_label" value="'.$filters[
'search_agenda_label'].
'" placeholder="'.$langs->trans(
"Label").
'">';
12649 $out .=
'<th class="liste_titre width50 middle">';
12650 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
12651 $out .= $searchpicto;
12658 $out .=
'</table>';
12665 $out .=
'<ul class="timeline">';
12669 if (get_class($filterobj) ==
'Societe') {
12670 $tmp .=
'<a href="'.DOL_URL_ROOT.
'/comm/action/list.php?mode=show_list&socid='.$filterobj->id.
'&status=done">';
12672 $tmp .= ($donetodo !=
'done' ? $langs->trans(
"ActionsToDoShort") :
'');
12673 $tmp .= ($donetodo !=
'done' && $donetodo !=
'todo' ?
' / ' :
'');
12674 $tmp .= ($donetodo !=
'todo' ? $langs->trans(
"ActionsDoneShort") :
'');
12676 if (get_class($filterobj) ==
'Societe') {
12687 $actualCycleDate =
false;
12690 foreach ($histo as $key => $value) {
12691 $actionstatic->fetch($histo[$key][
'id']);
12693 $actionstatic->type_picto = $histo[$key][
'apicto'];
12694 $actionstatic->type_code = $histo[$key][
'acode'];
12696 $url = DOL_URL_ROOT.
'/comm/action/card.php?id='.$histo[$key][
'id'];
12698 $tmpa =
dol_getdate($histo[$key][
'datestart'],
false);
12699 if ($actualCycleDate !== $tmpa[
'year'].
'-'.$tmpa[
'yday']) {
12700 $actualCycleDate = $tmpa[
'year'].
'-'.$tmpa[
'yday'];
12701 $out .=
'<!-- timeline time label -->';
12702 $out .=
'<li class="time-label">';
12703 $out .=
'<span class="timeline-badge-date">';
12704 $out .=
dol_print_date($histo[$key][
'datestart'],
'daytext',
'tzuserrel', $langs);
12707 $out .=
'<!-- /.timeline-label -->';
12711 $out .=
'<!-- timeline item -->'.
"\n";
12712 $out .=
'<li class="timeline-code-'.strtolower($actionstatic->code).
'">';
12716 $out .=
'<div class="timeline-item">'.
"\n";
12718 $out .=
'<span class="timeline-header-action">';
12720 if (isset($histo[$key][
'type']) && $histo[$key][
'type'] ==
'mailing') {
12721 $out .=
'<a class="timeline-btn" href="'.DOL_URL_ROOT.
'/comm/mailing/card.php?id='.$histo[$key][
'id'].
'">'.
img_object($langs->trans(
"ShowEMailing"),
"email").
' ';
12722 $out .= $histo[$key][
'id'];
12725 $out .= $actionstatic->getNomUrl(1, -1,
'valignmiddle').
' ';
12728 if ($user->hasRight(
'agenda',
'allactions',
'create') ||
12729 (($actionstatic->authorid == $user->id || $actionstatic->userownerid == $user->id) && $user->hasRight(
'agenda',
'myactions',
'create'))) {
12730 $out .=
'<a class="timeline-btn" href="'.DOL_MAIN_URL_ROOT.
'/comm/action/card.php?action=edit&token='.
newToken().
'&id='.$actionstatic->id.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?'.$param).
'"><i class="fa fa-pencil" title="'.$langs->trans(
"Modify").
'" ></i></a>';
12735 $out .=
'<span class="time"><i class="fa fa-clock-o valignmiddle"></i> <span class="valignmiddle">';
12736 $out .=
dol_print_date($histo[$key][
'datestart'],
'dayhour',
'tzuserrel');
12737 if ($histo[$key][
'dateend'] && $histo[$key][
'dateend'] != $histo[$key][
'datestart']) {
12738 $tmpa =
dol_getdate($histo[$key][
'datestart'],
true);
12739 $tmpb =
dol_getdate($histo[$key][
'dateend'],
true);
12740 if ($tmpa[
'mday'] == $tmpb[
'mday'] && $tmpa[
'mon'] == $tmpb[
'mon'] && $tmpa[
'year'] == $tmpb[
'year']) {
12741 $out .=
'-'.dol_print_date($histo[$key][
'dateend'],
'hour',
'tzuserrel');
12743 $out .=
'-'.dol_print_date($histo[$key][
'dateend'],
'dayhour',
'tzuserrel');
12747 if ($histo[$key][
'percent'] == 0 && $histo[$key][
'datestart'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
12750 if ($histo[$key][
'percent'] == 0 && !$histo[$key][
'datestart'] && $histo[$key][
'dateend'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
12753 if ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100 && $histo[$key][
'dateend'] && $histo[$key][
'dateend'] < ($now - $delay_warning)) {
12756 if ($histo[$key][
'percent'] > 0 && $histo[$key][
'percent'] < 100 && !$histo[$key][
'dateend'] && $histo[$key][
'datestart'] && $histo[$key][
'datestart'] < ($now - $delay_warning)) {
12762 $out .=
"</span></span>\n";
12765 $out .=
'<h3 class="timeline-header">';
12768 $out .=
'<div class="messaging-author inline-block tdoverflowmax150 valignmiddle marginrightonly">';
12769 if ($histo[$key][
'userid'] > 0) {
12770 if (!isset($userGetNomUrlCache[$histo[$key][
'userid']])) {
12771 $userstatic->fetch($histo[$key][
'userid']);
12772 $userGetNomUrlCache[$histo[$key][
'userid']] = $userstatic->getNomUrl(-1,
'', 0, 0, 16, 0,
'firstelselast',
'');
12774 $out .= $userGetNomUrlCache[$histo[$key][
'userid']];
12775 } elseif (!empty($histo[$key][
'msg_from']) && $actionstatic->code ==
'TICKET_MSG') {
12776 if (!isset($contactGetNomUrlCache[$histo[$key][
'msg_from']])) {
12777 if ($contactstatic->fetch(0,
null,
'', $histo[$key][
'msg_from']) > 0) {
12778 $contactGetNomUrlCache[$histo[$key][
'msg_from']] = $contactstatic->getNomUrl(-1,
'', 16);
12780 $contactGetNomUrlCache[$histo[$key][
'msg_from']] = $histo[$key][
'msg_from'];
12783 $out .= $contactGetNomUrlCache[$histo[$key][
'msg_from']];
12789 $out .=
' <div class="messaging-title inline-block">';
12791 if (preg_match(
'/^TICKET_MSG/', $actionstatic->code)) {
12792 $out .= $langs->trans(
'TicketNewMessage');
12793 } elseif (preg_match(
'/^TICKET_MSG_PRIVATE/', $actionstatic->code)) {
12794 $out .= $langs->trans(
'TicketNewMessage').
' <em>('.$langs->trans(
'Private').
')</em>';
12795 } elseif (isset($histo[$key][
'type'])) {
12796 if ($histo[$key][
'type'] ==
'action') {
12797 $transcode = $langs->transnoentitiesnoconv(
"Action".$histo[$key][
'acode']);
12798 $libelle = ($transcode !=
"Action".$histo[$key][
'acode'] ? $transcode : $histo[$key][
'alabel']);
12799 $libelle = $histo[$key][
'note'];
12800 $actionstatic->id = $histo[$key][
'id'];
12802 } elseif ($histo[$key][
'type'] ==
'mailing') {
12803 $out .=
'<a href="'.DOL_URL_ROOT.
'/comm/mailing/card.php?id='.$histo[$key][
'id'].
'">'.
img_object($langs->trans(
"ShowEMailing"),
"email").
' ';
12804 $transcode = $langs->transnoentitiesnoconv(
"Action".$histo[$key][
'acode']);
12805 $libelle = ($transcode !=
"Action".$histo[$key][
'acode'] ? $transcode :
'Send mass mailing');
12808 $libelle .= $histo[$key][
'note'];
12817 if (!empty($histo[$key][
'message'] && $histo[$key][
'message'] != $libelle)
12818 && $actionstatic->code !=
'AC_TICKET_CREATE'
12819 && $actionstatic->code !=
'AC_TICKET_MODIFY'
12821 $out .=
'<div class="timeline-body">';
12822 $out .= $histo[$key][
'message'];
12830 if (isset($histo[$key][
'socpeopleassigned']) && is_array($histo[$key][
'socpeopleassigned']) && count($histo[$key][
'socpeopleassigned']) > 0) {
12832 foreach ($histo[$key][
'socpeopleassigned'] as $cid => $Tab) {
12834 $result = $contact->fetch($cid);
12841 $contactList .= !empty($contactList) ?
', ' :
'';
12842 $contactList .= $contact->getNomUrl(1);
12843 if (isset($histo[$key][
'acode']) && $histo[$key][
'acode'] ==
'AC_TEL') {
12844 if (!empty($contact->phone_pro)) {
12845 $contactList .=
'('.dol_print_phone($contact->phone_pro).
')';
12851 $footer .= $langs->trans(
'ActionOnContact').
' : '.$contactList;
12852 } elseif (empty($objcon->id) && isset($histo[$key][
'contact_id']) && $histo[$key][
'contact_id'] > 0) {
12854 $result = $contact->fetch($histo[$key][
'contact_id']);
12861 $footer .= $contact->getNomUrl(1);
12862 if (isset($histo[$key][
'acode']) && $histo[$key][
'acode'] ==
'AC_TEL') {
12863 if (!empty($contact->phone_pro)) {
12864 $footer .=
'('.dol_print_phone($contact->phone_pro).
')';
12871 if (!empty($documents)) {
12872 $footer .=
'<div class="timeline-documents-container">';
12873 foreach ($documents as $doc) {
12874 $footer .=
'<span id="document_'.$doc->id.
'" class="timeline-documents" ';
12875 $footer .=
' data-id="'.$doc->id.
'" ';
12876 $footer .=
' data-path="'.$doc->filepath.
'"';
12877 $footer .=
' data-filename="'.dol_escape_htmltag($doc->filename).
'" ';
12880 $filePath = DOL_DATA_ROOT.
'/'.$doc->filepath.
'/'.$doc->filename;
12882 $file = $actionstatic->id.
'/'.$doc->filename;
12883 $thumb = $actionstatic->id.
'/thumbs/'.substr($doc->filename, 0, strrpos($doc->filename,
'.')).
'_mini'.substr($doc->filename, strrpos($doc->filename,
'.'));
12884 $doclink =
dol_buildpath(
'document.php', 1).
'?modulepart=actions&attachment=0&file='.urlencode($file).
'&entity='.$conf->entity;
12885 $viewlink =
dol_buildpath(
'viewimage.php', 1).
'?modulepart=actions&file='.urlencode($thumb).
'&entity='.$conf->entity;
12887 $mimeAttr =
' mime="'.$mime.
'" ';
12889 if (in_array($mime, array(
'image/png',
'image/jpeg',
'application/pdf'))) {
12890 $class .=
' documentpreview';
12893 $footer .=
'<a href="'.$doclink.
'" class="btn-link '.$class.
'" target="_blank" rel="noopener noreferrer" '.$mimeAttr.
' >';
12894 $footer .=
img_mime($filePath).
' '.$doc->filename;
12897 $footer .=
'</span>';
12899 $footer .=
'</div>';
12902 if (!empty($footer)) {
12903 $out .=
'<div class="timeline-footer">'.$footer.
'</div>';
12906 $out .=
'</div>'.
"\n";
12909 $out .=
'<!-- END timeline item -->';
12916 if (empty($histo)) {
12917 $out .=
'<span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span>';
12940 if ($hourTime ===
'getpost') {
12944 } elseif (preg_match(
'/^(\d\d):(\d\d):(\d\d)$/', $hourTime, $m)) {
12945 $hour = intval($m[1]);
12946 $minute = intval($m[2]);
12947 $second = intval($m[3]);
12949 $hour = $minute = $second = 0;
12952 $hour = min($hour, 23);
12953 $minute = min($minute, 59);
12954 $second = min($second, 59);
12971 if ($timestamp ===
null) $timestamp =
GETPOSTDATE($prefix, $hourTime, $gm);
12977 if ($hourTime ===
'getpost' || ($timestamp !==
null &&
dol_print_date($timestamp,
'%H:%M:%S') !==
'00:00:00')) {
12978 $TParam = array_merge($TParam, array(
12985 return '&' . http_build_query($TParam);
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif( $action=='specimen') elseif($action=='setmodel') elseif( $action=='del') elseif($action=='setdoc') $formactions
View.
ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input=array(), $morecss='', $htmlname='', $forcenojs=0)
On/off button to change a property status of an object This uses the ajax service objectonoff....
Class to manage agenda events (actions)
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()
Return if third party is a company (Business) or an end user (Consumer)
Class to manage translations.
Class to manage Dolibarr users.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
dol_get_prev_month($month, $year)
Return previous month.
dol_get_next_day($day, $month, $year)
Return next day.
getServerTimeZoneInt($refgmtdate='now')
Return server timezone int.
dol_get_prev_day($day, $month, $year)
Return previous day.
dol_get_next_month($month, $year)
Return next month.
dol_convert_file($fileinput, $ext='png', $fileoutput='', $page='')
Convert an image file or a PDF into another image format.
dragAndDropFileUpload($htmlname)
Function to manage the drag and drop of a file.
dol_dir_list($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.
isValidVATID($company)
Check if VAT numero is valid (check done on syntax only, no database or remote access)
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
dol_fiche_end($notab=0)
Show tab footer of a card.
dolCheckFilters($sqlfilters, &$error='')
Return if a $sqlfilters parameter has a valid balance of parenthesis.
dol_print_size($size, $shortvalue=0, $shortunit=0)
Return string with formated size.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
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 informations (by default a local PHP server timestamp) Re...
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) Si ...
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.
finishSimpleTable($addLineBreak=false)
Add the correct HTML close tags for "startSimpleTable(...)" (use after the last table line)
startSimpleTable($header, $link="", $arguments="", $emptyRows=0, $number=-1)
Start a table with headers and a optinal clickable number (don't forget to use "finishSimpleTable()" ...
getLanguageCodeFromCountryCode($countrycode)
Return default language from country code.
setEntity($currentobject)
Set entity id to use when to create an object.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
dol_print_socialnetworks($value, $cid, $socid, $type, $dictsocialnetworks=array())
Show social network link.
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.
img_right($titlealt='default', $selected=0, $moreatt='')
Show right arrow logo.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_left($titlealt='default', $selected=0, $moreatt='')
Show left arrow logo.
dol_print_ip($ip, $mode=0)
Return an IP formated to be shown on screen.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
isVisibleToUserType($type_user, &$menuentry, &$listofmodulesforexternal)
Function to test if an entry is enabled or not.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
isASecretKey($keyname)
Return if string has a name dedicated to store a secret.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $hideselectlimit=0, $beforearrows='', $hidenavigation=0)
Function to show navigation arrows into lists.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
get_date_range($date_start, $date_end, $format='', $outputlangs='', $withparenthesis=1)
Format output for start and end date.
get_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Get formated error messages to output (Used to show messages on html output).
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
roundUpToNextMultiple($n, $x=5)
Round to next multiple.
dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled='', $morecss='classlink button bordertransp', $jsonopen='', $backtopagejsfields='', $accesskey='')
Return HTML code to output a button to open a dialog popup box.
dol_user_country()
Return country code for current user.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs='', $mode=0, $extralangcode='')
Return a formated address (part address/zip/town/state) according to country rules.
isHTTPS()
Return if we are using a HTTPS connexion Check HTTPS (no way to be modified by user but may be empty ...
currentToken()
Return the value of token currently saved into session with name 'token'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
picto_required()
Return picto saying a field is required.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
img_action($titlealt, $numaction, $picto='', $moreatt='')
Show logo action.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
GETPOSTDATE($prefix, $hourTime='', $gm='auto')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
printCommonFooter($zone='private')
Print common footer : conf->global->MAIN_HTML_FOOTER js for switch of menu hider js for conf->global-...
checkVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1)
Get tax (VAT) main information from Id.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
utf8_valid($str)
Check if a string is in UTF8.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
img_allow($allow, $titlealt='default')
Show tick logo if allowed.
isValidMXRecord($domain)
Return if the domain name has a valid MX record.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
get_htmloutput_mesg($mesgstring='', $mesgarray='', $style='ok', $keepembedded=0)
Get formated messages to output (Used to show messages on html output).
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tab header of a card.
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
get_localtax_by_third($local)
Get values of localtaxes (1 or 2) for company country for the common vat with the highest value.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0)
Clean a string to keep only desirable HTML tags.
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_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
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_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_strftime($fmt, $ts=false, $is_gmt=false)
Format a string.
img_picto_common($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $notitle=0)
Show picto (generic function)
img_search($titlealt='default', $other='')
Show search logo.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
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.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
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.
dol_print_profids($profID, $profIDtype, $countrycode='', $addcpButton=1, $separ=' ')
Format profIDs according to country.
fieldLabel($langkey, $fieldkey, $fieldrequired=0)
Show a string with the label tag dedicated to the HTML edit field.
getBrowserInfo($user_agent)
Return information about user browser.
dolGetFirstLetters($s, $nbofchar=1)
Return first letters of a strings.
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
dol_sanitizeUrl($stringtoclean, $type=1)
Clean a string to use it as an URL (into a href or src attribute)
img_printer($titlealt="default", $other='')
Show printer logo.
dol_htmloutput_events($disabledoutputofmessages=0)
Print formated 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.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
getArrayOfSocialNetworks()
Get array of social network dictionary.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
dol_string_onlythesehtmlattributes($stringtoclean, $allowed_attributes=array("allow", "allowfullscreen", "alt", "class", "contenteditable", "data-html", "frameborder", "height", "href", "id", "name", "src", "style", "target", "title", "width"))
Clean a string from some undesirable HTML tags.
num2Alpha($n)
Return a numeric value into an Excel like column number.
dol_size($size, $type='')
Optimize a size for some browsers (phone, smarphone, ...)
img_split($titlealt='default', $other='class="pictosplit"')
Show split logo.
img_pdf($titlealt='default', $size=3)
Show pdf logo.
dolGetCountryCodeFromIp($ip)
Return a country code from IP.
dol_textishtml($msg, $option=0)
Return if a text is a html content.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
colorIsLight($stringcolor)
Return true if the color is light.
readfileLowMemory($fullpath_original_file_osencoded, $method=-1)
Return a file on output using a low memory.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
dol_shutdown()
Function called at end of web php process.
dol_print_address($address, $htmlid, $element, $id, $noprint=0, $charfornl='')
Format address string.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error_email($prefixcode, $errormessage='', $errormessages=array(), $morecss='error', $email='')
Show a public email and error code to contact if technical error.
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='float')
Show Url link.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
dol_bc($var, $moreclass='')
Return string to add class property on html element with pair/impair.
print_titre($title)
Show a title.
getElementProperties($element_type)
Get an array with properties of an element.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_string_nounprintableascii($str, $removetabcrlf=1)
Clean a string from all non printable ASCII chars (0x00-0x1F and 0x7F).
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
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 formated messages to output (Used to show messages on html output).
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
buildParamDate($prefix, $timestamp=null, $hourTime='', $gm='auto')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
img_next($titlealt='default', $moreatt='')
Show next logo.
print_date_range($date_start, $date_end, $format='', $outputlangs='')
Format output for start and end date.
isAFileWithExecutableContent($filename)
Return if a file can contains executable content.
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.
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).
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
get_product_localtax_for_country($idprod, $local, $thirdpartytouse)
Return localtax vat rate of a product in a particular country or default country vat if product is un...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
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 and dangerous content.
jsonOrUnserialize($stringtodecode)
Decode an encode string.
addSummaryTableLine($tableColumnCount, $num, $nbofloop=0, $total=0, $noneWord="None", $extraRightColumn=false)
Add a summary line to the current open table ("None", "XMoreLines" or "Total xxx")
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
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 +.
verifCond($strToEvaluate)
Verify if condition in string is ok or not.
if(!function_exists( 'utf8_encode')) if(!function_exists('utf8_decode')) if(!function_exists( 'str_starts_with')) if(!function_exists('str_ends_with')) if(!function_exists( 'str_contains')) getMultidirOutput($object, $module='')
Return the full path of the directory where a module (or an object of a module) stores its files.
print_fiche_titre($title, $mesg='', $picto='generic', $pictoisfullpath=0, $id='')
Show a title with picto.
get_product_vat_for_country($idprod, $thirdpartytouse, $idprodfournprice=0)
Return vat rate of a product in a particular country, or default country vat if product is unknown.
dolForgeDummyCriteriaCallback($matches)
Function to forge a SQL criteria from a Dolibarr filter syntax string.
dol_escape_json($stringtoescape)
Returns text escaped for inclusion into javascript code.
dolForgeCriteriaCallback($matches)
Function to forge a SQL criteria from a Dolibarr filter syntax string.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getUserRemoteIP()
Return the IP of remote user.
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.
img_credit_card($brand, $morecss=null)
Return image of a credit card according to its brand name.
dolPrintHTML($s)
Return a string ready to be output on HTML page To use text inside an attribute, use can use only dol...
img_searchclear($titlealt='default', $other='')
Show search logo.
dolPrintLabel($s)
Return a string label ready to be output on HTML content To use text inside an attribute,...
fetchObjectByElement($element_id, $element_type, $element_ref='')
Fetch an object from its id and element_type Inclusion of classes is automatic.
utf8_check($str)
Check if a string is in UTF8.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
show_actions_messaging($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep, a.id', $sortorder='DESC')
Show html area with actions in messaging format.
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 formated error messages to output (Used to show messages on html output).
getFieldErrorIcon($fieldValidationErrorMsg)
get field error icon
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_sanitizePathName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a path name.
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 formated text with and (WARNING: string must not have mixed and br sepa...
dolPrintHTMLForTextArea($s)
Return a string ready to be output on input textarea To use text inside an attribute,...
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...
dol_convertToWord($num, $langs, $currency='', $centimes=false)
Function to return a number into a text.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e rowid
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
if(!empty( $_SERVER[ 'MAIN_SHOW_TUNING_INFO'])) realCharForNumericEntities($matches)
Return the real char for a numeric entities.
dol_setcache($memoryid, $data, $expire=0)
Save data into a memory area shared by all users, all sessions on server.
dol_getcache($memoryid)
Read a memory area shared by all users, all sessions on server.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db name
Only used if Module[ID]Name translation string is not found.
dolGetRandomBytes($length)
Return a string of random bytes (hexa string) with length = $length fro cryptographic purposes.