46 include_once DOL_DOCUMENT_ROOT.
'/core/lib/json.lib.php';
49 if (!function_exists(
'utf8_encode')) {
56 function utf8_encode($elements)
58 return mb_convert_encoding($elements,
'UTF-8',
'ISO-8859-1');
62 if (!function_exists(
'utf8_decode')) {
69 function utf8_decode($elements)
71 return mb_convert_encoding($elements,
'ISO-8859-1',
'UTF-8');
74 if (!function_exists(
'str_starts_with')) {
82 function str_starts_with($haystack, $needle)
84 return (
string) $needle !==
'' && strncmp($haystack, $needle, strlen($needle)) === 0;
87 if (!function_exists(
'str_ends_with')) {
95 function str_ends_with($haystack, $needle)
97 return $needle !==
'' && substr($haystack, -strlen($needle)) === (string) $needle;
100 if (!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);
213 'project' =>
'projet',
214 'contract' =>
'contrat',
217 if (empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) {
218 $arrayconv[
'supplier_order'] =
'fournisseur';
219 $arrayconv[
'supplier_invoice'] =
'fournisseur';
221 if (!empty($arrayconv[$module])) {
222 $module = $arrayconv[$module];
225 return !empty($conf->modules[$module]);
242 require_once DOL_DOCUMENT_ROOT.
"/core/db/".$type.
'.class.php';
244 $class =
'DoliDB'.ucfirst($type);
245 $dolidb =
new $class($type, $host, $user, $pass, $name, $port);
266 function getEntity($element, $shared = 1, $currentobject =
null)
268 global $conf, $mc, $hookmanager, $object, $action, $db;
270 if (!is_object($hookmanager)) {
271 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
278 $element =
'contract';
280 case 'order_supplier':
281 $element =
'supplier_order';
283 case 'invoice_supplier':
284 $element =
'supplier_invoice';
288 if (is_object($mc)) {
289 $out = $mc->getEntity($element, $shared, $currentobject);
292 $addzero = array(
'user',
'usergroup',
'cronjob',
'c_email_templates',
'email_template',
'default_values');
293 if (in_array($element, $addzero)) {
296 $out .= ((int) $conf->entity);
301 'element' => $element,
304 'currentobject' => $currentobject,
307 $reshook = $hookmanager->executeHooks(
'hookGetEntity', $parameters, $currentobject, $action);
309 if (is_numeric($reshook)) {
310 if ($reshook == 0 && !empty($hookmanager->resPrint)) {
311 $out .=
','.$hookmanager->resPrint;
312 } elseif ($reshook == 1) {
313 $out = $hookmanager->resPrint;
330 if (is_object($mc) && method_exists($mc,
'setEntity')) {
331 return $mc->setEntity($currentobject);
333 return ((is_object($currentobject) && $currentobject->id > 0 && $currentobject->entity > 0) ? $currentobject->entity : $conf->entity);
345 return preg_match(
'/(_pass|password|_pw|_key|securekey|serverkey|secret\d?|p12key|exportkey|_PW_[a-z]+|token)$/i', $keyname);
357 for ($r =
""; $n >= 0; $n = intval($n / 26) - 1)
358 $r = chr($n % 26 + 0x41) . $r;
381 include_once DOL_DOCUMENT_ROOT.
'/includes/mobiledetect/mobiledetectlib/Mobile_Detect.php';
388 $user_agent = substr($user_agent, 0, 512);
390 $detectmobile =
new Mobile_Detect(
null, $user_agent);
391 $tablet = $detectmobile->isTablet();
393 if ($detectmobile->isMobile()) {
397 if ($detectmobile->is(
'AndroidOS')) {
398 $os = $phone =
'android';
399 } elseif ($detectmobile->is(
'BlackBerryOS')) {
400 $os = $phone =
'blackberry';
401 } elseif ($detectmobile->is(
'iOS')) {
404 } elseif ($detectmobile->is(
'PalmOS')) {
405 $os = $phone =
'palm';
406 } elseif ($detectmobile->is(
'SymbianOS')) {
408 } elseif ($detectmobile->is(
'webOS')) {
410 } elseif ($detectmobile->is(
'MaemoOS')) {
412 } elseif ($detectmobile->is(
'WindowsMobileOS') || $detectmobile->is(
'WindowsPhoneOS')) {
418 if (preg_match(
'/linux/i', $user_agent)) {
420 } elseif (preg_match(
'/macintosh/i', $user_agent)) {
422 } elseif (preg_match(
'/windows/i', $user_agent)) {
428 if (preg_match(
'/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
430 $version = empty($reg[2]) ?
'' : $reg[2];
431 } elseif (preg_match(
'/edge(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
433 $version = empty($reg[2]) ?
'' : $reg[2];
434 } elseif (preg_match(
'/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg)) {
436 $version = empty($reg[2]) ?
'' : $reg[2];
437 } elseif (preg_match(
'/chrome/i', $user_agent, $reg)) {
440 } elseif (preg_match(
'/iceweasel/i', $user_agent)) {
442 } elseif (preg_match(
'/epiphany/i', $user_agent)) {
444 } elseif (preg_match(
'/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
446 $version = empty($reg[2]) ?
'' : $reg[2];
447 } elseif (preg_match(
'/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
450 $version = empty($reg[2]) ?
'' : $reg[2];
451 } elseif (preg_match(
'/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
453 $version = end($reg);
454 } elseif (preg_match(
'/(Windows NT\s([0-9]+\.[0-9])).*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
457 $version = end($reg);
458 } elseif (preg_match(
'/l[iy]n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) {
461 $version = empty($reg[3]) ?
'' : $reg[3];
473 'browsername' => $name,
474 'browserversion' => $version,
476 'browserua' => $user_agent,
490 global $user, $langs, $db;
491 $disconnectdone =
false;
493 if (is_object($db) && !empty($db->connected)) {
494 $depth = $db->transaction_opened;
495 $disconnectdone = $db->close();
497 dol_syslog(
"--- End access to ".$_SERVER[
"PHP_SELF"].(($disconnectdone && $depth) ?
' (Warn: db disconnection forced, transaction depth was '.$depth.
')' :
''), (($disconnectdone && $depth) ? LOG_WARNING : LOG_INFO));
513 $relativepathstring = $_SERVER[
"PHP_SELF"];
515 if (constant(
'DOL_URL_ROOT')) {
516 $relativepathstring = preg_replace(
'/^'.preg_quote(constant(
'DOL_URL_ROOT'),
'/').
'/',
'', $relativepathstring);
518 $relativepathstring = preg_replace(
'/^\//',
'', $relativepathstring);
519 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
525 if (!empty($_GET[
'restore_lastsearch_values'])) {
526 if (!empty($_SESSION[
'lastsearch_values_'.$relativepathstring])) {
527 $tmp = json_decode($_SESSION[
'lastsearch_values_'.$relativepathstring],
true);
528 if (is_array($tmp)) {
529 foreach ($tmp as $key => $val) {
530 if ($key == $paramname) {
538 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_'.$relativepathstring])) {
540 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_'.$relativepathstring])) {
542 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_'.$relativepathstring])) {
544 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_'.$relativepathstring])) {
548 $isset = (isset($_POST[$paramname]) || isset($_GET[$paramname]));
565 if (empty($method)) {
566 $val = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
567 } elseif ($method == 1) {
568 $val = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
569 } elseif ($method == 2) {
570 $val = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
571 } elseif ($method == 3) {
572 $val = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
574 $val =
'BadFirstParameterForGETPOST';
577 return is_array($val);
609 function GETPOST($paramname, $check =
'alphanohtml', $method = 0, $filter =
null, $options =
null, $noreplace = 0)
611 global $mysoc, $user, $conf;
613 if (empty($paramname)) {
614 return 'BadFirstParameterForGETPOST';
617 dol_syslog(
"Deprecated use of GETPOST, called with 1st param = ".$paramname.
" and 2nd param is '', when calling page ".$_SERVER[
"PHP_SELF"], LOG_WARNING);
622 if (empty($method)) {
623 $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
624 } elseif ($method == 1) {
625 $out = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
626 } elseif ($method == 2) {
627 $out = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
628 } elseif ($method == 3) {
629 $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
631 return 'BadThirdParameterForGETPOST';
634 if (empty($method) || $method == 3 || $method == 4) {
635 $relativepathstring = $_SERVER[
"PHP_SELF"];
637 if (constant(
'DOL_URL_ROOT')) {
638 $relativepathstring = preg_replace(
'/^'.preg_quote(constant(
'DOL_URL_ROOT'),
'/').
'/',
'', $relativepathstring);
640 $relativepathstring = preg_replace(
'/^\//',
'', $relativepathstring);
641 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
647 if (!empty($_GET[
'restore_lastsearch_values'])) {
648 if (!empty($_SESSION[
'lastsearch_values_'.$relativepathstring])) {
649 $tmp = json_decode($_SESSION[
'lastsearch_values_'.$relativepathstring],
true);
650 if (is_array($tmp)) {
651 foreach ($tmp as $key => $val) {
652 if ($key == $paramname) {
660 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_'.$relativepathstring])) {
661 $out = $_SESSION[
'lastsearch_contextpage_'.$relativepathstring];
662 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_'.$relativepathstring])) {
663 $out = $_SESSION[
'lastsearch_limit_'.$relativepathstring];
664 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_'.$relativepathstring])) {
665 $out = $_SESSION[
'lastsearch_page_'.$relativepathstring];
666 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_'.$relativepathstring])) {
667 $out = $_SESSION[
'lastsearch_mode_'.$relativepathstring];
669 } elseif (!isset($_GET[
'sortfield'])) {
672 if (!empty($_GET[
'action']) && $_GET[
'action'] ==
'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
675 if (is_object($object) && isset($object->fields[$paramname][
'default'])) {
676 $out = $object->fields[$paramname][
'default'];
679 if (!empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) {
680 if (!empty($_GET[
'action']) && (preg_match(
'/^create/', $_GET[
'action']) || preg_match(
'/^presend/', $_GET[
'action'])) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
682 if (!empty($user->default_values)) {
683 if (isset($user->default_values[$relativepathstring][
'createform'])) {
684 foreach ($user->default_values[$relativepathstring][
'createform'] as $defkey => $defval) {
686 if ($defkey !=
'_noquery_') {
687 $tmpqueryarraytohave = explode(
'&', $defkey);
690 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
691 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
704 if (isset($user->default_values[$relativepathstring][
'createform'][$defkey][$paramname])) {
705 $out = $user->default_values[$relativepathstring][
'createform'][$defkey][$paramname];
712 } elseif (!empty($paramname) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
714 if (!empty($user->default_values)) {
717 if ($paramname ==
'sortfield' || $paramname ==
'sortorder') {
719 if (isset($user->default_values[$relativepathstring][
'sortorder'])) {
721 foreach ($user->default_values[$relativepathstring][
'sortorder'] as $defkey => $defval) {
723 if ($defkey !=
'_noquery_') {
724 $tmpqueryarraytohave = explode(
'&', $defkey);
727 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
728 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
741 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
742 foreach ($user->default_values[$relativepathstring][
'sortorder'][$defkey] as $key => $val) {
746 if ($paramname ==
'sortfield') {
749 if ($paramname ==
'sortorder') {
757 } elseif (isset($user->default_values[$relativepathstring][
'filters'])) {
758 foreach ($user->default_values[$relativepathstring][
'filters'] as $defkey => $defval) {
759 if (!empty($_GET[
'disabledefaultvalues'])) {
763 if ($defkey !=
'_noquery_') {
764 $tmpqueryarraytohave = explode(
'&', $defkey);
767 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
768 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
780 if ($qualified && isset($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname])) {
782 if (isset($_POST[
'sall']) || isset($_POST[
'search_all']) || isset($_GET[
'sall']) || isset($_GET[
'search_all'])) {
784 if (empty($conf->global->MAIN_DISABLE_DEFAULT_FILTER_FOR_QUICK_SEARCH)) {
785 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
786 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
789 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
790 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
805 if (!is_array($out) && empty($_POST[$paramname]) && empty($noreplace)) {
809 while (preg_match(
'/__([A-Z0-9]+_?[A-Z0-9]+)__/i', $out, $reg) && ($loopnb < $maxloop)) {
813 if ($reg[1] ==
'DAY') {
815 $newout = $tmp[
'mday'];
816 } elseif ($reg[1] ==
'MONTH') {
818 $newout = $tmp[
'mon'];
819 } elseif ($reg[1] ==
'YEAR') {
821 $newout = $tmp[
'year'];
822 } elseif ($reg[1] ==
'PREVIOUS_DAY') {
825 $newout = $tmp2[
'day'];
826 } elseif ($reg[1] ==
'PREVIOUS_MONTH') {
829 $newout = $tmp2[
'month'];
830 } elseif ($reg[1] ==
'PREVIOUS_YEAR') {
832 $newout = ($tmp[
'year'] - 1);
833 } elseif ($reg[1] ==
'NEXT_DAY') {
836 $newout = $tmp2[
'day'];
837 } elseif ($reg[1] ==
'NEXT_MONTH') {
840 $newout = $tmp2[
'month'];
841 } elseif ($reg[1] ==
'NEXT_YEAR') {
843 $newout = ($tmp[
'year'] + 1);
844 } elseif ($reg[1] ==
'MYCOMPANY_COUNTRY_ID' || $reg[1] ==
'MYCOUNTRY_ID' || $reg[1] ==
'MYCOUNTRYID') {
845 $newout = $mysoc->country_id;
846 } elseif ($reg[1] ==
'USER_ID' || $reg[1] ==
'USERID') {
848 } elseif ($reg[1] ==
'USER_SUPERVISOR_ID' || $reg[1] ==
'SUPERVISOR_ID' || $reg[1] ==
'SUPERVISORID') {
849 $newout = $user->fk_user;
850 } elseif ($reg[1] ==
'ENTITY_ID' || $reg[1] ==
'ENTITYID') {
851 $newout = $conf->entity;
856 $out = preg_replace(
'/__'.preg_quote($reg[1],
'/').
'__/', $newout, $out);
861 if (preg_match(
'/^array/', $check)) {
862 if (!is_array($out) || empty($out)) {
865 $tmparray = explode(
':', $check);
866 if (!empty($tmparray[1])) {
867 $tmpcheck = $tmparray[1];
869 $tmpcheck =
'alphanohtml';
871 foreach ($out as $outkey => $outval) {
872 $out[$outkey] =
sanitizeVal($outval, $tmpcheck, $filter, $options);
878 if (strpos($paramname,
'search_') === 0) {
879 $out = preg_replace(
'/([<>])([-+]?\d)/',
'\1 \2', $out);
882 $out =
sanitizeVal($out, $check, $filter, $options);
887 if ($paramname ==
'backtopage' || $paramname ==
'backtolist' || $paramname ==
'backtourl') {
888 $out = str_replace(
'\\',
'/', $out);
889 $out = str_replace(array(
':',
';',
'@',
"\t",
' '),
'', $out);
891 $oldstringtoclean = $out;
892 $out = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $out);
893 $out = preg_replace(array(
'/^[^\?]*%/'),
'', $out);
894 $out = preg_replace(array(
'/^[a-z]*\/\s*\/+/i'),
'', $out);
895 }
while ($oldstringtoclean != $out);
900 if (empty($method) || $method == 3 || $method == 4) {
901 if (preg_match(
'/^search_/', $paramname) || in_array($paramname, array(
'sortorder',
'sortfield'))) {
908 if ($out !=
'' && isset($user)) {
909 $user->lastsearch_values_tmp[$relativepathstring][$paramname] = $out;
928 return (
int)
GETPOST($paramname,
'int', $method,
null,
null, 0);
942 function checkVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
944 return sanitizeVal($out, $check, $filter, $options);
956 function sanitizeVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
964 if (!is_numeric($out)) {
969 if (preg_match(
'/[^0-9,-]+/i', $out)) {
974 $out = filter_var($out, FILTER_SANITIZE_STRING);
977 $out = filter_var($out, FILTER_SANITIZE_EMAIL);
980 if (!is_array($out)) {
982 if (preg_match(
'/[^a-z]+/i', $out)) {
988 if (!is_array($out)) {
990 if (preg_match(
'/[^a-z0-9_\-\.]+/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)) {
1013 if (!is_array($out)) {
1016 $oldstringtoclean = $out;
1023 $out = str_ireplace(array(
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'\',
'\',
'/',
'../',
'..\\'),
'', $out);
1024 }
while ($oldstringtoclean != $out);
1028 case 'alphawithlgt':
1029 if (!is_array($out)) {
1032 $oldstringtoclean = $out;
1038 $out = str_ireplace(array(
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'\',
'\',
'/',
'../',
'..\\'),
'', $out);
1039 }
while ($oldstringtoclean != $out);
1045 case 'restricthtmlnolink':
1046 case 'restricthtml':
1047 case 'restricthtmlallowclass':
1048 case 'restricthtmlallowunvalid':
1053 if (empty($filter)) {
1054 return 'BadParameterForGETPOST - Param 3 of sanitizeVal()';
1059 $out = filter_var($out, $filter, $options);
1068 if (!function_exists(
'dol_getprefix')) {
1078 function dol_getprefix($mode =
'')
1081 if ($mode ==
'email') {
1084 if (!empty($conf->global->MAIL_PREFIX_FOR_EMAIL_ID)) {
1085 if ($conf->global->MAIL_PREFIX_FOR_EMAIL_ID !=
'SERVER_NAME') {
1086 return $conf->global->MAIL_PREFIX_FOR_EMAIL_ID;
1087 } elseif (isset($_SERVER[
"SERVER_NAME"])) {
1088 return $_SERVER[
"SERVER_NAME"];
1093 if (!empty($conf->file->instance_unique_id)) {
1094 return sha1(
'dolibarr'.$conf->file->instance_unique_id);
1098 return sha1(DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1102 global $dolibarr_main_instance_unique_id, $dolibarr_main_cookie_cryptkey;
1103 $tmp_instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ?
'' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id;
1106 if (!empty($tmp_instance_unique_id)) {
1107 return sha1(
'dolibarr'.$tmp_instance_unique_id);
1111 if (isset($_SERVER[
"SERVER_NAME"]) && isset($_SERVER[
"DOCUMENT_ROOT"])) {
1112 return sha1($_SERVER[
"SERVER_NAME"].$_SERVER[
"DOCUMENT_ROOT"].DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1114 return sha1(DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1131 global $conf, $langs, $user, $mysoc;
1135 if (!file_exists($fullpath)) {
1136 dol_syslog(
'functions::dol_include_once Tried to load unexisting file: '.$relpath, LOG_WARNING);
1140 if (!empty($classname) && !class_exists($classname)) {
1141 return include $fullpath;
1143 return include_once $fullpath;
1162 $path = preg_replace(
'/^\//',
'', $path);
1165 $res = DOL_DOCUMENT_ROOT.
'/'.$path;
1166 if (is_array($conf->file->dol_document_root)) {
1167 foreach ($conf->file->dol_document_root as $key => $dirroot) {
1168 if ($key ==
'main') {
1171 if (file_exists($dirroot.
'/'.$path)) {
1172 $res = $dirroot.
'/'.$path;
1177 if ($returnemptyifnotfound) {
1179 if ($returnemptyifnotfound == 1 || !file_exists($res)) {
1191 $res = DOL_URL_ROOT.
'/'.$path;
1194 $res = DOL_MAIN_URL_ROOT.
'/'.$path;
1197 $res = DOL_URL_ROOT.
'/'.$path;
1200 foreach ($conf->file->dol_document_root as $key => $dirroot) {
1201 if ($key ==
'main') {
1203 global $dolibarr_main_url_root;
1206 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1207 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1210 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : $urlwithroot).
'/'.$path;
1215 preg_match(
'/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i', $path, $regs);
1216 if (!empty($regs[1])) {
1218 if (file_exists($dirroot.
'/'.$regs[1])) {
1220 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : DOL_URL_ROOT).$conf->file->dol_url_root[$key].
'/'.$path;
1223 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : DOL_MAIN_URL_ROOT).$conf->file->dol_url_root[$key].
'/'.$path;
1226 global $dolibarr_main_url_root;
1229 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1230 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1233 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : $urlwithroot).$conf->file->dol_url_root[$key].
'/'.$path;
1260 if (isset($object->db) && isset($object->db->db) && is_object($object->db->db) && get_class($object->db->db) ==
'PgSql\Connection') {
1261 $tmpsavdb = $object->db;
1265 $myclone = unserialize(serialize($object));
1267 if (!empty($tmpsavdb)) {
1268 $object->db = $tmpsavdb;
1270 } elseif ($native == 2) {
1272 $myclone =
new stdClass();
1273 $tmparray = get_object_vars($object);
1275 if (is_array($tmparray)) {
1276 foreach ($tmparray as $propertykey => $propertyval) {
1277 if (is_scalar($propertyval) || is_array($propertyval)) {
1278 $myclone->$propertykey = $propertyval;
1283 $myclone = clone $object;
1301 if (empty($conf->dol_optimize_smallscreen)) {
1304 if ($type ==
'width' && $size > 250) {
1329 $filesystem_forbidden_chars = array(
'<',
'>',
'/',
'\\',
'?',
'*',
'|',
'"',
':',
'°',
'$',
';',
'`');
1331 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
1332 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $tmp);
1333 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1334 $tmp = str_replace(
'..',
'', $tmp);
1354 $filesystem_forbidden_chars = array(
'<',
'>',
'?',
'*',
'|',
'"',
'°',
'$',
';',
'`');
1356 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
1357 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $tmp);
1358 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1359 $tmp = str_replace(
'..',
'', $tmp);
1374 $stringtoclean = preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $stringtoclean);
1376 $stringtoclean = preg_replace(
'/<!--[^>]*-->/',
'', $stringtoclean);
1378 $stringtoclean = str_replace(
'\\',
'/', $stringtoclean);
1382 $stringtoclean = str_replace(array(
':',
';',
'@'),
'', $stringtoclean);
1386 $oldstringtoclean = $stringtoclean;
1389 $stringtoclean = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $stringtoclean);
1390 }
while ($oldstringtoclean != $stringtoclean);
1394 $stringtoclean = preg_replace(array(
'/^[a-z]*\/\/+/i'),
'', $stringtoclean);
1397 return $stringtoclean;
1409 $oldstringtoclean = $stringtoclean;
1410 $stringtoclean = str_ireplace(array(
'"',
':',
'[',
']',
"\n",
"\r",
'\\',
'\/'),
'', $stringtoclean);
1411 }
while ($oldstringtoclean != $stringtoclean);
1413 return $stringtoclean;
1428 if (is_null($str)) {
1433 if (extension_loaded(
'intl') && !empty($conf->global->MAIN_UNACCENT_USE_TRANSLITERATOR)) {
1434 $transliterator = Transliterator::createFromRules(
':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', Transliterator::FORWARD);
1435 return $transliterator->transliterate($str);
1438 $string = rawurlencode($str);
1439 $replacements = array(
1440 '%C3%80' =>
'A',
'%C3%81' =>
'A',
'%C3%82' =>
'A',
'%C3%83' =>
'A',
'%C3%84' =>
'A',
'%C3%85' =>
'A',
1442 '%C3%88' =>
'E',
'%C3%89' =>
'E',
'%C3%8A' =>
'E',
'%C3%8B' =>
'E',
1443 '%C3%8C' =>
'I',
'%C3%8D' =>
'I',
'%C3%8E' =>
'I',
'%C3%8F' =>
'I',
1445 '%C3%92' =>
'O',
'%C3%93' =>
'O',
'%C3%94' =>
'O',
'%C3%95' =>
'O',
'%C3%96' =>
'O',
1447 '%C3%99' =>
'U',
'%C3%9A' =>
'U',
'%C3%9B' =>
'U',
'%C3%9C' =>
'U',
1448 '%C3%9D' =>
'Y',
'%C5%B8' =>
'y',
1449 '%C3%A0' =>
'a',
'%C3%A1' =>
'a',
'%C3%A2' =>
'a',
'%C3%A3' =>
'a',
'%C3%A4' =>
'a',
'%C3%A5' =>
'a',
1451 '%C3%A8' =>
'e',
'%C3%A9' =>
'e',
'%C3%AA' =>
'e',
'%C3%AB' =>
'e',
1452 '%C3%AC' =>
'i',
'%C3%AD' =>
'i',
'%C3%AE' =>
'i',
'%C3%AF' =>
'i',
1454 '%C3%B2' =>
'o',
'%C3%B3' =>
'o',
'%C3%B4' =>
'o',
'%C3%B5' =>
'o',
'%C3%B6' =>
'o',
1456 '%C3%B9' =>
'u',
'%C3%BA' =>
'u',
'%C3%BB' =>
'u',
'%C3%BC' =>
'u',
1457 '%C3%BD' =>
'y',
'%C3%BF' =>
'y'
1459 $string = strtr($string, $replacements);
1460 return rawurldecode($string);
1465 "\xC0\xC1\xC2\xC3\xC4\xC5\xC7
1466 \xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1
1467 \xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD
1468 \xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB
1469 \xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8
1470 \xF9\xFA\xFB\xFC\xFD\xFF",
1478 $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"));
1496 function dol_string_nospecial($str, $newstr =
'_', $badcharstoreplace =
'', $badcharstoremove =
'', $keepspaces = 0)
1498 $forbidden_chars_to_replace = array(
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
",",
";",
"=",
'°',
'$',
';');
1499 if (empty($keepspaces)) {
1500 $forbidden_chars_to_replace[] =
" ";
1502 $forbidden_chars_to_remove = array();
1505 if (is_array($badcharstoreplace)) {
1506 $forbidden_chars_to_replace = $badcharstoreplace;
1508 if (is_array($badcharstoremove)) {
1509 $forbidden_chars_to_remove = $badcharstoremove;
1512 return str_replace($forbidden_chars_to_replace, $newstr, str_replace($forbidden_chars_to_remove,
"", $str));
1531 if ($removetabcrlf) {
1532 return preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $str);
1534 return preg_replace(
'/[\x00-\x08\x11-\x12\x14-\x1F\x7F]/u',
'', $str);
1548 if (is_null($stringtoescape)) {
1553 $substitjs = array(
"'"=>
"\\'",
"\r"=>
'\\r');
1555 if (empty($noescapebackslashn)) {
1556 $substitjs[
"\n"] =
'\\n';
1557 $substitjs[
'\\'] =
'\\\\';
1560 $substitjs[
"'"] =
"\\'";
1561 $substitjs[
'"'] =
"\\'";
1562 } elseif ($mode == 1) {
1563 $substitjs[
"'"] =
"\\'";
1564 } elseif ($mode == 2) {
1565 $substitjs[
'"'] =
'\\"';
1566 } elseif ($mode == 3) {
1567 $substitjs[
"'"] =
"\\'";
1568 $substitjs[
'"'] =
"\\\"";
1570 return strtr($stringtoescape, $substitjs);
1581 return str_replace(
'"',
'\"', $stringtoescape);
1600 function dol_escape_htmltag($stringtoescape, $keepb = 0, $keepn = 0, $noescapetags =
'', $escapeonlyhtmltags = 0, $cleanalsojavascript = 0)
1602 if ($noescapetags ==
'common') {
1603 $noescapetags =
'html,body,a,b,em,hr,i,u,ul,li,br,div,img,font,p,span,strong,table,tr,td,th,tbody';
1605 if ($cleanalsojavascript) {
1610 if ($escapeonlyhtmltags) {
1611 $tmp = htmlspecialchars_decode((
string) $stringtoescape, ENT_COMPAT);
1613 $tmp = html_entity_decode((
string) $stringtoescape, ENT_COMPAT,
'UTF-8');
1616 $tmp = strtr($tmp, array(
"<b>"=>
'',
'</b>'=>
''));
1619 $tmp = strtr($tmp, array(
"\r"=>
'\\r',
"\n"=>
'\\n'));
1622 if ($escapeonlyhtmltags) {
1623 return htmlspecialchars($tmp, ENT_COMPAT,
'UTF-8');
1627 $tmparrayoftags = array();
1628 if ($noescapetags) {
1629 $tmparrayoftags = explode(
',', $noescapetags);
1631 if (count($tmparrayoftags)) {
1632 foreach ($tmparrayoftags as $tagtoreplace) {
1633 $tmp = str_ireplace(
'<'.$tagtoreplace.
'>',
'__BEGINTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
1634 $tmp = str_ireplace(
'</'.$tagtoreplace.
'>',
'__ENDTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
1635 $tmp = str_ireplace(
'<'.$tagtoreplace.
' />',
'__BEGINENDTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
1639 $result = htmlentities($tmp, ENT_COMPAT,
'UTF-8');
1641 if (count($tmparrayoftags)) {
1642 foreach ($tmparrayoftags as $tagtoreplace) {
1643 $result = str_ireplace(
'__BEGINTAGTOREPLACE'.$tagtoreplace.
'__',
'<'.$tagtoreplace.
'>', $result);
1644 $result = str_ireplace(
'__ENDTAGTOREPLACE'.$tagtoreplace.
'__',
'</'.$tagtoreplace.
'>', $result);
1645 $result = str_ireplace(
'__BEGINENDTAGTOREPLACE'.$tagtoreplace.
'__',
'<'.$tagtoreplace.
' />', $result);
1662 if (function_exists(
'mb_strtolower')) {
1663 return mb_strtolower($string, $encoding);
1665 return strtolower($string);
1679 if (function_exists(
'mb_strtoupper')) {
1680 return mb_strtoupper($string, $encoding);
1682 return strtoupper($string);
1696 if (function_exists(
'mb_substr')) {
1697 return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding).mb_substr($string, 1,
null, $encoding);
1699 return ucfirst($string);
1713 if (function_exists(
'mb_convert_case')) {
1714 return mb_convert_case($string, MB_CASE_TITLE, $encoding);
1716 return ucwords($string);
1741 function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename =
'', $restricttologhandler =
'', $logcontext =
null)
1743 global $conf, $user, $debugbar;
1751 if (defined(
'USEEXTERNALSERVER') && !defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
1752 global $website, $websitekey;
1753 if (is_object($website) && !empty($website->ref)) {
1754 $suffixinfilename .=
'_website_'.$website->ref;
1755 } elseif (!empty($websitekey)) {
1756 $suffixinfilename .=
'_website_'.$websitekey;
1761 if (defined(
'USESUFFIXINLOG')) {
1762 $suffixinfilename .= constant(
'USESUFFIXINLOG');
1766 foreach ($conf->loghandlers as $loghandlerinstance) {
1767 $loghandlerinstance->setIdent($ident);
1771 if (!empty($message)) {
1773 $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');
1774 if (!array_key_exists($level, $logLevels)) {
1775 throw new Exception(
'Incorrect log level');
1781 if (empty($conf->global->MAIN_SHOW_PASSWORD_INTO_LOG)) {
1782 $message = preg_replace(
'/password=\'[^\']*\'/',
'password=\'hidden\'', $message);
1786 if ((!empty($_REQUEST[
'logtohtml']) && !empty($conf->global->MAIN_ENABLE_LOG_TO_HTML))
1787 || (!empty($user->rights->debugbar->read) && is_object($debugbar))) {
1788 $conf->logbuffer[] =
dol_print_date(time(),
"%Y-%m-%d %H:%M:%S").
" ".$logLevels[$level].
" ".$message;
1793 if (!empty($conf->global->MAIN_ENABLE_LOG_INLINE_HTML) && !empty($_GET[
"log"])) {
1794 print
"\n\n<!-- Log start\n";
1796 print
"Log end -->\n";
1800 'message' => $message,
1801 'script' => (isset($_SERVER[
'PHP_SELF']) ? basename($_SERVER[
'PHP_SELF'],
'.php') :
false),
1803 'user' => ((is_object($user) && $user->id) ? $user->login :
false),
1808 if (!empty($remoteip)) {
1809 $data[
'ip'] = $remoteip;
1811 if (!empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) && $_SERVER[
'HTTP_X_FORWARDED_FOR'] != $remoteip) {
1812 $data[
'ip'] = $_SERVER[
'HTTP_X_FORWARDED_FOR'].
' -> '.$data[
'ip'];
1813 } elseif (!empty($_SERVER[
'HTTP_CLIENT_IP']) && $_SERVER[
'HTTP_CLIENT_IP'] != $remoteip) {
1814 $data[
'ip'] = $_SERVER[
'HTTP_CLIENT_IP'].
' -> '.$data[
'ip'];
1816 } elseif (!empty($_SERVER[
'SERVER_ADDR'])) {
1818 $data[
'ip'] = $_SERVER[
'SERVER_ADDR'];
1819 } elseif (!empty($_SERVER[
'COMPUTERNAME'])) {
1821 $data[
'ip'] = $_SERVER[
'COMPUTERNAME'].(empty($_SERVER[
'USERNAME']) ?
'' :
'@'.$_SERVER[
'USERNAME']);
1822 } elseif (!empty($_SERVER[
'LOGNAME'])) {
1824 $data[
'ip'] =
'???@'.$_SERVER[
'LOGNAME'];
1828 foreach ($conf->loghandlers as $loghandlerinstance) {
1829 if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
1832 $loghandlerinstance->export($data, $suffixinfilename);
1838 foreach ($conf->loghandlers as $loghandlerinstance) {
1839 $loghandlerinstance->setIdent($ident);
1860 function dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled =
'', $morecss =
'classlink button bordertransp', $jsonopen =
'', $backtopagejsfields =
'', $accesskey =
'')
1864 if (strpos($url,
'?') > 0) {
1865 $url .=
'&dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup='.urlencode($name);
1867 $url .=
'?dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup='.urlencode($name);
1872 $backtopagejsfieldsid =
''; $backtopagejsfieldslabel =
'';
1873 if ($backtopagejsfields) {
1874 $tmpbacktopagejsfields = explode(
':', $backtopagejsfields);
1875 if (empty($tmpbacktopagejsfields[1])) {
1876 $backtopagejsfields = $name.
":".$backtopagejsfields;
1877 $tmp2backtopagejsfields = explode(
',', $tmpbacktopagejsfields[0]);
1879 $tmp2backtopagejsfields = explode(
',', $tmpbacktopagejsfields[1]);
1881 $backtopagejsfieldsid = empty($tmp2backtopagejsfields[0]) ?
'' : $tmp2backtopagejsfields[0];
1882 $backtopagejsfieldslabel = empty($tmp2backtopagejsfields[1]) ?
'' : $tmp2backtopagejsfields[1];
1883 $url .=
'&backtopagejsfields='.urlencode($backtopagejsfields);
1887 $out .=
'<!-- a link for button to open url into a dialog popup with backtopagejsfields = '.$backtopagejsfields.
' -->';
1888 $out .=
'<a '.($accesskey ?
' accesskey="'.$accesskey.
'"' :
'').
' class="cursorpointer reposition button_'.$name.($morecss ?
' '.$morecss :
'').
'"'.$disabled.
' title="'.
dol_escape_htmltag($label).
'"';
1889 if (empty($conf->use_javascript_ajax)) {
1890 $out .=
' href="'.DOL_URL_ROOT.$url.
'" target="_blank"';
1891 } elseif ($jsonopen) {
1892 $out .=
' href="#" onclick="'.$jsonopen.
'"';
1894 $out .=
' href="#"';
1896 $out .=
'>'.$buttonstring.
'</a>';
1898 if (!empty($conf->use_javascript_ajax)) {
1900 $out .=
'<!-- code to open popup and variables to retreive returned variables -->';
1901 $out .=
'<div id="idfordialog'.$name.
'" class="hidden">div for dialog</div>';
1902 $out .=
'<div id="varforreturndialogid'.$name.
'" class="hidden">div for returned id</div>';
1903 $out .=
'<div id="varforreturndialoglabel'.$name.
'" class="hidden">div for returned label</div>';
1904 $out .=
'<!-- Add js code to open dialog popup on dialog -->';
1905 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">
1906 jQuery(document).ready(function () {
1907 jQuery(".button_'.$name.
'").click(function () {
1908 console.log(\'Open popup with jQuery(...).dialog() on URL '.
dol_escape_js(DOL_URL_ROOT.$url).
'\');
1909 var $tmpdialog = $(\
'#idfordialog'.$name.
'\');
1910 $tmpdialog.html(\
'<iframe class="iframedialog" id="iframedialog'.$name.
'" style="border: 0px;" src="'.DOL_URL_ROOT.$url.
'" width="100%" height="98%"></iframe>\');
1914 height: (window.innerHeight - 150),
1917 open:
function (event, ui) {
1918 console.log(
"open popup name='.$name.', backtopagejsfields='.$backtopagejsfields.'");
1920 close:
function (event, ui) {
1921 var returnedid = jQuery(
"#varforreturndialogid'.$name.'").text();
1922 var returnedlabel = jQuery(
"#varforreturndialoglabel'.$name.'").text();
1923 console.log(
"popup has been closed. returnedid (js var defined into parent page)="+returnedid+
" returnedlabel="+returnedlabel);
1924 if (returnedid !=
"" && returnedid !=
"div for returned id") {
1925 jQuery(
"#'.(empty($backtopagejsfieldsid)?"none
":$backtopagejsfieldsid).'").val(returnedid);
1927 if (returnedlabel !=
"" && returnedlabel !=
"div for returned label") {
1928 jQuery(
"#'.(empty($backtopagejsfieldslabel)?"none
":$backtopagejsfieldslabel).'").val(returnedlabel);
1933 $tmpdialog.dialog(\
'open\');
1958 function dol_fiche_head($links = array(), $active =
'0', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'')
1960 print
dol_get_fiche_head($links, $active, $title, $notab, $picto, $pictoisfullpath, $morehtmlright, $morecss, $limittoshow, $moretabssuffix);
1979 function dol_get_fiche_head($links = array(), $active =
'', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'', $dragdropfile = 0)
1981 global $conf, $langs, $hookmanager;
1985 if (!empty($conf->dol_optimize_smallscreen)) {
1989 $out =
"\n".
'<!-- dol_fiche_head - dol_get_fiche_head -->';
1991 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
1992 $out .=
'<div class="tabs'.($picto ?
'' :
' nopaddingleft').
'" data-role="controlgroup" data-type="horizontal">'.
"\n";
1996 if ($morehtmlright) {
1997 $out .=
'<div class="inline-block floatright tabsElem">'.$morehtmlright.
'</div>';
2001 if (!empty($title) && $showtitle && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2003 $out .=
'<a class="tabTitle">';
2005 $noprefix = $pictoisfullpath;
2006 if (strpos($picto,
'fontawesome_') !==
false) {
2009 $out .=
img_picto($title, ($noprefix ?
'' :
'object_').$picto,
'', $pictoisfullpath, 0, 0,
'',
'imgTabTitle').
' ';
2011 $out .=
'<span class="tabTitleText">'.dol_escape_htmltag(
dol_trunc($title, $limittitle)).
'</span>';
2019 if (is_array($links) && !empty($links)) {
2020 $keys = array_keys($links);
2022 $maxkey = max($keys);
2028 if (empty($limittoshow)) {
2029 $limittoshow = (empty($conf->global->MAIN_MAXTABS_IN_CARD) ? 99 : $conf->global->MAIN_MAXTABS_IN_CARD);
2031 if (!empty($conf->dol_optimize_smallscreen)) {
2039 for ($i = 0; $i <= $maxkey; $i++) {
2040 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
2042 if ($i >= $limittoshow) {
2048 for ($i = 0; $i <= $maxkey; $i++) {
2049 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
2055 if ($i < $limittoshow || $isactive) {
2057 $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])).
' -->';
2059 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
2060 if (!empty($links[$i][0])) {
2061 $out .=
'<a class="tabimage'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">'.$links[$i][1].
'</a>'.
"\n";
2063 $out .=
'<span class="tabspan">'.$links[$i][1].
'</span>'.
"\n";
2065 } elseif (!empty($links[$i][1])) {
2067 $out .=
'<div class="tab tab'.($isactive?
'active':
'unactive').
'" style="margin: 0 !important">';
2068 if (!empty($links[$i][0])) {
2069 $titletoshow = preg_replace(
'/<.*$/',
'', $links[$i][1]);
2070 $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).
'">';
2072 $out .= $links[$i][1];
2073 if (!empty($links[$i][0])) {
2074 $out .=
'</a>'.
"\n";
2076 $out .= empty($links[$i][4]) ?
'' : $links[$i][4];
2085 $outmore .=
'<div class="popuptabset wordwrap">';
2087 $outmore .=
'<div class="popuptab wordwrap" style="display:inherit;">';
2088 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
2089 if (!empty($links[$i][0])) {
2090 $outmore .=
'<a class="tabimage'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">'.$links[$i][1].
'</a>'.
"\n";
2092 $outmore .=
'<span class="tabspan">'.$links[$i][1].
'</span>'.
"\n";
2094 } elseif (!empty($links[$i][1])) {
2095 $outmore .=
'<a'.(!empty($links[$i][2]) ?
' id="'.$links[$i][2].
'"' :
'').
' class="wordwrap inline-block'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">';
2096 $outmore .= preg_replace(
'/([a-z])\|([a-z])/i',
'\\1 | \\2', $links[$i][1]);
2097 $outmore .=
'</a>'.
"\n";
2099 $outmore .=
'</div>';
2106 $outmore .=
'</div>';
2110 $left = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'right' :
'left');
2111 $right = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right');
2112 $widthofpopup = 200;
2114 $tabsname = $moretabssuffix;
2115 if (empty($tabsname)) {
2116 $tabsname = str_replace(
"@",
"", $picto);
2118 $out .=
'<div id="moretabs'.$tabsname.
'" class="inline-block tabsElem valignmiddle">';
2119 $out .=
'<div class="tab"><a href="#" class="tab moretab inline-block tabunactive"><span class="hideonsmartphone">'.$langs->trans(
"More").
'</span>... ('.$nbintab.
')</a></div>';
2120 $out .=
'<div id="moretabsList'.$tabsname.
'" style="width: '.$widthofpopup.
'px; position: absolute; '.$left.
': -999em; text-align: '.$left.
'; margin:0px; padding:2px; z-index:10;">';
2123 $out .=
'<div></div>';
2126 $out .=
'<script nonce="'.getNonce().
'">';
2127 $out .=
"$('#moretabs".$tabsname.
"').mouseenter( function() {
2128 var x = this.offsetLeft, y = this.offsetTop;
2129 console.log('mouseenter ".$left.
" x='+x+' y='+y+' window.innerWidth='+window.innerWidth);
2130 if ((window.innerWidth - x) < ".($widthofpopup + 10).
") {
2131 $('#moretabsList".$tabsname.
"').css('".$right.
"','8px');
2133 $('#moretabsList".$tabsname.
"').css('".$left.
"','auto');
2136 $out .=
"$('#moretabs".$tabsname.
"').mouseleave( function() { console.log('mouseleave ".$left.
"'); $('#moretabsList".$tabsname.
"').css('".$left.
"','-999em');});";
2137 $out .=
"</script>";
2140 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
2144 if (!$notab || $notab == -1 || $notab == -2 || $notab == -3) {
2145 $out .=
"\n".
'<div id="dragDropAreaTabBar" class="tabBar'.($notab == -1 ?
'' : ($notab == -2 ?
' tabBarNoTop' : (($notab == -3 ?
' noborderbottom' :
'').
' tabBarWithBottom'))).
'">'.
"\n";
2147 if (!empty($dragdropfile)) {
2150 $parameters = array(
'tabname' => $active,
'out' => $out);
2151 $reshook = $hookmanager->executeHooks(
'printTabsHead', $parameters);
2153 $out = $hookmanager->resPrint;
2179 if (!$notab || $notab == -1) {
2180 return "\n</div>\n";
2205 function dol_banner_tab($object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $onlybanner = 0, $morehtmlright =
'')
2207 global $conf,
$form, $user, $langs, $hookmanager, $action;
2211 $maxvisiblephotos = 1;
2213 $entity = (empty($object->entity) ? $conf->entity : $object->entity);
2214 $showbarcode = empty($conf->barcode->enabled) ? 0 : (empty($object->barcode) ? 0 : 1);
2215 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
2218 $modulepart =
'unknown';
2220 if ($object->element ==
'societe' || $object->element ==
'contact' || $object->element ==
'product' || $object->element ==
'ticket') {
2221 $modulepart = $object->element;
2222 } elseif ($object->element ==
'member') {
2223 $modulepart =
'memberphoto';
2224 } elseif ($object->element ==
'user') {
2225 $modulepart =
'userphoto';
2228 if (class_exists(
"Imagick")) {
2229 if ($object->element ==
'expensereport' || $object->element ==
'propal' || $object->element ==
'commande' || $object->element ==
'facture' || $object->element ==
'supplier_proposal') {
2230 $modulepart = $object->element;
2231 } elseif ($object->element ==
'fichinter') {
2232 $modulepart =
'ficheinter';
2233 } elseif ($object->element ==
'contrat') {
2234 $modulepart =
'contract';
2235 } elseif ($object->element ==
'order_supplier') {
2236 $modulepart =
'supplier_order';
2237 } elseif ($object->element ==
'invoice_supplier') {
2238 $modulepart =
'supplier_invoice';
2242 if ($object->element ==
'product') {
2244 $cssclass =
'photowithmargin photoref';
2245 $showimage = $object->is_photo_available($conf->product->multidir_output[$entity]);
2246 $maxvisiblephotos = (isset($conf->global->PRODUCT_MAX_VISIBLE_PHOTO) ? $conf->global->PRODUCT_MAX_VISIBLE_PHOTO : 5);
2247 if ($conf->browser->layout ==
'phone') {
2248 $maxvisiblephotos = 1;
2251 $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>';
2253 if (!empty($conf->global->PRODUCT_NODISPLAYIFNOPHOTO)) {
2255 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
2257 $nophoto =
'/public/theme/common/nophoto.png';
2258 $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>';
2261 } elseif ($object->element ==
'ticket') {
2263 $cssclass =
'photoref';
2264 $showimage = $object->is_photo_available($conf->ticket->multidir_output[$entity].
'/'.$object->ref);
2265 $maxvisiblephotos = (isset($conf->global->TICKET_MAX_VISIBLE_PHOTO) ? $conf->global->TICKET_MAX_VISIBLE_PHOTO : 2);
2266 if ($conf->browser->layout ==
'phone') {
2267 $maxvisiblephotos = 1;
2271 $showphoto = $object->show_photos(
'ticket', $conf->ticket->multidir_output[$entity],
'small', $maxvisiblephotos, 0, 0, 0, $width, 0);
2272 if ($object->nbphoto > 0) {
2273 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$showphoto.
'</div>';
2279 if (!empty($conf->global->TICKET_NODISPLAYIFNOPHOTO)) {
2281 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
2283 $nophoto =
img_picto(
'No photo',
'object_ticket');
2284 $morehtmlleft .=
'<!-- No photo to show -->';
2285 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
2286 $morehtmlleft .= $nophoto;
2287 $morehtmlleft .=
'</div></div>';
2292 if ($modulepart !=
'unknown') {
2295 if (in_array($modulepart, array(
'propal',
'commande',
'facture',
'ficheinter',
'contract',
'supplier_order',
'supplier_proposal',
'supplier_invoice',
'expensereport')) && class_exists(
"Imagick")) {
2297 $dir_output = (empty($conf->$modulepart->multidir_output[$entity]) ? $conf->$modulepart->dir_output : $conf->$modulepart->multidir_output[$entity]).
"/";
2298 if (in_array($modulepart, array(
'invoice_supplier',
'supplier_invoice'))) {
2299 $subdir =
get_exdir($object->id, 2, 0, 1, $object, $modulepart);
2300 $subdir .= ((!empty($subdir) && !preg_match(
'/\/$/', $subdir)) ?
'/' :
'').$objectref;
2302 $subdir =
get_exdir($object->id, 0, 0, 1, $object, $modulepart);
2304 if (empty($subdir)) {
2305 $subdir =
'errorgettingsubdirofobject';
2308 $filepath = $dir_output.$subdir.
"/";
2310 $filepdf = $filepath.$objectref.
".pdf";
2311 $relativepath = $subdir.
'/'.$objectref.
'.pdf';
2314 $fileimage = $filepdf.
'_preview.png';
2315 $relativepathimage = $relativepath.
'_preview.png';
2317 $pdfexists = file_exists($filepdf);
2322 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
2323 if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) {
2324 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2333 if ($pdfexists && !$error) {
2334 $heightforphotref = 80;
2335 if (!empty($conf->dol_optimize_smallscreen)) {
2336 $heightforphotref = 60;
2339 if (file_exists($fileimage)) {
2340 $phototoshow =
'<div class="photoref">';
2341 $phototoshow .=
'<img height="'.$heightforphotref.
'" class="photo photowithborder" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart=apercu'.$modulepart.
'&file='.urlencode($relativepathimage).
'">';
2342 $phototoshow .=
'</div>';
2345 } elseif (!$phototoshow) {
2346 $phototoshow .=
$form->showphoto($modulepart, $object, 0, 0, 0,
'photowithmargin photoref',
'small', 1, 0, $maxvisiblephotos);
2350 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">';
2351 $morehtmlleft .= $phototoshow;
2352 $morehtmlleft .=
'</div>';
2356 if (empty($phototoshow)) {
2357 if ($object->element ==
'action') {
2359 $cssclass =
'photorefcenter';
2360 $nophoto =
img_picto(
'No photo',
'title_agenda');
2363 $cssclass =
'photorefcenter';
2364 $picto = $object->picto;
2365 $prefix =
'object_';
2366 if ($object->element ==
'project' && !$object->public) {
2369 if (strpos($picto,
'fontawesome_') !==
false) {
2372 $nophoto =
img_picto(
'No photo', $prefix.$picto);
2374 $morehtmlleft .=
'<!-- No photo to show -->';
2375 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
2376 $morehtmlleft .= $nophoto;
2377 $morehtmlleft .=
'</div></div>';
2384 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$form->showbarcode($object, 100,
'photoref valignmiddle').
'</div>';
2387 if ($object->element ==
'societe') {
2388 if (!empty($conf->use_javascript_ajax) && $user->hasRight(
'societe',
'creer') && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
2389 $morehtmlstatus .=
ajax_object_onoff($object,
'status',
'status',
'InActivity',
'ActivityCeased');
2391 $morehtmlstatus .= $object->getLibStatut(6);
2393 } elseif ($object->element ==
'product') {
2395 if (!empty($conf->use_javascript_ajax) && $user->hasRight(
'produit',
'creer') && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
2396 $morehtmlstatus .=
ajax_object_onoff($object,
'status',
'tosell',
'ProductStatusOnSell',
'ProductStatusNotOnSell');
2398 $morehtmlstatus .=
'<span class="statusrefsell">'.$object->getLibStatut(6, 0).
'</span>';
2400 $morehtmlstatus .=
' ';
2402 if (!empty($conf->use_javascript_ajax) && $user->hasRight(
'produit',
'creer') && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
2403 $morehtmlstatus .=
ajax_object_onoff($object,
'status_buy',
'tobuy',
'ProductStatusOnBuy',
'ProductStatusNotOnBuy');
2405 $morehtmlstatus .=
'<span class="statusrefbuy">'.$object->getLibStatut(6, 1).
'</span>';
2407 } elseif (in_array($object->element, array(
'facture',
'invoice',
'invoice_supplier',
'chargesociales',
'loan',
'tva',
'salary'))) {
2408 $tmptxt = $object->getLibStatut(6, $object->totalpaid);
2409 if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
2410 $tmptxt = $object->getLibStatut(5, $object->totalpaid);
2412 $morehtmlstatus .= $tmptxt;
2413 } elseif ($object->element ==
'contrat' || $object->element ==
'contract') {
2414 if ($object->statut == 0) {
2415 $morehtmlstatus .= $object->getLibStatut(5);
2417 $morehtmlstatus .= $object->getLibStatut(4);
2419 } elseif ($object->element ==
'facturerec') {
2420 if ($object->frequency == 0) {
2421 $morehtmlstatus .= $object->getLibStatut(2);
2423 $morehtmlstatus .= $object->getLibStatut(5);
2425 } elseif ($object->element ==
'project_task') {
2426 $object->fk_statut = 1;
2427 if ($object->progress > 0) {
2428 $object->fk_statut = 2;
2430 if ($object->progress >= 100) {
2431 $object->fk_statut = 3;
2433 $tmptxt = $object->getLibStatut(5);
2434 $morehtmlstatus .= $tmptxt;
2435 } elseif (method_exists($object,
'getLibStatut')) {
2436 $tmptxt = $object->getLibStatut(6);
2437 if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
2438 $tmptxt = $object->getLibStatut(5);
2440 $morehtmlstatus .= $tmptxt;
2444 if (
isModEnabled(
'accounting') && in_array($object->element, array(
'bank',
'paiementcharge',
'facture',
'invoice',
'invoice_supplier',
'expensereport',
'payment_various'))) {
2446 if (method_exists($object,
'getVentilExportCompta')) {
2447 $accounted = $object->getVentilExportCompta();
2448 $langs->load(
"accountancy");
2449 $morehtmlstatus .=
'</div><div class="statusref statusrefbis"><span class="opacitymedium">'.($accounted > 0 ? $langs->trans(
"Accounted") : $langs->trans(
"NotYetAccounted")).
'</span>';
2454 if (!empty($object->name_alias)) {
2455 $morehtmlref .=
'<div class="refidno opacitymedium">'.dol_escape_htmltag($object->name_alias).
'</div>';
2459 if (in_array($object->element, array(
'product',
'bank_account',
'project_task'))) {
2460 if (!empty($object->label)) {
2461 $morehtmlref .=
'<div class="refidno opacitymedium">'.$object->label.
'</div>';
2466 if (method_exists($object,
'getBannerAddress') && !in_array($object->element, array(
'product',
'bookmark',
'ecm_directories',
'ecm_files'))) {
2467 $moreaddress = $object->getBannerAddress(
'refaddress', $object);
2469 $morehtmlref .=
'<div class="refidno refaddress">';
2470 $morehtmlref .= $moreaddress;
2471 $morehtmlref .=
'</div>';
2474 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)) {
2475 $morehtmlref .=
'<div style="clear: both;"></div>';
2476 $morehtmlref .=
'<div class="refidno opacitymedium">';
2477 $morehtmlref .= $langs->trans(
"TechnicalID").
': '.((int) $object->id);
2478 $morehtmlref .=
'</div>';
2481 $parameters=array(
'morehtmlref'=>$morehtmlref);
2482 $reshook = $hookmanager->executeHooks(
'formDolBanner', $parameters, $object, $action);
2485 } elseif (empty($reshook)) {
2486 $morehtmlref .= $hookmanager->resPrint;
2487 } elseif ($reshook > 0) {
2488 $morehtmlref = $hookmanager->resPrint;
2492 print
'<div class="'.($onlybanner ?
'arearefnobottom ' :
'arearef ').
'heightref valignmiddle centpercent">';
2493 print
$form->showrefnav($object, $paramid, $morehtml, $shownav, $fieldid, $fieldref, $morehtmlref, $moreparam, $nodbprefix, $morehtmlleft, $morehtmlstatus, $morehtmlright);
2495 print
'<div class="underrefbanner clearboth"></div>';
2511 if ($fieldrequired) {
2512 $ret .=
'<span class="fieldrequired">';
2514 $ret .=
'<label for="'.$fieldkey.
'">';
2515 $ret .= $langs->trans($langkey);
2517 if ($fieldrequired) {
2533 $ret =
' '.$bc[$var];
2535 $ret = preg_replace(
'/class=\"/',
'class="'.$moreclass.
' ', $ret);
2553 function dol_format_address($object, $withcountry = 0, $sep =
"\n", $outputlangs =
'', $mode = 0, $extralangcode =
'')
2555 global $conf, $langs, $hookmanager;
2558 $countriesusingstate = array(
'AU',
'CA',
'US',
'IN',
'GB',
'ES',
'UK',
'TR',
'CN');
2563 $ret .= ($extralangcode ? $object->array_languages[
'address'][$extralangcode] : (empty($object->address) ?
'' : preg_replace(
'/[\n\r]/', $sep, $object->address)));
2566 if (isset($object->country_code) && in_array($object->country_code, array(
'AU',
'CA',
'US',
'CN')) || !empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS)) {
2568 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2569 $ret .= (($ret && $town) ? $sep :
'').$town;
2571 if (!empty($object->state)) {
2572 $ret .= ($ret ? ($town ?
", " : $sep) :
'').$object->state;
2574 if (!empty($object->zip)) {
2575 $ret .= ($ret ? (($town || $object->state) ?
", " : $sep) :
'').$object->zip;
2577 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'GB',
'UK'))) {
2579 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2580 $ret .= ($ret ? $sep :
'').$town;
2581 if (!empty($object->state)) {
2582 $ret .= ($ret ?
", " :
'').$object->state;
2584 if (!empty($object->zip)) {
2585 $ret .= ($ret ? $sep :
'').$object->zip;
2587 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'ES',
'TR'))) {
2589 $ret .= ($ret ? $sep :
'').$object->zip;
2590 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2591 $ret .= ($town ? (($object->zip ?
' ' :
'').$town) :
'');
2592 if (!empty($object->state)) {
2593 $ret .= $sep.$object->state;
2595 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'JP'))) {
2598 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2599 $ret .= ($ret ? $sep :
'').($object->state ? $object->state.
', ' :
'').$town.($object->zip ?
' ' :
'').$object->zip;
2600 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'IT'))) {
2602 $ret .= ($ret ? $sep :
'').$object->zip;
2603 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2604 $ret .= ($town ? (($object->zip ?
' ' :
'').$town) :
'');
2605 $ret .= (empty($object->state_code) ?
'' : (
' '.$object->state_code));
2608 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2609 $ret .= !empty($object->zip) ? (($ret ? $sep :
'').$object->zip) :
'';
2610 $ret .= ($town ? (($object->zip ?
' ' : ($ret ? $sep :
'')).$town) :
'');
2611 if (!empty($object->state) && in_array($object->country_code, $countriesusingstate)) {
2612 $ret .= ($ret ?
", " :
'').$object->state;
2616 if (!is_object($outputlangs)) {
2617 $outputlangs = $langs;
2620 $langs->load(
"dict");
2621 $ret .= (empty($object->country_code) ?
'' : ($ret ? $sep :
'').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv(
"Country".$object->country_code)));
2624 $parameters = array(
'withcountry' => $withcountry,
'sep' => $sep,
'outputlangs' => $outputlangs,
'mode' => $mode,
'extralangcode' => $extralangcode);
2625 $reshook = $hookmanager->executeHooks(
'formatAddress', $parameters, $object);
2629 $ret .= $hookmanager->resPrint;
2647 if ((abs($ts) <= 0x7FFFFFFF)) {
2648 return ($is_gmt) ? @gmstrftime($fmt, $ts) : @strftime($fmt, $ts);
2650 return 'Error date into a not supported range';
2675 function dol_print_date($time, $format =
'', $tzoutput =
'auto', $outputlangs =
'', $encodetooutput =
false)
2677 global $conf, $langs;
2684 if ($tzoutput ===
'auto') {
2685 $tzoutput = (empty($conf) ?
'tzserver' : (isset($conf->tzuserinputkey) ? $conf->tzuserinputkey :
'tzserver'));
2690 $offsettz = $offsetdst = 0;
2693 if (is_string($tzoutput)) {
2694 if ($tzoutput ==
'tzserver') {
2696 $offsettzstring = @date_default_timezone_get();
2699 } elseif ($tzoutput ==
'tzuser' || $tzoutput ==
'tzuserrel') {
2701 $offsettzstring = (empty($_SESSION[
'dol_tz_string']) ?
'UTC' : $_SESSION[
'dol_tz_string']);
2703 if (class_exists(
'DateTimeZone')) {
2704 $user_date_tz =
new DateTimeZone($offsettzstring);
2705 $user_dt =
new DateTime();
2706 $user_dt->setTimezone($user_date_tz);
2707 $user_dt->setTimestamp($tzoutput ==
'tzuser' ?
dol_now() : (
int) $time);
2708 $offsettz = $user_dt->getOffset();
2710 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
2711 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
2716 if (!is_object($outputlangs)) {
2717 $outputlangs = $langs;
2720 $format =
'daytextshort';
2725 $reduceformat = (!empty($conf->dol_optimize_smallscreen) && in_array($format, array(
'day',
'dayhour'))) ? 1 : 0;
2726 $format = preg_replace(
'/inputnoreduce/',
'', $format);
2727 $formatwithoutreduce = preg_replace(
'/reduceformat/',
'', $format);
2728 if ($formatwithoutreduce != $format) {
2729 $format = $formatwithoutreduce;
2735 if ($format ==
'day') {
2736 $format = ($outputlangs->trans(
"FormatDateShort") !=
"FormatDateShort" ? $outputlangs->trans(
"FormatDateShort") : $conf->format_date_short);
2737 } elseif ($format ==
'hour') {
2738 $format = ($outputlangs->trans(
"FormatHourShort") !=
"FormatHourShort" ? $outputlangs->trans(
"FormatHourShort") : $conf->format_hour_short);
2739 } elseif ($format ==
'hourduration') {
2740 $format = ($outputlangs->trans(
"FormatHourShortDuration") !=
"FormatHourShortDuration" ? $outputlangs->trans(
"FormatHourShortDuration") : $conf->format_hour_short_duration);
2741 } elseif ($format ==
'daytext') {
2742 $format = ($outputlangs->trans(
"FormatDateText") !=
"FormatDateText" ? $outputlangs->trans(
"FormatDateText") : $conf->format_date_text);
2743 } elseif ($format ==
'daytextshort') {
2744 $format = ($outputlangs->trans(
"FormatDateTextShort") !=
"FormatDateTextShort" ? $outputlangs->trans(
"FormatDateTextShort") : $conf->format_date_text_short);
2745 } elseif ($format ==
'dayhour') {
2746 $format = ($outputlangs->trans(
"FormatDateHourShort") !=
"FormatDateHourShort" ? $outputlangs->trans(
"FormatDateHourShort") : $conf->format_date_hour_short);
2747 } elseif ($format ==
'dayhoursec') {
2748 $format = ($outputlangs->trans(
"FormatDateHourSecShort") !=
"FormatDateHourSecShort" ? $outputlangs->trans(
"FormatDateHourSecShort") : $conf->format_date_hour_sec_short);
2749 } elseif ($format ==
'dayhourtext') {
2750 $format = ($outputlangs->trans(
"FormatDateHourText") !=
"FormatDateHourText" ? $outputlangs->trans(
"FormatDateHourText") : $conf->format_date_hour_text);
2751 } elseif ($format ==
'dayhourtextshort') {
2752 $format = ($outputlangs->trans(
"FormatDateHourTextShort") !=
"FormatDateHourTextShort" ? $outputlangs->trans(
"FormatDateHourTextShort") : $conf->format_date_hour_text_short);
2753 } elseif ($format ==
'dayhourlog') {
2755 $format =
'%Y%m%d%H%M%S';
2756 } elseif ($format ==
'dayhourlogsmall') {
2758 $format =
'%y%m%d%H%M';
2759 } elseif ($format ==
'dayhourldap') {
2760 $format =
'%Y%m%d%H%M%SZ';
2761 } elseif ($format ==
'dayhourxcard') {
2762 $format =
'%Y%m%dT%H%M%SZ';
2763 } elseif ($format ==
'dayxcard') {
2765 } elseif ($format ==
'dayrfc') {
2766 $format =
'%Y-%m-%d';
2767 } elseif ($format ==
'dayhourrfc') {
2768 $format =
'%Y-%m-%dT%H:%M:%SZ';
2769 } elseif ($format ==
'standard') {
2770 $format =
'%Y-%m-%d %H:%M:%S';
2773 if ($reduceformat) {
2774 $format = str_replace(
'%Y',
'%y', $format);
2775 $format = str_replace(
'yyyy',
'yy', $format);
2779 if (preg_match(
'/%b/i', $format)) {
2781 $format = str_replace(
'%b',
'__b__', $format);
2782 $format = str_replace(
'%B',
'__B__', $format);
2784 if (preg_match(
'/%a/i', $format)) {
2786 $format = str_replace(
'%a',
'__a__', $format);
2787 $format = str_replace(
'%A',
'__A__', $format);
2792 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)) {
2793 dol_print_error(
'',
"Functions.lib::dol_print_date function called with a bad value from page ".$_SERVER[
"PHP_SELF"]);
2795 } elseif (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $time, $reg)) {
2797 dol_syslog(
"Functions.lib::dol_print_date function called with a bad value from page ".$_SERVER[
"PHP_SELF"], LOG_WARNING);
2800 $syear = (!empty($reg[1]) ? $reg[1] :
'');
2801 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
2802 $sday = (!empty($reg[3]) ? $reg[3] :
'');
2803 $shour = (!empty($reg[4]) ? $reg[4] :
'');
2804 $smin = (!empty($reg[5]) ? $reg[5] :
'');
2805 $ssec = (!empty($reg[6]) ? $reg[6] :
'');
2807 $time =
dol_mktime($shour, $smin, $ssec, $smonth, $sday, $syear,
true);
2810 $tzo =
new DateTimeZone(
'UTC');
2812 $tzo =
new DateTimeZone(date_default_timezone_get());
2814 $dtts =
new DateTime();
2815 $dtts->setTimestamp($time);
2816 $dtts->setTimezone($tzo);
2817 $newformat = str_replace(
2818 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2819 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2821 $ret = $dtts->format($newformat);
2823 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2824 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2829 if ($time < 100000000000) {
2830 $timetouse = $time + $offsettz + $offsetdst;
2833 $tzo =
new DateTimeZone(
'UTC');
2835 $tzo =
new DateTimeZone(date_default_timezone_get());
2837 $dtts =
new DateTime();
2838 $dtts->setTimestamp($timetouse);
2839 $dtts->setTimezone($tzo);
2840 $newformat = str_replace(
2841 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'%w',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2842 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'w',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2844 $ret = $dtts->format($newformat);
2846 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2847 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2852 $ret =
'Bad value '.$time.
' for date';
2856 if (preg_match(
'/__b__/i', $format)) {
2857 $timetouse = $time + $offsettz + $offsetdst;
2860 $tzo =
new DateTimeZone(
'UTC');
2862 $tzo =
new DateTimeZone(date_default_timezone_get());
2864 $dtts =
new DateTime();
2865 $dtts->setTimestamp($timetouse);
2866 $dtts->setTimezone($tzo);
2867 $month = $dtts->format(
"m");
2868 $month = sprintf(
"%02d", $month);
2869 if ($encodetooutput) {
2870 $monthtext = $outputlangs->transnoentities(
'Month'.$month);
2871 $monthtextshort = $outputlangs->transnoentities(
'MonthShort'.$month);
2873 $monthtext = $outputlangs->transnoentitiesnoconv(
'Month'.$month);
2874 $monthtextshort = $outputlangs->transnoentitiesnoconv(
'MonthShort'.$month);
2877 $ret = str_replace(
'__b__', $monthtextshort, $ret);
2878 $ret = str_replace(
'__B__', $monthtext, $ret);
2882 if (preg_match(
'/__a__/i', $format)) {
2884 $timetouse = $time + $offsettz + $offsetdst;
2887 $tzo =
new DateTimeZone(
'UTC');
2889 $tzo =
new DateTimeZone(date_default_timezone_get());
2891 $dtts =
new DateTime();
2892 $dtts->setTimestamp($timetouse);
2893 $dtts->setTimezone($tzo);
2894 $w = $dtts->format(
"w");
2895 $dayweek = $outputlangs->transnoentitiesnoconv(
'Day'.$w);
2897 $ret = str_replace(
'__A__', $dayweek, $ret);
2898 $ret = str_replace(
'__a__',
dol_substr($dayweek, 0, 3), $ret);
2927 $datetimeobj =
new DateTime();
2928 $datetimeobj->setTimestamp($timestamp);
2929 if ($forcetimezone) {
2930 $datetimeobj->setTimezone(
new DateTimeZone($forcetimezone ==
'gmt' ?
'UTC' : $forcetimezone));
2933 'year'=>((
int) date_format($datetimeobj,
'Y')),
2934 'mon'=>((
int) date_format($datetimeobj,
'm')),
2935 'mday'=>((
int) date_format($datetimeobj,
'd')),
2936 'wday'=>((
int) date_format($datetimeobj,
'w')),
2937 'yday'=>((
int) date_format($datetimeobj,
'z')),
2938 'hours'=>((
int) date_format($datetimeobj,
'H')),
2939 'minutes'=>((
int) date_format($datetimeobj,
'i')),
2940 'seconds'=>((
int) date_format($datetimeobj,
's')),
2968 function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm =
'auto', $check = 1)
2973 if ($gm ===
'auto') {
2974 $gm = (empty($conf) ?
'tzserver' : $conf->tzuserinputkey);
2979 if ($hour == -1 || empty($hour)) {
2982 if ($minute == -1 || empty($minute)) {
2985 if ($second == -1 || empty($second)) {
2991 if (!$month || !$day) {
3000 if ($hour < 0 || $hour > 24) {
3003 if ($minute < 0 || $minute > 60) {
3006 if ($second < 0 || $second > 60) {
3011 if (empty($gm) || ($gm ===
'server' || $gm ===
'tzserver')) {
3012 $default_timezone = @date_default_timezone_get();
3013 $localtz =
new DateTimeZone($default_timezone);
3014 } elseif ($gm ===
'user' || $gm ===
'tzuser' || $gm ===
'tzuserrel') {
3016 $default_timezone = (empty($_SESSION[
"dol_tz_string"]) ? @date_default_timezone_get() : $_SESSION[
"dol_tz_string"]);
3018 $localtz =
new DateTimeZone($default_timezone);
3020 dol_syslog(
"Warning dol_tz_string contains an invalid value ".$_SESSION[
"dol_tz_string"], LOG_WARNING);
3021 $default_timezone = @date_default_timezone_get();
3023 } elseif (strrpos($gm,
"tz,") !==
false) {
3024 $timezone = str_replace(
"tz,",
"", $gm);
3026 $localtz =
new DateTimeZone($timezone);
3028 dol_syslog(
"Warning passed timezone contains an invalid value ".$timezone, LOG_WARNING);
3032 if (empty($localtz)) {
3033 $localtz =
new DateTimeZone(
'UTC');
3037 $dt =
new DateTime(
'now', $localtz);
3038 $dt->setDate((
int) $year, (
int) $month, (
int) $day);
3039 $dt->setTime((
int) $hour, (
int) $minute, (
int) $second);
3040 $date = $dt->getTimestamp();
3060 if ($mode ===
'auto') {
3064 if ($mode ==
'gmt') {
3066 } elseif ($mode ==
'tzserver') {
3067 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
3069 $ret = (int) (
dol_now(
'gmt') + ($tzsecond * 3600));
3075 } elseif ($mode ==
'tzuser' || $mode ==
'tzuserrel') {
3078 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
3079 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
3080 $ret = (int) (
dol_now(
'gmt') + ($offsettz + $offsetdst));
3097 global $conf, $langs;
3100 if (!empty($conf->dol_optimize_smallscreen)) {
3105 if (empty($shortvalue) || $size < ($level * 10)) {
3107 $textunitshort = $langs->trans(
"b");
3108 $textunitlong = $langs->trans(
"Bytes");
3110 $ret = round($size / $level, 0);
3111 $textunitshort = $langs->trans(
"Kb");
3112 $textunitlong = $langs->trans(
"KiloBytes");
3115 if (empty($shortunit)) {
3116 $ret .=
' '.$textunitlong;
3118 $ret .=
' '.$textunitshort;
3134 function dol_print_url($url, $target =
'_blank', $max = 32, $withpicto = 0, $morecss =
'float')
3142 $link =
'<a href="';
3143 if (!preg_match(
'/^http/i', $url)) {
3149 $link .=
' target="'.$target.
'"';
3152 if (!preg_match(
'/^http/i', $url)) {
3158 if ($morecss ==
'float') {
3159 return '<div class="nospan'.($morecss ?
' '.$morecss :
'').
'" style="margin-right: 10px">'.($withpicto ?
img_picto($langs->trans(
"Url"),
'globe').
' ' :
'').$link.
'</div>';
3161 return '<span class="nospan'.($morecss ?
' '.$morecss :
'').
'" style="margin-right: 10px">'.($withpicto ?
img_picto($langs->trans(
"Url"),
'globe').
' ' :
'').$link.
'</span>';
3177 function dol_print_email($email, $cid = 0, $socid = 0, $addlink = 0, $max = 64, $showinvalid = 1, $withpicto = 0)
3179 global $conf, $user, $langs, $hookmanager;
3183 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) {
3187 if (empty($email)) {
3191 if (!empty($addlink)) {
3192 $newemail =
'<a style="text-overflow: ellipsis;" href="';
3193 if (!preg_match(
'/^mailto:/i', $email)) {
3194 $newemail .=
'mailto:';
3196 $newemail .= $email;
3199 $newemail .=
'</a>';
3201 $langs->load(
"errors");
3202 $newemail .=
img_warning($langs->trans(
"ErrorBadEMail", $email));
3205 if (($cid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
3208 if (!empty($conf->global->AGENDA_ADDACTIONFOREMAIL)) {
3209 $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>';
3212 $newemail =
'<div>'.$newemail.
' '.$link.
'</div>';
3217 $langs->load(
"errors");
3218 $newemail .=
img_warning($langs->trans(
"ErrorBadEMail", $email));
3223 $rep = ($withpicto ?
img_picto($langs->trans(
"EMail").
' : '.$email, (is_numeric($withpicto) ?
'email' : $withpicto)).
' ' :
'').$newemail;
3226 $parameters = array(
'cid' => $cid,
'socid' => $socid,
'addlink' => $addlink,
'picto' => $withpicto);
3228 $reshook = $hookmanager->executeHooks(
'printEmail', $parameters, $email);
3232 $rep .= $hookmanager->resPrint;
3247 $socialnetworks = array();
3249 require_once DOL_DOCUMENT_ROOT.
'/core/lib/memory.lib.php';
3250 $cachekey =
'socialnetworks_' . $conf->entity;
3252 if (!is_null($dataretrieved)) {
3253 $socialnetworks = $dataretrieved;
3255 $sql =
"SELECT rowid, code, label, url, icon, active FROM ".MAIN_DB_PREFIX.
"c_socialnetworks";
3256 $sql .=
" WHERE entity=".$conf->entity;
3257 $resql = $db->query(
$sql);
3259 while ($obj = $db->fetch_object($resql)) {
3260 $socialnetworks[$obj->code] = array(
3261 'rowid' => $obj->rowid,
3262 'label' => $obj->label,
3264 'icon' => $obj->icon,
3265 'active' => $obj->active,
3272 return $socialnetworks;
3287 global $conf, $user, $langs;
3291 if (empty($value)) {
3295 if (!empty($type)) {
3296 $htmllink =
'<div class="divsocialnetwork inline-block valignmiddle">';
3298 $htmllink .=
'<span class="fa pictofixedwidth '.($dictsocialnetworks[$type][
'icon'] ? $dictsocialnetworks[$type][
'icon'] :
'fa-link').
'"></span>';
3299 if ($type ==
'skype') {
3301 $htmllink .=
' <a href="skype:';
3303 $htmllink .=
'?call" alt="'.$langs->trans(
"Call").
' '.$value.
'" title="'.
dol_escape_htmltag($langs->trans(
"Call").
' '.$value).
'">';
3304 $htmllink .=
'<img src="'.DOL_URL_ROOT.
'/theme/common/skype_callbutton.png" border="0">';
3305 $htmllink .=
'</a><a href="skype:';
3307 $htmllink .=
'?chat" alt="'.$langs->trans(
"Chat").
' '.$value.
'" title="'.
dol_escape_htmltag($langs->trans(
"Chat").
' '.$value).
'">';
3308 $htmllink .=
'<img class="paddingleft" src="'.DOL_URL_ROOT.
'/theme/common/skype_chatbutton.png" border="0">';
3309 $htmllink .=
'</a>';
3310 if (($cid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
'agenda',
'myactions',
'create')) {
3311 $addlink =
'AC_SKYPE';
3313 if (!empty($conf->global->AGENDA_ADDACTIONFORSKYPE)) {
3314 $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>';
3316 $htmllink .= ($link ?
' '.$link :
'');
3319 if (!empty($dictsocialnetworks[$type][
'url'])) {
3320 $tmpvirginurl = preg_replace(
'/\/?{socialid}/',
'', $dictsocialnetworks[$type][
'url']);
3321 if ($tmpvirginurl) {
3322 $value = preg_replace(
'/^www\.'.preg_quote($tmpvirginurl,
'/').
'\/?/',
'', $value);
3323 $value = preg_replace(
'/^'.preg_quote($tmpvirginurl,
'/').
'\/?/',
'', $value);
3325 $tmpvirginurl3 = preg_replace(
'/^https:\/\//i',
'https://www.', $tmpvirginurl);
3326 if ($tmpvirginurl3) {
3327 $value = preg_replace(
'/^www\.'.preg_quote($tmpvirginurl3,
'/').
'\/?/',
'', $value);
3328 $value = preg_replace(
'/^'.preg_quote($tmpvirginurl3,
'/').
'\/?/',
'', $value);
3331 $tmpvirginurl2 = preg_replace(
'/^https?:\/\//i',
'', $tmpvirginurl);
3332 if ($tmpvirginurl2) {
3333 $value = preg_replace(
'/^www\.'.preg_quote($tmpvirginurl2,
'/').
'\/?/',
'', $value);
3334 $value = preg_replace(
'/^'.preg_quote($tmpvirginurl2,
'/').
'\/?/',
'', $value);
3337 $link = str_replace(
'{socialid}', $value, $dictsocialnetworks[$type][
'url']);
3338 if (preg_match(
'/^https?:\/\//i', $link)) {
3339 $htmllink .=
'<a href="'.dol_sanitizeUrl($link, 0).
'" target="_blank" rel="noopener noreferrer">'.
dol_escape_htmltag($value).
'</a>';
3341 $htmllink .=
'<a href="'.dol_sanitizeUrl($link, 1).
'" target="_blank" rel="noopener noreferrer">'.
dol_escape_htmltag($value).
'</a>';
3347 $htmllink .=
'</div>';
3349 $langs->load(
"errors");
3350 $htmllink .=
img_warning($langs->trans(
"ErrorBadSocialNetworkValue", $value));
3365 function dol_print_profids($profID, $profIDtype, $countrycode =
'', $addcpButton = 1, $separ =
' ')
3369 if (empty($profID) || empty($profIDtype)) {
3372 if (empty($countrycode)) $countrycode = $mysoc->country_code;
3373 $newProfID = $profID;
3374 $id = substr($profIDtype, -1);
3376 if (strtoupper($countrycode) ==
'FR') {
3378 if ($id == 1 &&
dol_strlen($newProfID) == 9) $newProfID = substr($newProfID, 0, 3).$separ.substr($newProfID, 3, 3).$separ.substr($newProfID, 6, 3);
3379 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);
3380 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);
3383 else $ret = $newProfID;
3401 function dol_print_phone($phone, $countrycode =
'', $cid = 0, $socid = 0, $addlink =
'', $separ =
" ", $withpicto =
'', $titlealt =
'', $adddivfloat = 0)
3403 global $conf, $user, $langs, $mysoc, $hookmanager;
3406 $phone = is_null($phone) ?
'' : preg_replace(
"/[\s.-]/",
"", trim($phone));
3407 if (empty($phone)) {
3410 if (!empty($conf->global->MAIN_PHONE_SEPAR)) {
3411 $separ = $conf->global->MAIN_PHONE_SEPAR;
3413 if (empty($countrycode) && is_object($mysoc)) {
3414 $countrycode = $mysoc->country_code;
3418 if ($conf->dol_optimize_smallscreen) {
3423 if (strtoupper($countrycode) ==
"FR") {
3426 $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);
3428 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 2).$separ.substr($newphone, 5, 2);
3430 $newphone = substr($newphone, 0, 2).$separ.substr($newphone, 2, 3).$separ.substr($newphone, 5, 2).$separ.substr($newphone, 7, 2);
3432 $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);
3434 $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);
3436 $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);
3438 } elseif (strtoupper($countrycode) ==
"CA") {
3440 $newphone = ($separ !=
'' ?
'(' :
'').substr($newphone, 0, 3).($separ !=
'' ?
')' :
'').$separ.substr($newphone, 3, 3).($separ !=
'' ?
'-' :
'').substr($newphone, 6, 4);
3442 } elseif (strtoupper($countrycode) ==
"PT") {
3444 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3446 } elseif (strtoupper($countrycode) ==
"SR") {
3448 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3);
3450 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 4);
3452 } elseif (strtoupper($countrycode) ==
"DE") {
3454 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 4).$separ.substr($newphone, 11, 3);
3456 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 4).$separ.substr($newphone, 10, 3);
3458 } elseif (strtoupper($countrycode) ==
"ES") {
3460 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3462 } elseif (strtoupper($countrycode) ==
"BF") {
3464 $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);
3466 } elseif (strtoupper($countrycode) ==
"RO") {
3468 $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);
3470 } elseif (strtoupper($countrycode) ==
"TR") {
3472 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 4);
3474 } elseif (strtoupper($countrycode) ==
"US") {
3476 $newphone = substr($newphone, 0, 2).$separ.substr($newphone, 2, 3).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 4);
3478 } elseif (strtoupper($countrycode) ==
"MX") {
3480 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 2);
3482 $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);
3484 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 4);
3486 } elseif (strtoupper($countrycode) ==
"ML") {
3488 $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);
3490 } elseif (strtoupper($countrycode) ==
"TH") {
3492 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 3);
3494 $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);
3496 } elseif (strtoupper($countrycode) ==
"MU") {
3499 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 2).$separ.substr($newphone, 9, 2);
3501 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 4).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 2);
3503 } elseif (strtoupper($countrycode) ==
"ZA") {
3505 $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);
3507 } elseif (strtoupper($countrycode) ==
"SY") {
3509 $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);
3511 $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);
3513 } elseif (strtoupper($countrycode) ==
"AE") {
3515 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 2);
3517 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3519 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 4);
3521 } elseif (strtoupper($countrycode) ==
"DZ") {
3523 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3525 } elseif (strtoupper($countrycode) ==
"BE") {
3527 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 3);
3529 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3531 } elseif (strtoupper($countrycode) ==
"PF") {
3533 $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);
3535 } elseif (strtoupper($countrycode) ==
"CO") {
3537 $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);
3539 } elseif (strtoupper($countrycode) ==
"JO") {
3541 $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);
3543 } elseif (strtoupper($countrycode) ==
"JM") {
3545 $newphone = substr($newphone, 0, 5).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 4);
3547 } elseif (strtoupper($countrycode) ==
"MG") {
3549 $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);
3551 } elseif (strtoupper($countrycode) ==
"GB") {
3553 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3555 } elseif (strtoupper($countrycode) ==
"CH") {
3557 $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);
3559 $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);
3561 } elseif (strtoupper($countrycode) ==
"TN") {
3563 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3565 } elseif (strtoupper($countrycode) ==
"GF") {
3567 $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);
3569 } elseif (strtoupper($countrycode) ==
"GP") {
3571 $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);
3573 } elseif (strtoupper($countrycode) ==
"MQ") {
3575 $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);
3577 } elseif (strtoupper($countrycode) ==
"IT") {
3579 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3581 $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);
3583 } elseif (strtoupper($countrycode) ==
"AU") {
3587 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 1).$separ.substr($newphone, 4, 4).$separ.substr($newphone, 8, 4);
3589 } elseif (strtoupper($countrycode) ==
"LU") {
3592 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 2);
3594 $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);
3596 $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);
3598 $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);
3601 if (!empty($addlink)) {
3602 if ($addlink ==
'tel' || $conf->browser->layout ==
'phone' || (
isModEnabled(
'clicktodial') && !empty($conf->global->CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS))) {
3603 $newphoneform = $newphone;
3604 $newphone =
'<a href="tel:'.$phone.
'"';
3605 $newphone .=
'>'.$newphoneform.
'</a>';
3606 } elseif (
isModEnabled(
'clicktodial') && $addlink ==
'AC_TEL') {
3607 if (empty($user->clicktodial_loaded)) {
3608 $user->fetch_clicktodial();
3612 $urlmask =
'ErrorClickToDialModuleNotConfigured';
3613 if (!empty($conf->global->CLICKTODIAL_URL)) {
3614 $urlmask = $conf->global->CLICKTODIAL_URL;
3616 if (!empty($user->clicktodial_url)) {
3617 $urlmask = $user->clicktodial_url;
3620 $clicktodial_poste = (!empty($user->clicktodial_poste) ?urlencode($user->clicktodial_poste) :
'');
3621 $clicktodial_login = (!empty($user->clicktodial_login) ?urlencode($user->clicktodial_login) :
'');
3622 $clicktodial_password = (!empty($user->clicktodial_password) ?urlencode($user->clicktodial_password) :
'');
3624 $url = sprintf($urlmask, urlencode($phone), $clicktodial_poste, $clicktodial_login, $clicktodial_password);
3626 $substitarray = array(
'__PHONEFROM__'=>$clicktodial_poste,
3627 '__PHONETO__'=>urlencode($phone),
3628 '__LOGIN__'=>$clicktodial_login,
3629 '__PASS__'=>$clicktodial_password);
3631 $newphonesav = $newphone;
3632 if (empty($conf->global->CLICKTODIAL_DO_NOT_USE_AJAX_CALL)) {
3634 $newphone =
'<a href="'.$url.
'" class="cssforclicktodial"';
3635 $newphone .=
'>'.$newphonesav.
'</a>';
3638 $newphone =
'<a href="'.$url.
'"';
3639 if (!empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) {
3640 $newphone .=
' target="_blank" rel="noopener noreferrer"';
3642 $newphone .=
'>'.$newphonesav.
'</a>';
3647 if (
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
3650 if ($addlink ==
'AC_FAX') {
3653 if (!empty($conf->global->AGENDA_ADDACTIONFORPHONE)) {
3654 $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>';
3657 $newphone =
'<div>'.$newphone.
' '.$link.
'</div>';
3662 if (empty($titlealt)) {
3663 $titlealt = ($withpicto ==
'fax' ? $langs->trans(
"Fax") : $langs->trans(
"Phone"));
3668 $parameters = array(
'countrycode' => $countrycode,
'cid' => $cid,
'socid' => $socid,
'titlealt' => $titlealt,
'picto' => $withpicto);
3669 $reshook = $hookmanager->executeHooks(
'printPhone', $parameters, $phone);
3670 $rep .= $hookmanager->resPrint;
3672 if (empty($reshook)) {
3675 if ($withpicto ==
'fax') {
3676 $picto =
'phoning_fax';
3677 } elseif ($withpicto ==
'phone') {
3679 } elseif ($withpicto ==
'mobile') {
3680 $picto =
'phoning_mobile';
3685 if ($adddivfloat == 1) {
3686 $rep .=
'<div class="nospan float" style="margin-right: 10px">';
3687 } elseif (empty($adddivfloat)) {
3688 $rep .=
'<span style="margin-right: 10px;">';
3690 $rep .= ($withpicto ?
img_picto($titlealt,
'object_'.$picto.
'.png').
' ' :
'').$newphone;
3691 if ($adddivfloat == 1) {
3693 } elseif (empty($adddivfloat)) {
3710 global $conf, $langs;
3721 if (file_exists(DOL_DOCUMENT_ROOT.
'/theme/common/flags/'.$countrycode.
'.png')) {
3722 $ret .=
' '.img_picto($countrycode.
' '.$langs->trans(
"AccordingToGeoIPDatabase"), DOL_URL_ROOT.
'/theme/common/flags/'.$countrycode.
'.png',
'', 1);
3724 $ret .=
' ('.$countrycode.
')';
3744 if (empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) || preg_match(
'/[^0-9\.\:,\[\]]/', $_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
3745 if (empty($_SERVER[
'HTTP_CLIENT_IP']) || preg_match(
'/[^0-9\.\:,\[\]]/', $_SERVER[
'HTTP_CLIENT_IP'])) {
3746 if (empty($_SERVER[
"HTTP_CF_CONNECTING_IP"])) {
3747 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
3749 $ip = $_SERVER[
"HTTP_CF_CONNECTING_IP"];
3752 $ip = $_SERVER[
'HTTP_CLIENT_IP'];
3755 $ip = $_SERVER[
'HTTP_X_FORWARDED_FOR'];
3771 if (isset($_SERVER[
'HTTPS']) && $_SERVER[
'HTTPS'] ==
'on') {
3773 } 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') {
3791 if (!empty($conf->geoipmaxmind->enabled)) {
3795 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeoip.class.php';
3796 $geoip =
new DolGeoIP(
'country', $datafile);
3798 $countrycode = $geoip->getCountryCodeFromIP($ip);
3801 return $countrycode;
3813 global $conf, $langs, $user;
3817 if (!empty($conf->geoipmaxmind->enabled)) {
3822 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeoip.class.php';
3823 $geoip =
new DolGeoIP(
'country', $datafile);
3824 $countrycode = $geoip->getCountryCodeFromIP($ip);
3825 $ret = $countrycode;
3844 global $conf, $user, $langs, $hookmanager;
3850 $parameters = array(
'element' => $element,
'id' => $id);
3851 $reshook = $hookmanager->executeHooks(
'printAddress', $parameters, $address);
3852 $out .= $hookmanager->resPrint;
3854 if (empty($reshook)) {
3855 if (empty($charfornl)) {
3856 $out .= nl2br($address);
3858 $out .= preg_replace(
'/[\r\n]+/', $charfornl, $address);
3862 $showgmap = $showomap = 0;
3863 if (($element ==
'thirdparty' || $element ==
'societe') &&
isModEnabled(
'google') && !empty($conf->global->GOOGLE_ENABLE_GMAPS)) {
3866 if ($element ==
'contact' &&
isModEnabled(
'google') && !empty($conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS)) {
3869 if ($element ==
'member' &&
isModEnabled(
'google') && !empty($conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS)) {
3872 if (($element ==
'thirdparty' || $element ==
'societe') &&
isModEnabled(
'openstreetmap') && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS)) {
3875 if ($element ==
'contact' &&
isModEnabled(
'openstreetmap') && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS)) {
3878 if ($element ==
'member' &&
isModEnabled(
'openstreetmap') && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS)) {
3882 $url =
dol_buildpath(
'/google/gmaps.php?mode='.$element.
'&id='.$id, 1);
3883 $out .=
' <a href="'.$url.
'" target="_gmaps"><img id="'.$htmlid.
'" class="valigntextbottom" src="'.DOL_URL_ROOT.
'/theme/common/gmap.png"></a>';
3886 $url =
dol_buildpath(
'/openstreetmap/maps.php?mode='.$element.
'&id='.$id, 1);
3887 $out .=
' <a href="'.$url.
'" target="_gmaps"><img id="'.$htmlid.
'_openstreetmap" class="valigntextbottom" src="'.DOL_URL_ROOT.
'/theme/common/gmap.png"></a>';
3908 function isValidEmail($address, $acceptsupervisorkey = 0, $acceptuserkey = 0)
3910 if ($acceptsupervisorkey && $address ==
'__SUPERVISOREMAIL__') {
3913 if ($acceptuserkey && $address ==
'__USER_EMAIL__') {
3916 if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
3933 if (function_exists(
'idn_to_ascii') && function_exists(
'checkdnsrr')) {
3934 if (!checkdnsrr(idn_to_ascii($domain),
'MX')) {
3937 if (function_exists(
'getmxrr')) {
3940 getmxrr(idn_to_ascii($domain), $mxhosts, $weight);
3941 if (count($mxhosts) > 1) {
3944 if (count($mxhosts) == 1 && !empty($mxhosts[0])) {
3981 $tmparray = explode(
' ', $s);
3982 foreach ($tmparray as $tmps) {
3999 if (is_null($string)) {
4003 if (function_exists(
'mb_strlen')) {
4004 return mb_strlen($string, $stringencoding);
4006 return strlen($string);
4020 function dol_substr($string, $start, $length =
null, $stringencoding =
'', $trunconbytes = 0)
4024 if (empty($stringencoding)) {
4025 $stringencoding = $langs->charset_output;
4029 if (empty($trunconbytes)) {
4030 if (function_exists(
'mb_substr')) {
4031 $ret = mb_substr($string, $start, $length, $stringencoding);
4033 $ret = substr($string, $start, $length);
4036 if (function_exists(
'mb_strcut')) {
4037 $ret = mb_strcut($string, $start, $length, $stringencoding);
4039 $ret = substr($string, $start, $length);
4059 function dol_trunc($string, $size = 40, $trunc =
'right', $stringencoding =
'UTF-8', $nodot = 0, $display = 0)
4063 if (empty($size) || !empty($conf->global->MAIN_DISABLE_TRUNC)) {
4067 if (empty($stringencoding)) {
4068 $stringencoding =
'UTF-8';
4071 if ($conf->dol_optimize_smallscreen == 1 && $display == 1) {
4072 $size = round($size / 3);
4076 if ($trunc ==
'right') {
4078 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
4080 return dol_substr($newstring, 0, $size, $stringencoding).($nodot ?
'' :
'…');
4085 } elseif ($trunc ==
'middle') {
4087 if (
dol_strlen($newstring, $stringencoding) > 2 &&
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
4088 $size1 = round($size / 2);
4089 $size2 = round($size / 2);
4090 return dol_substr($newstring, 0, $size1, $stringencoding).
'…'.
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
4094 } elseif ($trunc ==
'left') {
4096 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
4098 return '…'.dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
4102 } elseif ($trunc ==
'wrap') {
4104 if (
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
4110 return 'BadParam3CallingDolTrunc';
4135 function img_picto($titlealt, $picto, $moreatt =
'', $pictoisfullpath =
false, $srconly = 0, $notitle = 0, $alt =
'', $morecss =
'', $marginleftonlyshort = 2)
4137 global $conf, $langs;
4140 $url = DOL_URL_ROOT;
4141 $theme = isset($conf->theme) ? $conf->theme :
null;
4142 $path =
'theme/'.$theme;
4144 if ($pictoisfullpath) {
4146 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
4149 $fullpathpicto = $picto;
4151 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
4152 $morecss .= ($morecss ?
' ' :
'').$reg[1];
4153 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
4156 $pictowithouttext = preg_replace(
'/(\.png|\.gif|\.svg)$/',
'', $picto);
4157 $pictowithouttext = str_replace(
'object_',
'', $pictowithouttext);
4158 $pictowithouttext = str_replace(
'_nocolor',
'', $pictowithouttext);
4160 if (strpos($pictowithouttext,
'fontawesome_') !==
false || preg_match(
'/^fa-/', $pictowithouttext)) {
4162 $pictowithouttext = str_replace(
'fontawesome_',
'', $pictowithouttext);
4163 $pictowithouttext = str_replace(
'fa-',
'', $pictowithouttext);
4165 $pictowithouttextarray = explode(
'_', $pictowithouttext);
4166 $marginleftonlyshort = 0;
4168 if (!empty($pictowithouttextarray[1])) {
4170 $fakey =
'fa-'.$pictowithouttextarray[0];
4171 $fa = empty($pictowithouttextarray[1]) ?
'fa' : $pictowithouttextarray[1];
4172 $facolor = empty($pictowithouttextarray[2]) ?
'' : $pictowithouttextarray[2];
4173 $fasize = empty($pictowithouttextarray[3]) ?
'' : $pictowithouttextarray[3];
4175 $fakey =
'fa-'.$pictowithouttext;
4185 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
4186 $morecss .= ($morecss ?
' ' :
'').$reg[1];
4187 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
4189 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
4190 $morestyle = $reg[1];
4191 $moreatt = str_replace(
'style="'.$reg[1].
'"',
'', $moreatt);
4193 $moreatt = trim($moreatt);
4195 $enabledisablehtml =
'<span class="'.$fa.
' '.$fakey.($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
4196 $enabledisablehtml .= ($morecss ?
' '.$morecss :
'').
'" style="'.($fasize ? (
'font-size: '.$fasize.
';') :
'').($facolor ? (
' color: '.$facolor.
';') :
'').($morestyle ?
' '.$morestyle :
'').
'"'.(($notitle || empty($titlealt)) ?
'' :
' title="'.
dol_escape_htmltag($titlealt).
'"').($moreatt ?
' '.$moreatt :
'').
'>';
4200 $enabledisablehtml .=
'</span>';
4202 return $enabledisablehtml;
4205 if (empty($srconly) && in_array($pictowithouttext, array(
4206 '1downarrow',
'1uparrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected',
4207 'accountancy',
'accounting_account',
'account',
'accountline',
'action',
'add',
'address',
'angle-double-down',
'angle-double-up',
'asset',
4208 'bank_account',
'barcode',
'bank',
'bell',
'bill',
'billa',
'billr',
'billd',
'birthday-cake',
'bookmark',
'bom',
'briefcase-medical',
'bug',
'building',
4209 'card',
'calendarlist',
'calendar',
'calendarmonth',
'calendarweek',
'calendarday',
'calendarperuser',
'calendarpertype',
4210 'cash-register',
'category',
'chart',
'check',
'clock',
'clone',
'close_title',
'cog',
'collab',
'company',
'contact',
'country',
'contract',
'conversation',
'cron',
'cross',
'cubes',
4211 'currency',
'multicurrency',
4212 'delete',
'dolly',
'dollyrevert',
'donation',
'download',
'dynamicprice',
4213 'edit',
'ellipsis-h',
'email',
'entity',
'envelope',
'eraser',
'establishment',
'expensereport',
'external-link-alt',
'external-link-square-alt',
'eye',
4214 'filter',
'file-code',
'file-export',
'file-import',
'file-upload',
'autofill',
'folder',
'folder-open',
'folder-plus',
4215 'gears',
'generate',
'generic',
'globe',
'globe-americas',
'graph',
'grip',
'grip_title',
'group',
4216 'hands-helping',
'help',
'holiday',
4217 'id-card',
'images',
'incoterm',
'info',
'intervention',
'inventory',
'intracommreport',
'jobprofile',
4218 'knowledgemanagement',
4219 'label',
'language',
'line',
'link',
'list',
'list-alt',
'listlight',
'loan',
'lock',
'lot',
'long-arrow-alt-right',
4220 'margin',
'map-marker-alt',
'member',
'meeting',
'money-bill-alt',
'movement',
'mrp',
'note',
'next',
4221 'off',
'on',
'order',
4222 'paiment',
'paragraph',
'play',
'pdf',
'phone',
'phoning',
'phoning_mobile',
'phoning_fax',
'playdisabled',
'previous',
'poll',
'pos',
'printer',
'product',
'propal',
'proposal',
'puce',
4223 'stock',
'resize',
'service',
'stats',
'trip',
4224 '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',
4225 'github',
'google',
'jabber',
'microsoft',
'skype',
'twitter',
'facebook',
'linkedin',
'instagram',
'snapchat',
'youtube',
'google-plus-g',
'whatsapp',
4226 'chevron-left',
'chevron-right',
'chevron-down',
'chevron-top',
'commercial',
'companies',
4227 'generic',
'home',
'hrm',
'members',
'products',
'invoicing',
4228 'partnership',
'payment',
'payment_vat',
'pencil-ruler',
'pictoconfirm',
'preview',
'project',
'projectpub',
'projecttask',
'question',
'refresh',
'region',
4229 'salary',
'shipment',
'state',
'supplier_invoice',
'supplier_invoicea',
'supplier_invoicer',
'supplier_invoiced',
4230 'technic',
'ticket',
4232 'recent',
'reception',
'recruitmentcandidature',
'recruitmentjobposition',
'replacement',
'resource',
'recurring',
'rss',
4233 'shapes',
'skill',
'square',
'stop-circle',
'supplier',
'supplier_proposal',
'supplier_order',
'supplier_invoice',
4234 'timespent',
'title_setup',
'title_accountancy',
'title_bank',
'title_hrm',
'title_agenda',
4235 'uncheck',
'url',
'user-cog',
'user-injured',
'user-md',
'vat',
'website',
'workstation',
'webhook',
'world',
'private',
4236 'conferenceorbooth',
'eventorganization',
4237 'stamp',
'signature'
4239 $fakey = $pictowithouttext;
4243 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'))) {
4246 if (in_array($pictowithouttext, array(
'black-tie',
'github',
'google',
'microsoft',
'skype',
'twitter',
'facebook',
'linkedin',
'instagram',
'snapchat',
'stripe',
'stripe-s',
'youtube',
'google-plus-g',
'whatsapp'))) {
4250 $arrayconvpictotofa = array(
4251 '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',
4252 'bank_account'=>
'university',
4253 'bill'=>
'file-invoice-dollar',
'billa'=>
'file-excel',
'billr'=>
'file-invoice-dollar',
'billd'=>
'file-medical',
4254 'supplier_invoice'=>
'file-invoice-dollar',
'supplier_invoicea'=>
'file-excel',
'supplier_invoicer'=>
'file-invoice-dollar',
'supplier_invoiced'=>
'file-medical',
4256 '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',
4257 'donation'=>
'file-alt',
'dynamicprice'=>
'hand-holding-usd',
4258 'setup'=>
'cog',
'companies'=>
'building',
'products'=>
'cube',
'commercial'=>
'suitcase',
'invoicing'=>
'coins',
4259 'accounting'=>
'search-dollar',
'category'=>
'tag',
'dollyrevert'=>
'dolly',
4260 'generate'=>
'plus-square',
'hrm'=>
'user-tie',
'incoterm'=>
'truck-loading',
4261 'margin'=>
'calculator',
'members'=>
'user-friends',
'ticket'=>
'ticket-alt',
'globe'=>
'external-link-alt',
'lot'=>
'barcode',
4262 'email'=>
'at',
'establishment'=>
'building',
'edit'=>
'pencil-alt',
'entity'=>
'globe',
4263 'graph'=>
'chart-line',
'grip_title'=>
'arrows-alt',
'grip'=>
'arrows-alt',
'help'=>
'question-circle',
4264 'generic'=>
'file',
'holiday'=>
'umbrella-beach',
4265 'info'=>
'info-circle',
'inventory'=>
'boxes',
'intracommreport'=>
'globe-europe',
'jobprofile'=>
'cogs',
4266 'knowledgemanagement'=>
'ticket-alt',
'label'=>
'layer-group',
'line'=>
'bars',
'loan'=>
'money-bill-alt',
4267 'member'=>
'user-alt',
'meeting'=>
'chalkboard-teacher',
'mrp'=>
'cubes',
'next'=>
'arrow-alt-circle-right',
4268 'trip'=>
'wallet',
'expensereport'=>
'wallet',
'group'=>
'users',
'movement'=>
'people-carry',
4269 'sign-out'=>
'sign-out-alt',
4270 'switch_off'=>
'toggle-off',
'switch_on'=>
'toggle-on',
'switch_on_warning'=>
'toggle-on',
'switch_on_red'=>
'toggle-on',
'check'=>
'check',
'bookmark'=>
'star',
4271 'bank'=>
'university',
'close_title'=>
'times',
'delete'=>
'trash',
'filter'=>
'filter',
4272 'list-alt'=>
'list-alt',
'calendarlist'=>
'bars',
'calendar'=>
'calendar-alt',
'calendarmonth'=>
'calendar-alt',
'calendarweek'=>
'calendar-week',
'calendarday'=>
'calendar-day',
'calendarperuser'=>
'table',
4273 'intervention'=>
'ambulance',
'invoice'=>
'file-invoice-dollar',
'currency'=>
'dollar-sign',
'multicurrency'=>
'dollar-sign',
'order'=>
'file-invoice',
4274 'error'=>
'exclamation-triangle',
'warning'=>
'exclamation-triangle',
4276 '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',
4277 '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',
4278 'recent' =>
'check-square',
'reception'=>
'dolly',
'recruitmentjobposition'=>
'id-card-alt',
'recruitmentcandidature'=>
'id-badge',
4279 'resize'=>
'crop',
'supplier_order'=>
'dol-order_supplier',
'supplier_proposal'=>
'file-signature',
4280 'refresh'=>
'redo',
'region'=>
'map-marked',
'replacement'=>
'exchange-alt',
'resource'=>
'laptop-house',
'recurring'=>
'history',
4281 'service'=>
'concierge-bell',
4282 'skill'=>
'shapes',
'state'=>
'map-marked-alt',
'security'=>
'key',
'salary'=>
'wallet',
'shipment'=>
'dolly',
'stock'=>
'box-open',
'stats' =>
'chart-bar',
'split'=>
'code-branch',
'stripe'=>
'stripe-s',
4283 'supplier'=>
'building',
'technic'=>
'cogs',
4284 'timespent'=>
'clock',
'title_setup'=>
'tools',
'title_accountancy'=>
'money-check-alt',
'title_bank'=>
'university',
'title_hrm'=>
'umbrella-beach',
4285 'title_agenda'=>
'calendar-alt',
4286 'uncheck'=>
'times',
'uparrow'=>
'share',
'url'=>
'external-link-alt',
'vat'=>
'money-check-alt',
'vcard'=>
'arrow-alt-circle-down',
4287 'jabber'=>
'comment-o',
4288 'website'=>
'globe-americas',
'workstation'=>
'pallet',
'webhook'=>
'bullseye',
'world'=>
'globe',
'private'=>
'user-lock',
4289 'conferenceorbooth'=>
'chalkboard-teacher',
'eventorganization'=>
'project-diagram'
4291 if ($pictowithouttext ==
'off') {
4292 $fakey =
'fa-square';
4294 } elseif ($pictowithouttext ==
'on') {
4295 $fakey =
'fa-check-square';
4297 } elseif ($pictowithouttext ==
'listlight') {
4298 $fakey =
'fa-download';
4299 $marginleftonlyshort = 1;
4300 } elseif ($pictowithouttext ==
'printer') {
4301 $fakey =
'fa-print';
4303 } elseif ($pictowithouttext ==
'note') {
4304 $fakey =
'fa-sticky-note';
4305 $marginleftonlyshort = 1;
4306 } elseif (in_array($pictowithouttext, array(
'1uparrow',
'1downarrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected'))) {
4307 $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');
4308 $fakey =
'fa-'.$convertarray[$pictowithouttext];
4309 if (preg_match(
'/selected/', $pictowithouttext)) {
4312 $marginleftonlyshort = 1;
4313 } elseif (!empty($arrayconvpictotofa[$pictowithouttext])) {
4314 $fakey =
'fa-'.$arrayconvpictotofa[$pictowithouttext];
4316 $fakey =
'fa-'.$pictowithouttext;
4319 if (in_array($pictowithouttext, array(
'dollyrevert',
'member',
'members',
'contract',
'group',
'resource',
'shipment'))) {
4320 $morecss .=
' em092';
4322 if (in_array($pictowithouttext, array(
'conferenceorbooth',
'collab',
'eventorganization',
'holiday',
'info',
'project',
'workstation'))) {
4323 $morecss .=
' em088';
4325 if (in_array($pictowithouttext, array(
'asset',
'intervention',
'payment',
'loan',
'partnership',
'stock',
'technic'))) {
4326 $morecss .=
' em080';
4330 $arrayconvpictotomarginleftonly = array(
4331 'bank',
'check',
'delete',
'generic',
'grip',
'grip_title',
'jabber',
4332 'grip_title',
'grip',
'listlight',
'note',
'on',
'off',
'playdisabled',
'printer',
'resize',
'sign-out',
'stats',
'switch_on',
'switch_on_red',
'switch_off',
4333 'uparrow',
'1uparrow',
'1downarrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected'
4335 if (!isset($arrayconvpictotomarginleftonly[$pictowithouttext])) {
4336 $marginleftonlyshort = 0;
4340 $arrayconvpictotomorcess = array(
4341 'action'=>
'infobox-action',
'account'=>
'infobox-bank_account',
'accounting_account'=>
'infobox-bank_account',
'accountline'=>
'infobox-bank_account',
'accountancy'=>
'infobox-bank_account',
'asset'=>
'infobox-bank_account',
4342 'bank_account'=>
'infobox-bank_account',
4343 'bill'=>
'infobox-commande',
'billa'=>
'infobox-commande',
'billr'=>
'infobox-commande',
'billd'=>
'infobox-commande',
4344 'margin'=>
'infobox-bank_account',
'conferenceorbooth'=>
'infobox-project',
4345 'cash-register'=>
'infobox-bank_account',
'contract'=>
'infobox-contrat',
'check'=>
'font-status4',
'collab'=>
'infobox-action',
'conversation'=>
'infobox-contrat',
4346 'donation'=>
'infobox-commande',
'dolly'=>
'infobox-commande',
'dollyrevert'=>
'flip infobox-order_supplier',
4347 'ecm'=>
'infobox-action',
'eventorganization'=>
'infobox-project',
4348 'hrm'=>
'infobox-adherent',
'group'=>
'infobox-adherent',
'intervention'=>
'infobox-contrat',
4349 'incoterm'=>
'infobox-supplier_proposal',
4350 'currency'=>
'infobox-bank_account',
'multicurrency'=>
'infobox-bank_account',
4351 'members'=>
'infobox-adherent',
'member'=>
'infobox-adherent',
'money-bill-alt'=>
'infobox-bank_account',
4352 'order'=>
'infobox-commande',
4353 'user'=>
'infobox-adherent',
'users'=>
'infobox-adherent',
4354 'error'=>
'pictoerror',
'warning'=>
'pictowarning',
'switch_on'=>
'font-status4',
'switch_on_warning'=>
'font-status4 warning',
'switch_on_red'=>
'font-status8',
4355 'holiday'=>
'infobox-holiday',
'info'=>
'opacityhigh',
'invoice'=>
'infobox-commande',
4356 'knowledgemanagement'=>
'infobox-contrat rotate90',
'loan'=>
'infobox-bank_account',
4357 'payment'=>
'infobox-bank_account',
'payment_vat'=>
'infobox-bank_account',
'poll'=>
'infobox-adherent',
'pos'=>
'infobox-bank_account',
'project'=>
'infobox-project',
'projecttask'=>
'infobox-project',
4358 'propal'=>
'infobox-propal',
'proposal'=>
'infobox-propal',
'private'=>
'infobox-project',
4359 'reception'=>
'flip',
'recruitmentjobposition'=>
'infobox-adherent',
'recruitmentcandidature'=>
'infobox-adherent',
4360 'resource'=>
'infobox-action',
4361 'salary'=>
'infobox-bank_account',
'shipment'=>
'infobox-commande',
'supplier_invoice'=>
'infobox-order_supplier',
'supplier_invoicea'=>
'infobox-order_supplier',
'supplier_invoiced'=>
'infobox-order_supplier',
4362 'supplier'=>
'infobox-order_supplier',
'supplier_order'=>
'infobox-order_supplier',
'supplier_proposal'=>
'infobox-supplier_proposal',
4363 'ticket'=>
'infobox-contrat',
'title_accountancy'=>
'infobox-bank_account',
'title_hrm'=>
'infobox-holiday',
'expensereport'=>
'infobox-expensereport',
'trip'=>
'infobox-expensereport',
'title_agenda'=>
'infobox-action',
4364 'vat'=>
'infobox-bank_account',
4366 'list-alt'=>
'imgforviewmode',
'calendar'=>
'imgforviewmode',
'calendarweek'=>
'imgforviewmode',
'calendarmonth'=>
'imgforviewmode',
'calendarday'=>
'imgforviewmode',
'calendarperuser'=>
'imgforviewmode'
4368 if (!empty($arrayconvpictotomorcess[$pictowithouttext]) && strpos($picto,
'_nocolor') ===
false) {
4369 $morecss .= ($morecss ?
' ' :
'').$arrayconvpictotomorcess[$pictowithouttext];
4373 $arrayconvpictotocolor = array(
4374 'address'=>
'#6c6aa8',
'building'=>
'#6c6aa8',
'bom'=>
'#a69944',
4375 'clone'=>
'#999',
'cog'=>
'#999',
'companies'=>
'#6c6aa8',
'company'=>
'#6c6aa8',
'contact'=>
'#6c6aa8',
'cron'=>
'#555',
4376 'dynamicprice'=>
'#a69944',
4377 'edit'=>
'#444',
'note'=>
'#999',
'error'=>
'',
'help'=>
'#bbb',
'listlight'=>
'#999',
'language'=>
'#555',
4379 'lock'=>
'#ddd',
'lot'=>
'#a69944',
4380 'map-marker-alt'=>
'#aaa',
'mrp'=>
'#a69944',
'product'=>
'#a69944',
'service'=>
'#a69944',
'inventory'=>
'#a69944',
'stock'=>
'#a69944',
'movement'=>
'#a69944',
4381 'other'=>
'#ddd',
'world'=>
'#986c6a',
4382 'partnership'=>
'#6c6aa8',
'playdisabled'=>
'#ccc',
'printer'=>
'#444',
'projectpub'=>
'#986c6a',
'reception'=>
'#a69944',
'resize'=>
'#444',
'rss'=>
'#cba',
4384 'security'=>
'#999',
'square'=>
'#888',
'stop-circle'=>
'#888',
'stats'=>
'#444',
'switch_off'=>
'#999',
'technic'=>
'#999',
'timespent'=>
'#555',
4385 'uncheck'=>
'#800',
'uparrow'=>
'#555',
'user-cog'=>
'#999',
'country'=>
'#aaa',
'globe-americas'=>
'#aaa',
'region'=>
'#aaa',
'state'=>
'#aaa',
4386 'website'=>
'#304',
'workstation'=>
'#a69944'
4388 if (isset($arrayconvpictotocolor[$pictowithouttext]) && strpos($picto,
'_nocolor') ===
false) {
4389 $facolor = $arrayconvpictotocolor[$pictowithouttext];
4396 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
4397 $morecss .= ($morecss ?
' ' :
'').$reg[1];
4398 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
4400 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
4401 $morestyle = $reg[1];
4402 $moreatt = str_replace(
'style="'.$reg[1].
'"',
'', $moreatt);
4404 $moreatt = trim($moreatt);
4406 $enabledisablehtml =
'<span class="'.$fa.
' '.$fakey.($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
4407 $enabledisablehtml .= ($morecss ?
' '.$morecss :
'').
'" style="'.($fasize ? (
'font-size: '.$fasize.
';') :
'').($facolor ? (
' color: '.$facolor.
';') :
'').($morestyle ?
' '.$morestyle :
'').
'"'.(($notitle || empty($titlealt)) ?
'' :
' title="'.
dol_escape_htmltag($titlealt).
'"').($moreatt ?
' '.$moreatt :
'').
'>';
4411 $enabledisablehtml .=
'</span>';
4413 return $enabledisablehtml;
4416 if (!empty($conf->global->MAIN_OVERWRITE_THEME_PATH)) {
4417 $path = $conf->global->MAIN_OVERWRITE_THEME_PATH.
'/theme/'.$theme;
4418 } elseif (!empty($conf->global->MAIN_OVERWRITE_THEME_RES)) {
4419 $path = $conf->global->MAIN_OVERWRITE_THEME_RES.
'/theme/'.$conf->global->MAIN_OVERWRITE_THEME_RES;
4420 } elseif (!empty($conf->modules_parts[
'theme']) && array_key_exists($theme, $conf->modules_parts[
'theme'])) {
4421 $path = $theme.
'/theme/'.$theme;
4426 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $picto, $regs)) {
4432 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
4437 foreach ($conf->file->dol_document_root as $type => $dirroot) {
4438 if ($type ==
'main') {
4442 if (file_exists($dirroot.
'/'.$path.
'/img/'.$picto)) {
4443 $url = DOL_URL_ROOT.$conf->file->dol_url_root[$type];
4449 $fullpathpicto = $url.
'/'.$path.
'/img/'.$picto;
4453 return $fullpathpicto;
4457 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 :
'').
'"').
'>';
4473 function img_object($titlealt, $picto, $moreatt =
'', $pictoisfullpath =
false, $srconly = 0, $notitle = 0)
4475 if (strpos($picto,
'^') === 0) {
4476 return img_picto($titlealt, str_replace(
'^',
'', $picto), $moreatt, $pictoisfullpath, $srconly, $notitle);
4478 return img_picto($titlealt,
'object_'.$picto, $moreatt, $pictoisfullpath, $srconly, $notitle);
4493 function img_weather($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $morecss =
'')
4497 if (is_numeric($picto)) {
4500 return '<i class="fa fa-weather-level'.$picto.
'"></i>';
4501 } elseif (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
4505 $path = DOL_URL_ROOT.
'/theme/'.$conf->theme.
'/img/weather/'.$picto;
4507 return img_picto($titlealt, $path, $moreatt, 1, 0, 0,
'', $morecss);
4521 function img_picto_common($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $notitle = 0)
4525 if (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
4529 if ($pictoisfullpath) {
4532 $path = DOL_URL_ROOT.
'/theme/common/'.$picto;
4534 if (!empty($conf->global->MAIN_MODULE_CAN_OVERWRITE_COMMONICONS)) {
4535 $themepath = DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/img/'.$picto;
4537 if (file_exists($themepath)) {
4543 return img_picto($titlealt, $path, $moreatt, 1, 0, $notitle);
4559 function img_action($titlealt, $numaction, $picto =
'', $moreatt =
'')
4563 if (empty($titlealt) || $titlealt ==
'default') {
4564 if ($numaction ==
'-1' || $numaction ==
'ST_NO') {
4566 $titlealt = $langs->transnoentitiesnoconv(
'ChangeDoNotContact');
4567 } elseif ($numaction ==
'0' || $numaction ==
'ST_NEVER') {
4569 $titlealt = $langs->transnoentitiesnoconv(
'ChangeNeverContacted');
4570 } elseif ($numaction ==
'1' || $numaction ==
'ST_TODO') {
4572 $titlealt = $langs->transnoentitiesnoconv(
'ChangeToContact');
4573 } elseif ($numaction ==
'2' || $numaction ==
'ST_PEND') {
4575 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactInProcess');
4576 } elseif ($numaction ==
'3' || $numaction ==
'ST_DONE') {
4578 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactDone');
4580 $titlealt = $langs->transnoentitiesnoconv(
'ChangeStatus '.$numaction);
4584 if (!is_numeric($numaction)) {
4588 return img_picto($titlealt, (empty($picto) ?
'stcomm'.$numaction.
'.png' : $picto), $moreatt);
4598 function img_pdf($titlealt =
'default', $size = 3)
4602 if ($titlealt ==
'default') {
4603 $titlealt = $langs->trans(
'Show');
4606 return img_picto($titlealt,
'pdf'.$size.
'.png');
4620 if ($titlealt ==
'default') {
4621 $titlealt = $langs->trans(
'Add');
4624 return img_picto($titlealt,
'edit_add.png', $other);
4637 if ($titlealt ==
'default') {
4638 $titlealt = $langs->trans(
'Remove');
4641 return img_picto($titlealt,
'edit_remove.png', $other);
4652 function img_edit($titlealt =
'default', $float = 0, $other =
'')
4656 if ($titlealt ==
'default') {
4657 $titlealt = $langs->trans(
'Modify');
4660 return img_picto($titlealt,
'edit.png', ($float ?
'style="float: '.($langs->tab_translate[
"DIRECTION"] ==
'rtl' ?
'left' :
'right').
'"' :
"").($other ?
' '.$other :
''));
4671 function img_view($titlealt =
'default', $float = 0, $other =
'class="valignmiddle"')
4675 if ($titlealt ==
'default') {
4676 $titlealt = $langs->trans(
'View');
4679 $moreatt = ($float ?
'style="float: right" ' :
'').$other;
4681 return img_picto($titlealt,
'eye', $moreatt);
4692 function img_delete($titlealt =
'default', $other =
'class="pictodelete"', $morecss =
'')
4696 if ($titlealt ==
'default') {
4697 $titlealt = $langs->trans(
'Delete');
4700 return img_picto($titlealt,
'delete.png', $other,
false, 0, 0,
'', $morecss);
4713 if ($titlealt ==
"default") {
4714 $titlealt = $langs->trans(
"Print");
4716 return img_picto($titlealt,
'printer.png', $other);
4726 function img_split($titlealt =
'default', $other =
'class="pictosplit"')
4730 if ($titlealt ==
'default') {
4731 $titlealt = $langs->trans(
'Split');
4734 return img_picto($titlealt,
'split.png', $other);
4744 function img_help($usehelpcursor = 1, $usealttitle = 1)
4749 if (is_string($usealttitle)) {
4752 $usealttitle = $langs->trans(
'Info');
4756 return img_picto($usealttitle,
'info.png',
'style="vertical-align: middle;'.($usehelpcursor == 1 ?
' cursor: help' : ($usehelpcursor == 2 ?
' cursor: pointer' :
'')).
'"');
4769 if ($titlealt ==
'default') {
4770 $titlealt = $langs->trans(
'Informations');
4773 return img_picto($titlealt,
'info.png',
'style="vertical-align: middle;"');
4784 function img_warning($titlealt =
'default', $moreatt =
'', $morecss =
'pictowarning')
4788 if ($titlealt ==
'default') {
4789 $titlealt = $langs->trans(
'Warning');
4793 return img_picto($titlealt,
'warning.png',
'class="'.$morecss.
'"'.($moreatt ? ($moreatt ==
'1' ?
' style="float: right"' :
' '.$moreatt) :
''));
4806 if ($titlealt ==
'default') {
4807 $titlealt = $langs->trans(
'Error');
4810 return img_picto($titlealt,
'error.png');
4820 function img_next($titlealt =
'default', $moreatt =
'')
4824 if ($titlealt ==
'default') {
4825 $titlealt = $langs->trans(
'Next');
4829 return '<span class="fa fa-chevron-right paddingright paddingleft" title="'.dol_escape_htmltag($titlealt).
'"></span>';
4843 if ($titlealt ==
'default') {
4844 $titlealt = $langs->trans(
'Previous');
4848 return '<span class="fa fa-chevron-left paddingright paddingleft" title="'.dol_escape_htmltag($titlealt).
'"></span>';
4859 function img_down($titlealt =
'default', $selected = 0, $moreclass =
'')
4863 if ($titlealt ==
'default') {
4864 $titlealt = $langs->trans(
'Down');
4867 return img_picto($titlealt, ($selected ?
'1downarrow_selected.png' :
'1downarrow.png'),
'class="imgdown'.($moreclass ?
" ".$moreclass :
"").
'"');
4878 function img_up($titlealt =
'default', $selected = 0, $moreclass =
'')
4882 if ($titlealt ==
'default') {
4883 $titlealt = $langs->trans(
'Up');
4886 return img_picto($titlealt, ($selected ?
'1uparrow_selected.png' :
'1uparrow.png'),
'class="imgup'.($moreclass ?
" ".$moreclass :
"").
'"');
4897 function img_left($titlealt =
'default', $selected = 0, $moreatt =
'')
4901 if ($titlealt ==
'default') {
4902 $titlealt = $langs->trans(
'Left');
4905 return img_picto($titlealt, ($selected ?
'1leftarrow_selected.png' :
'1leftarrow.png'), $moreatt);
4916 function img_right($titlealt =
'default', $selected = 0, $moreatt =
'')
4920 if ($titlealt ==
'default') {
4921 $titlealt = $langs->trans(
'Right');
4924 return img_picto($titlealt, ($selected ?
'1rightarrow_selected.png' :
'1rightarrow.png'), $moreatt);
4938 if ($titlealt ==
'default') {
4939 $titlealt = $langs->trans(
'Active');
4943 return img_picto($titlealt,
'tick.png');
4958 if (is_null($morecss)) {
4962 if ($brand ==
'visa' || $brand ==
'Visa') {
4964 } elseif ($brand ==
'mastercard' || $brand ==
'MasterCard') {
4965 $brand =
'cc-mastercard';
4966 } elseif ($brand ==
'amex' || $brand ==
'American Express') {
4968 } elseif ($brand ==
'discover' || $brand ==
'Discover') {
4969 $brand =
'cc-discover';
4970 } elseif ($brand ==
'jcb' || $brand ==
'JCB') {
4972 } elseif ($brand ==
'diners' || $brand ==
'Diners club') {
4973 $brand =
'cc-diners-club';
4974 } elseif (!in_array($brand, array(
'cc-visa',
'cc-mastercard',
'cc-amex',
'cc-discover',
'cc-jcb',
'cc-diners-club'))) {
4975 $brand =
'credit-card';
4978 return '<span class="fa fa-'.$brand.
' fa-fw'.($morecss ?
' '.$morecss :
'').
'"></span>';
4989 function img_mime($file, $titlealt =
'', $morecss =
'')
4991 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
4997 if (empty($titlealt)) {
4998 $titlealt =
'Mime type: '.$mimetype;
5002 return '<i class="fa fa-'.$mimefa.
' paddingright'.($morecss ?
' '.$morecss :
'').
'"'.($titlealt ?
' title="'.$titlealt.
'"' :
'').
'></i>';
5015 global $conf, $langs;
5017 if ($titlealt ==
'default') {
5018 $titlealt = $langs->trans(
'Search');
5021 $img =
img_picto($titlealt,
'search.png', $other,
false, 1);
5023 $input =
'<input type="image" class="liste_titre" name="button_search" src="'.$img.
'" ';
5024 $input .=
'value="'.dol_escape_htmltag($titlealt).
'" title="'.
dol_escape_htmltag($titlealt).
'" >';
5038 global $conf, $langs;
5040 if ($titlealt ==
'default') {
5041 $titlealt = $langs->trans(
'Search');
5044 $img =
img_picto($titlealt,
'searchclear.png', $other,
false, 1);
5046 $input =
'<input type="image" class="liste_titre" name="button_removefilter" src="'.$img.
'" ';
5047 $input .=
'value="'.dol_escape_htmltag($titlealt).
'" title="'.
dol_escape_htmltag($titlealt).
'" >';
5063 function info_admin($text, $infoonimgalt = 0, $nodiv = 0, $admin =
'1', $morecss =
'hideonsmartphone', $textfordropdown =
'')
5065 global $conf, $langs;
5067 if ($infoonimgalt) {
5068 $result =
img_picto($text,
'info',
'class="'.($morecss ?
' '.$morecss :
'').
'"');
5070 if (empty($conf->use_javascript_ajax)) {
5071 $textfordropdown =
'';
5074 $class = (empty($admin) ?
'undefined' : ($admin ==
'1' ?
'info' : $admin));
5075 $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>');
5077 if ($textfordropdown) {
5078 $tmpresult =
'<span class="'.$class.
'text opacitymedium cursorpointer">'.$langs->trans($textfordropdown).
' '.
img_picto($langs->trans($textfordropdown),
'1downarrow').
'</span>';
5079 $tmpresult .=
'<script nonce="'.getNonce().
'" type="text/javascript">
5080 jQuery(document).ready(function() {
5081 jQuery(".'.$class.
'text").click(function() {
5082 console.log("toggle text");
5083 jQuery(".'.$class.
'").toggle();
5088 $result = $tmpresult.$result;
5109 global $conf, $langs, $argv;
5110 global $dolibarr_main_prod;
5117 require_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
5119 $langs->load(
"main");
5123 $langs->loadLangs(array(
'main',
'errors'));
5125 if ($_SERVER[
'DOCUMENT_ROOT']) {
5126 $out .= $langs->trans(
"DolibarrHasDetectedError").
".<br>\n";
5128 $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";
5130 $out .= $langs->trans(
"InformationToHelpDiagnose").
":<br>\n";
5132 $out .=
"<b>".$langs->trans(
"Date").
":</b> ".
dol_print_date(time(),
'dayhourlog').
"<br>\n";
5133 $out .=
"<b>".$langs->trans(
"Dolibarr").
":</b> ".DOL_VERSION.
" - https://www.dolibarr.org<br>\n";
5134 if (isset($conf->global->MAIN_FEATURES_LEVEL)) {
5135 $out .=
"<b>".$langs->trans(
"LevelOfFeature").
":</b> ".
getDolGlobalInt(
'MAIN_FEATURES_LEVEL').
"<br>\n";
5137 if (function_exists(
"phpversion")) {
5138 $out .=
"<b>".$langs->trans(
"PHP").
":</b> ".phpversion().
"<br>\n";
5140 $out .=
"<b>".$langs->trans(
"Server").
":</b> ".(isset($_SERVER[
"SERVER_SOFTWARE"]) ?
dol_htmlentities($_SERVER[
"SERVER_SOFTWARE"], ENT_COMPAT) :
'').
"<br>\n";
5141 if (function_exists(
"php_uname")) {
5142 $out .=
"<b>".$langs->trans(
"OS").
":</b> ".php_uname().
"<br>\n";
5144 $out .=
"<b>".$langs->trans(
"UserAgent").
":</b> ".(isset($_SERVER[
"HTTP_USER_AGENT"]) ?
dol_htmlentities($_SERVER[
"HTTP_USER_AGENT"], ENT_COMPAT) :
'').
"<br>\n";
5146 $out .=
"<b>".$langs->trans(
"RequestedUrl").
":</b> ".
dol_htmlentities($_SERVER[
"REQUEST_URI"], ENT_COMPAT).
"<br>\n";
5147 $out .=
"<b>".$langs->trans(
"Referer").
":</b> ".(isset($_SERVER[
"HTTP_REFERER"]) ?
dol_htmlentities($_SERVER[
"HTTP_REFERER"], ENT_COMPAT) :
'').
"<br>\n";
5148 $out .=
"<b>".$langs->trans(
"MenuManager").
":</b> ".(isset($conf->standard_menu) ?
dol_htmlentities($conf->standard_menu, ENT_COMPAT) :
'').
"<br>\n";
5150 $syslog .=
"url=".dol_escape_htmltag($_SERVER[
"REQUEST_URI"]);
5151 $syslog .=
", query_string=".dol_escape_htmltag($_SERVER[
"QUERY_STRING"]);
5153 $out .=
'> '.$langs->transnoentities(
"ErrorInternalErrorDetected").
":\n".$argv[0].
"\n";
5154 $syslog .=
"pid=".dol_getmypid();
5157 if (!empty($conf->modules)) {
5158 $out .=
"<b>".$langs->trans(
"Modules").
":</b> ".join(
', ', $conf->modules).
"<br>\n";
5161 if (is_object($db)) {
5162 if ($_SERVER[
'DOCUMENT_ROOT']) {
5163 $out .=
"<b>".$langs->trans(
"DatabaseTypeManager").
":</b> ".$db->type.
"<br>\n";
5164 $lastqueryerror = $db->lastqueryerror();
5166 $lastqueryerror =
"SQL error string is not a valid UTF8 string. We can't show it.";
5168 $out .=
"<b>".$langs->trans(
"RequestLastAccessInError").
":</b> ".($lastqueryerror ?
dol_escape_htmltag($lastqueryerror) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
5169 $out .=
"<b>".$langs->trans(
"ReturnCodeLastAccessInError").
":</b> ".($db->lasterrno() ?
dol_escape_htmltag($db->lasterrno()) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
5170 $out .=
"<b>".$langs->trans(
"InformationLastAccessInError").
":</b> ".($db->lasterror() ?
dol_escape_htmltag($db->lasterror()) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
5174 $out .=
'> '.$langs->transnoentities(
"DatabaseTypeManager").
":\n".$db->type.
"\n";
5175 $out .=
'> '.$langs->transnoentities(
"RequestLastAccessInError").
":\n".($db->lastqueryerror() ? $db->lastqueryerror() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
5176 $out .=
'> '.$langs->transnoentities(
"ReturnCodeLastAccessInError").
":\n".($db->lasterrno() ? $db->lasterrno() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
5177 $out .=
'> '.$langs->transnoentities(
"InformationLastAccessInError").
":\n".($db->lasterror() ? $db->lasterror() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
5179 $syslog .=
", sql=".$db->lastquery();
5180 $syslog .=
", db_error=".$db->lasterror();
5183 if ($error || $errors) {
5184 $langs->load(
"errors");
5187 if (is_array($error) && is_array($errors)) {
5188 $errors = array_merge($error, $errors);
5189 } elseif (is_array($error)) {
5191 } elseif (is_array($errors)) {
5192 $errors = array_merge(array($error), $errors);
5194 $errors = array_merge(array($error), array($errors));
5197 foreach ($errors as $msg) {
5201 if ($_SERVER[
'DOCUMENT_ROOT']) {
5205 $out .=
'> '.$langs->transnoentities(
"Message").
":\n".$msg.
"\n";
5207 $syslog .=
", msg=".$msg;
5210 if (empty($dolibarr_main_prod) && $_SERVER[
'DOCUMENT_ROOT'] && function_exists(
'xdebug_print_function_stack') && function_exists(
'xdebug_call_file')) {
5211 xdebug_print_function_stack();
5212 $out .=
'<b>XDebug informations:</b>'.
"<br>\n";
5213 $out .=
'File: '.xdebug_call_file().
"<br>\n";
5214 $out .=
'Line: '.xdebug_call_line().
"<br>\n";
5215 $out .=
'Function: '.xdebug_call_function().
"<br>\n";
5220 if (!headers_sent()) {
5221 if (function_exists(
'top_httphead')) {
5225 http_response_code(202);
5228 if (empty($dolibarr_main_prod)) {
5231 if (empty($langs->defaultlang)) {
5232 $langs->setDefaultLang();
5234 $langs->loadLangs(array(
"main",
"errors"));
5236 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";
5237 print $langs->trans(
"DolibarrHasDetectedError").
'. ';
5238 print $langs->trans(
"YouCanSetOptionDolibarrMainProdToZero");
5239 define(
"MAIN_CORE_ERROR", 1);
5255 function dol_print_error_email($prefixcode, $errormessage =
'', $errormessages = array(), $morecss =
'error', $email =
'')
5257 global $langs, $conf;
5259 if (empty($email)) {
5260 $email = $conf->global->MAIN_INFO_SOCIETE_MAIL;
5263 $langs->load(
"errors");
5266 print
'<br><div class="center login_main_message"><div class="'.$morecss.
'">';
5267 print $langs->trans(
"ErrorContactEMail", $email, $prefixcode.
'-'.
dol_print_date($now,
'%Y%m%d%H%M%S'));
5268 if ($errormessage) {
5269 print
'<br><br>'.$errormessage;
5271 if (is_array($errormessages) && count($errormessages)) {
5272 foreach ($errormessages as $mesgtoshow) {
5273 print
'<br><br>'.$mesgtoshow;
5276 print
'</div></div>';
5295 function print_liste_field_titre($name, $file =
"", $field =
"", $begin =
"", $moreparam =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $tooltip =
"", $forcenowrapcolumntitle = 0)
5297 print
getTitleFieldOfList($name, 0, $file, $field, $begin, $moreparam, $moreattrib, $sortfield, $sortorder, $prefix, 0, $tooltip, $forcenowrapcolumntitle);
5318 function getTitleFieldOfList($name, $thead = 0, $file =
"", $field =
"", $begin =
"", $moreparam =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $disablesortlink = 0, $tooltip =
'', $forcenowrapcolumntitle = 0)
5320 global $conf, $langs,
$form;
5323 if ($moreattrib ==
'class="right"') {
5324 $prefix .=
'right ';
5327 $sortorder = strtoupper($sortorder);
5336 $tmpsortfield = explode(
',', $sortfield);
5337 $sortfield1 = trim($tmpsortfield[0]);
5338 $tmpfield = explode(
',', $field);
5339 $field1 = trim($tmpfield[0]);
5341 if (empty($conf->global->MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE) && empty($forcenowrapcolumntitle)) {
5342 $prefix =
'wrapcolumntitle '.$prefix;
5348 $liste_titre =
'liste_titre';
5349 if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace(
"/^[^\.]+\./",
"", $field1))) {
5350 $liste_titre =
'liste_titre_sel';
5353 $tagstart =
'<'.$tag.
' class="'.$prefix.$liste_titre.
'" '.$moreattrib;
5355 $tagstart .= ($name && empty($conf->global->MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE) && empty($forcenowrapcolumntitle) && !
dol_textishtml($name)) ?
' title="'.
dol_escape_htmltag($langs->trans($name)).
'"' :
'';
5358 if (empty($thead) && $field && empty($disablesortlink)) {
5359 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
5360 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
5361 $options = preg_replace(
'/&+/i',
'&', $options);
5362 if (!preg_match(
'/^&/', $options)) {
5363 $options =
'&'.$options;
5366 $sortordertouseinlink =
'';
5367 if ($field1 != $sortfield1) {
5368 if (preg_match(
'/^DESC/i', $sortorder)) {
5369 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
5371 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
5374 if (preg_match(
'/^ASC/i', $sortorder)) {
5375 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
5377 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
5380 $sortordertouseinlink = preg_replace(
'/,$/',
'', $sortordertouseinlink);
5381 $out .=
'<a class="reposition" href="'.$file.
'?sortfield='.$field.
'&sortorder='.$sortordertouseinlink.
'&begin='.$begin.$options.
'"';
5387 if (preg_match(
'/:\w+$/', $tooltip)) {
5388 $tmptooltip = explode(
':', $tooltip);
5390 $tmptooltip = array($tooltip);
5392 $out .=
$form->textwithpicto($langs->trans($name), $langs->trans($tmptooltip[0]), 1,
'help',
'', 0, 3, (empty($tmptooltip[1]) ?
'' :
'extra_'.str_replace(
'.',
'_', $field).
'_'.$tmptooltip[1]));
5394 $out .= $langs->trans($name);
5397 if (empty($thead) && $field && empty($disablesortlink)) {
5401 if (empty($thead) && $field) {
5402 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
5403 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
5404 $options = preg_replace(
'/&+/i',
'&', $options);
5405 if (!preg_match(
'/^&/', $options)) {
5406 $options =
'&'.$options;
5409 if (!$sortorder || ($field1 != $sortfield1)) {
5413 if (preg_match(
'/^DESC/', $sortorder)) {
5416 $sortimg .=
'<span class="nowrap">'.img_up(
"Z-A", 0,
'paddingright').
'</span>';
5418 if (preg_match(
'/^ASC/', $sortorder)) {
5421 $sortimg .=
'<span class="nowrap">'.img_down(
"A-Z", 0,
'paddingright').
'</span>';
5426 $tagend =
'</'.$tag.
'>';
5428 $out = $tagstart.$sortimg.$out.$tagend;
5443 dol_syslog(__FUNCTION__.
" is deprecated", LOG_WARNING);
5445 print
'<div class="titre">'.$title.
'</div>';
5477 function load_fiche_titre($titre, $morehtmlright =
'', $picto =
'generic', $pictoisfullpath = 0, $id =
'', $morecssontable =
'', $morehtmlcenter =
'')
5483 if ($picto ==
'setup') {
5488 $return .=
'<table '.($id ?
'id="'.$id.
'" ' :
'').
'class="centpercent notopnoleftnoright table-fiche-title'.($morecssontable ?
' '.$morecssontable :
'').
'">';
5489 $return .=
'<tr class="titre">';
5491 $return .=
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">'.img_picto(
'', $picto,
'class="valignmiddle widthpictotitle pictotitle"', $pictoisfullpath).
'</td>';
5493 $return .=
'<td class="nobordernopadding valignmiddle col-title">';
5494 $return .=
'<div class="titre inline-block">'.$titre.
'</div>';
5497 $return .=
'<td class="nobordernopadding center valignmiddle col-center">'.$morehtmlcenter.
'</td>';
5500 $return .=
'<td class="nobordernopadding titre_right wordbreakimp right valignmiddle col-right">'.$morehtmlright.
'</td>';
5502 $return .=
'</tr></table>'.
"\n";
5530 function 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 =
'')
5532 global $conf, $langs;
5535 $savtotalnboflines = $totalnboflines;
5536 $totalnboflines = abs((
int) $totalnboflines);
5538 $page = (int) $page;
5540 if ($picto ==
'setup') {
5541 $picto =
'title_setup.png';
5543 if (($conf->browser->name ==
'ie') && $picto ==
'generic') {
5544 $picto =
'title.gif';
5547 $limit = $conf->liste_limit;
5550 if ($savlimit != 0 && (($num > $limit) || ($num == -1) || ($limit == 0))) {
5558 print
"<!-- Begin title -->\n";
5559 print
'<table class="centpercent notopnoleftnoright table-fiche-title'.($morecss ?
' '.$morecss :
'').
'"><tr>';
5563 if ($picto && $titre) {
5564 print
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">'.img_picto(
'', $picto,
'class="valignmiddle pictotitle widthpictotitle"', $pictoisfullpath).
'</td>';
5567 print
'<td class="nobordernopadding valignmiddle col-title">';
5568 print
'<div class="titre inline-block">'.$titre;
5569 if (!empty($titre) && $savtotalnboflines >= 0 && (string) $savtotalnboflines !=
'') {
5570 print
'<span class="opacitymedium colorblack paddingleft">('.$totalnboflines.
')</span>';
5572 print
'</div></td>';
5575 if ($morehtmlcenter && empty($conf->dol_optimize_smallscreen)) {
5576 print
'<td class="nobordernopadding center valignmiddle col-center">'.$morehtmlcenter.
'</td>';
5580 print
'<td class="nobordernopadding valignmiddle right col-right">';
5581 print
'<input type="hidden" name="pageplusoneold" value="'.((int) $page + 1).
'">';
5583 $options .=
"&sortfield=".urlencode($sortfield);
5586 $options .=
"&sortorder=".urlencode($sortorder);
5590 if ($savlimit != 0 && ($page > 0 || $num > $limit)) {
5591 if ($totalnboflines) {
5593 $maxnbofpage = (empty($conf->dol_optimize_smallscreen) ? 4 : 0);
5596 $nbpages = ceil($totalnboflines / $limit);
5600 $cpt = ($page - $maxnbofpage);
5606 if (empty($pagenavastextinput)) {
5607 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page=0'.$options.
'">1</a></li>';
5609 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
5610 } elseif ($cpt == 2) {
5611 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page=1'.$options.
'">2</a></li>';
5617 if ($pagenavastextinput) {
5618 if ($cpt == $page) {
5619 $pagelist .=
'<li class="pagination"><input type="text" class="'.($totalnboflines > 100 ?
'width40' :
'width25').
' center pageplusone" name="pageplusone" value="'.($page + 1).
'"></li>';
5623 if ($cpt == $page) {
5624 $pagelist .=
'<li class="pagination"><span class="active">'.($page + 1).
'</span></li>';
5626 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page='.$cpt.$options.
'">'.($cpt + 1).
'</a></li>';
5630 }
while ($cpt < $nbpages && $cpt <= ($page + $maxnbofpage));
5632 if (empty($pagenavastextinput)) {
5633 if ($cpt < $nbpages) {
5634 if ($cpt < $nbpages - 2) {
5635 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
5636 } elseif ($cpt == $nbpages - 2) {
5637 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page='.($nbpages - 2).$options.
'">'.($nbpages - 1).
'</a></li>';
5639 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page='.($nbpages - 1).$options.
'">'.$nbpages.
'</a></li>';
5643 $pagelist .=
'<li class="pagination paginationlastpage"><a href="'.$file.
'?page='.($nbpages - 1).$options.
'">'.$nbpages.
'</a></li>';
5646 $pagelist .=
'<li class="pagination"><span class="active">'.($page + 1).
"</li>";
5650 if ($savlimit || $morehtmlright || $morehtmlrightbeforearrow) {
5651 print_fleche_navigation($page, $file, $options, $nextpage, $pagelist, $morehtmlright, $savlimit, $totalnboflines, $hideselectlimit, $morehtmlrightbeforearrow, $hidenavigation);
5655 if ($pagenavastextinput) {
5662 print
'</table>'.
"\n";
5665 if ($morehtmlcenter && !empty($conf->dol_optimize_smallscreen)) {
5666 print
'<div class="nobordernopadding marginbottomonly center valignmiddle col-center centpercent">'.$morehtmlcenter.
'</div>';
5669 print
"<!-- End title -->\n\n";
5688 function print_fleche_navigation($page, $file, $options =
'', $nextpage = 0, $betweenarrows =
'', $afterarrows =
'', $limit = -1, $totalnboflines = 0, $hideselectlimit = 0, $beforearrows =
'', $hidenavigation = 0)
5690 global $conf, $langs;
5692 print
'<div class="pagination"><ul>';
5693 if ($beforearrows) {
5694 print
'<li class="paginationbeforearrows">';
5695 print $beforearrows;
5699 if (empty($hidenavigation)) {
5700 if ((
int) $limit > 0 && empty($hideselectlimit)) {
5701 $pagesizechoices =
'10:10,15:15,20:20,30:30,40:40,50:50,100:100,250:250,500:500,1000:1000';
5702 $pagesizechoices .=
',5000:5000,10000:10000,20000:20000';
5705 if (!empty($conf->global->MAIN_PAGESIZE_CHOICES)) {
5706 $pagesizechoices = $conf->global->MAIN_PAGESIZE_CHOICES;
5709 print
'<li class="pagination">';
5710 print
'<select class="flat selectlimit" name="limit" title="'.dol_escape_htmltag($langs->trans(
"MaxNbOfRecordPerPage")).
'">';
5711 $tmpchoice = explode(
',', $pagesizechoices);
5712 $tmpkey = $limit.
':'.$limit;
5713 if (!in_array($tmpkey, $tmpchoice)) {
5714 $tmpchoice[] = $tmpkey;
5716 $tmpkey = $conf->liste_limit.
':'.$conf->liste_limit;
5717 if (!in_array($tmpkey, $tmpchoice)) {
5718 $tmpchoice[] = $tmpkey;
5720 asort($tmpchoice, SORT_NUMERIC);
5721 foreach ($tmpchoice as $val) {
5723 $tmp = explode(
':', $val);
5726 if ($key !=
'' && $val !=
'') {
5727 if ((
int) $key == (
int) $limit) {
5728 $selected =
' selected="selected"';
5730 print
'<option name="'.$key.
'"'.$selected.
'>'.
dol_escape_htmltag($val).
'</option>'.
"\n";
5734 if ($conf->use_javascript_ajax) {
5735 print
'<!-- JS CODE TO ENABLE select limit to launch submit of page -->
5737 jQuery(document).ready(function () {
5738 jQuery(".selectlimit").change(function() {
5739 console.log("Change limit. Send submit");
5740 $(this).parents(\'form:first\').submit();
5749 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>';
5751 if ($betweenarrows) {
5752 print
'<!--<div class="betweenarrows nowraponall inline-block">-->';
5753 print $betweenarrows;
5754 print
'<!--</div>-->';
5756 if ($nextpage > 0) {
5757 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>';
5760 print
'<li class="paginationafterarrows">';
5765 print
'</ul></div>'.
"\n";
5780 function vatrate($rate, $addpercent =
false, $info_bits = 0, $usestarfornpr = 0, $html = 0)
5784 if (preg_match(
'/%/', $rate)) {
5785 $rate = str_replace(
'%',
'', $rate);
5789 if (preg_match(
'/\((.*)\)/', $rate, $reg)) {
5790 $morelabel =
' ('.$reg[1].
')';
5791 $rate = preg_replace(
'/\s*'.preg_quote($morelabel,
'/').
'/',
'', $rate);
5792 $morelabel =
' '.($html ?
'<span class="opacitymedium">' :
'').
'('.$reg[1].
')'.($html ?
'</span>' :
'');
5794 if (preg_match(
'/\*/', $rate)) {
5795 $rate = str_replace(
'*',
'', $rate);
5800 if (!preg_match(
'/\//', $rate)) {
5801 $ret =
price($rate, 0,
'', 0, 0).($addpercent ?
'%' :
'');
5804 $ret = $rate.($addpercent ?
'%' :
'');
5806 if (($info_bits & 1) && $usestarfornpr >= 0) {
5829 function price($amount,
$form = 0, $outlangs =
'', $trunc = 1, $rounding = -1, $forcerounding = -1, $currency_code =
'')
5831 global $langs, $conf;
5834 if (empty($amount)) {
5837 $amount = (is_numeric($amount) ? $amount : 0);
5838 if ($rounding == -1) {
5839 $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
5841 $nbdecimal = $rounding;
5843 if ($outlangs ===
'none') {
5853 if (!is_object($outlangs)) {
5857 if ($outlangs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
5858 $dec = $outlangs->transnoentitiesnoconv(
"SeparatorDecimal");
5860 if ($outlangs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
5861 $thousand = $outlangs->transnoentitiesnoconv(
"SeparatorThousand");
5863 if ($thousand ==
'None') {
5865 } elseif ($thousand ==
'Space') {
5872 $amount = str_replace(
',',
'.', $amount);
5874 $datas = explode(
'.', $amount);
5875 $decpart = isset($datas[1]) ? $datas[1] :
'';
5876 $decpart = preg_replace(
'/0+$/i',
'', $decpart);
5885 if ($trunc && $nbdecimal > $conf->global->MAIN_MAX_DECIMALS_SHOWN) {
5886 $nbdecimal = $conf->global->MAIN_MAX_DECIMALS_SHOWN;
5887 if (preg_match(
'/\.\.\./i', $conf->global->MAIN_MAX_DECIMALS_SHOWN)) {
5894 if ((
string) $forcerounding !=
'-1') {
5895 if ($forcerounding ===
'MU') {
5896 $nbdecimal = $conf->global->MAIN_MAX_DECIMALS_UNIT;
5897 } elseif ($forcerounding ===
'MT') {
5898 $nbdecimal = $conf->global->MAIN_MAX_DECIMALS_TOT;
5899 } elseif ($forcerounding >= 0) {
5900 $nbdecimal = $forcerounding;
5905 $output = number_format($amount, $nbdecimal, $dec, $thousand);
5907 $output = preg_replace(
'/\s/',
' ', $output);
5908 $output = preg_replace(
'/\'/',
''', $output);
5911 $cursymbolbefore = $cursymbolafter =
'';
5912 if ($currency_code && is_object($outlangs)) {
5913 if ($currency_code ==
'auto') {
5914 $currency_code = $conf->currency;
5917 $listofcurrenciesbefore = array(
'AUD',
'CAD',
'CNY',
'COP',
'CLP',
'GBP',
'HKD',
'MXN',
'PEN',
'USD',
'CRC');
5918 $listoflanguagesbefore = array(
'nl_NL');
5919 if (in_array($currency_code, $listofcurrenciesbefore) || in_array($outlangs->defaultlang, $listoflanguagesbefore)) {
5920 $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
5922 $tmpcur = $outlangs->getCurrencySymbol($currency_code);
5923 $cursymbolafter .= ($tmpcur == $currency_code ?
' '.$tmpcur : $tmpcur);
5926 $output = $cursymbolbefore.$output.$end.($cursymbolafter ?
' ' :
'').$cursymbolafter;
5957 global $langs, $conf;
5960 if (is_null($amount)) {
5969 if (is_null($langs)) {
5973 if ($langs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
5974 $dec = $langs->transnoentitiesnoconv(
"SeparatorDecimal");
5976 if ($langs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
5977 $thousand = $langs->transnoentitiesnoconv(
"SeparatorThousand");
5980 if ($thousand ==
'None') {
5982 } elseif ($thousand ==
'Space') {
5990 if (!is_numeric($amount)) {
5991 $amount = preg_replace(
'/[a-zA-Z\/\\\*\(\)<>\_]/',
'', $amount);
5994 if ($option == 2 && $thousand ==
'.' && preg_match(
'/\.(\d\d\d)$/', (
string) $amount)) {
5995 $amount = str_replace($thousand,
'', $amount);
6001 if (is_numeric($amount)) {
6003 $temps = sprintf(
"%0.10F", $amount - intval($amount));
6004 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
6006 $amount = number_format($amount, $nbofdec, $dec, $thousand);
6011 if ($thousand !=
',' && $thousand !=
'.') {
6012 $amount = str_replace(
',',
'.', $amount);
6015 $amount = str_replace(
' ',
'', $amount);
6016 $amount = str_replace($thousand,
'', $amount);
6017 $amount = str_replace($dec,
'.', $amount);
6019 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
6025 $nbofdectoround =
'';
6026 if ($rounding ==
'MU') {
6027 $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_UNIT;
6028 } elseif ($rounding ==
'MT') {
6029 $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_TOT;
6030 } elseif ($rounding ==
'MS') {
6031 $nbofdectoround = isset($conf->global->MAIN_MAX_DECIMALS_STOCK) ? $conf->global->MAIN_MAX_DECIMALS_STOCK : 5;
6032 } elseif ($rounding ==
'CU') {
6033 $nbofdectoround = max($conf->global->MAIN_MAX_DECIMALS_UNIT, 8);
6034 } elseif ($rounding ==
'CT') {
6035 $nbofdectoround = max($conf->global->MAIN_MAX_DECIMALS_TOT, 8);
6036 } elseif (is_numeric($rounding)) {
6037 $nbofdectoround = (int) $rounding;
6042 $amount = round(is_string($amount) ? (
float) $amount : $amount, $nbofdectoround);
6044 return 'ErrorBadParameterProvidedToFunction';
6050 if (is_numeric($amount)) {
6052 $temps = sprintf(
"%0.10F", $amount - intval($amount));
6053 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
6055 $amount = number_format($amount, min($nbofdec, $nbofdectoround), $dec, $thousand);
6061 if ($thousand !=
',' && $thousand !=
'.') {
6062 $amount = str_replace(
',',
'.', $amount);
6065 $amount = str_replace(
' ',
'', $amount);
6066 $amount = str_replace($thousand,
'', $amount);
6067 $amount = str_replace($dec,
'.', $amount);
6069 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
6087 function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round = -1, $forceunitoutput =
'no', $use_short_label = 0)
6089 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
6091 if (($forceunitoutput ==
'no' && $dimension < 1 / 10000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -6)) {
6092 $dimension = $dimension * 1000000;
6094 } elseif (($forceunitoutput ==
'no' && $dimension < 1 / 10 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -3)) {
6095 $dimension = $dimension * 1000;
6097 } elseif (($forceunitoutput ==
'no' && $dimension > 100000000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 6)) {
6098 $dimension = $dimension / 1000000;
6100 } elseif (($forceunitoutput ==
'no' && $dimension > 100000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 3)) {
6101 $dimension = $dimension / 1000;
6117 $ret =
price($dimension, 0, $outputlangs, 0, 0, $round);
6118 $ret .=
' '.measuringUnitString(0, $type, $unit, $use_short_label, $outputlangs);
6136 function get_localtax($vatrate, $local, $thirdparty_buyer =
"", $thirdparty_seller =
"", $vatnpr = 0)
6138 global $db, $conf, $mysoc;
6140 if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) {
6141 $thirdparty_seller = $mysoc;
6144 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);
6146 $vatratecleaned = $vatrate;
6148 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
6149 $vatratecleaned = trim($reg[1]);
6150 $vatratecode = $reg[2];
6159 if ($mysoc->country_code ==
'ES') {
6161 if (!$mysoc->localtax1_assuj || (
string) $vatratecleaned ==
"0") {
6164 if ($thirdparty_seller->id == $mysoc->id) {
6165 if (!$thirdparty_buyer->localtax1_assuj) {
6169 if (!$thirdparty_seller->localtax1_assuj) {
6177 if (!$mysoc->localtax2_assuj) {
6180 if ($thirdparty_seller->id == $mysoc->id) {
6181 if (!$thirdparty_buyer->localtax2_assuj) {
6185 if (!$thirdparty_seller->localtax2_assuj) {
6191 if ($local == 1 && !$thirdparty_seller->localtax1_assuj) {
6194 if ($local == 2 && !$thirdparty_seller->localtax2_assuj) {
6200 if (in_array($mysoc->country_code, array(
'ES'))) {
6201 $conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY = 1;
6205 if (!empty($conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY)) {
6207 if ($thirdparty_seller != $mysoc) {
6209 return $thirdparty_seller->localtax1_value;
6213 return $conf->global->MAIN_INFO_VALUE_LOCALTAX1;
6218 if ($thirdparty_seller != $mysoc) {
6221 return $thirdparty_seller->localtax2_value;
6224 if (in_array($mysoc->country_code, array(
'ES'))) {
6225 return $thirdparty_buyer->localtax2_value;
6227 return $conf->global->MAIN_INFO_VALUE_LOCALTAX2;
6234 $sql =
"SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
6235 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
6236 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($thirdparty_seller->country_code).
"'";
6237 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
6238 if (!empty($vatratecode)) {
6239 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
6241 $sql .=
" AND t.recuperableonly = '".$db->escape($vatnpr).
"'";
6244 $resql = $db->query(
$sql);
6247 $obj = $db->fetch_object($resql);
6250 return $obj->localtax1;
6251 } elseif ($local == 2) {
6252 return $obj->localtax2;
6273 $valors = explode(
":", $tax);
6275 if (count($valors) > 1) {
6292 $sql =
" SELECT t.localtax".$local.
" as localtax";
6293 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t INNER JOIN ".MAIN_DB_PREFIX.
"c_country as c ON c.rowid = t.fk_pays";
6294 $sql .=
" WHERE c.code = '".$db->escape($mysoc->country_code).
"' AND t.active = 1 AND t.taux = (";
6295 $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";
6296 $sql .=
" WHERE c.code = '".$db->escape($mysoc->country_code).
"' AND tt.active = 1)";
6297 $sql .=
" AND t.localtax".$local.
"_type <> '0'";
6298 $sql .=
" ORDER BY t.rowid DESC";
6300 $resql = $db->query(
$sql);
6302 $obj = $db->fetch_object($resql);
6304 return $obj->localtax;
6325 function getTaxesFromId($vatrate, $buyer =
null, $seller =
null, $firstparamisid = 1)
6329 dol_syslog(
"getTaxesFromId vat id or rate = ".$vatrate);
6332 $sql =
"SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy,";
6333 $sql .=
" t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type";
6334 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t";
6335 if ($firstparamisid) {
6336 $sql .=
" WHERE t.rowid = ".(int) $vatrate;
6338 $vatratecleaned = $vatrate;
6341 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
6342 $vatratecleaned = $reg[1];
6343 $vatratecode = $reg[2];
6346 $sql .=
", ".MAIN_DB_PREFIX.
"c_country as c";
6349 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($seller->country_code).
"'";
6350 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
6352 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
6356 $resql = $db->query(
$sql);
6358 $obj = $db->fetch_object($resql);
6361 'rowid'=>$obj->rowid,
6364 'localtax1'=>$obj->localtax1,
6365 'localtax1_type'=>$obj->localtax1_type,
6366 'localtax2'=>$obj->localtax2,
6367 'localtax2_type'=>$obj->localtax2_type,
6369 'accountancy_code_sell'=>$obj->accountancy_code_sell,
6370 'accountancy_code_buy'=>$obj->accountancy_code_buy
6402 dol_syslog(
"getLocalTaxesFromRate vatrate=".$vatrate.
" local=".$local);
6405 $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";
6406 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t";
6407 if ($firstparamisid) {
6408 $sql .=
" WHERE t.rowid = ".(int) $vatrate;
6410 $vatratecleaned = $vatrate;
6413 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
6414 $vatratecleaned = $reg[1];
6415 $vatratecode = $reg[2];
6418 $sql .=
", ".MAIN_DB_PREFIX.
"c_country as c";
6419 if (!empty($mysoc) && $mysoc->country_code ==
'ES') {
6420 $countrycodetouse = ((empty($buyer) || empty($buyer->country_code)) ? $mysoc->country_code : $buyer->country_code);
6421 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($countrycodetouse).
"'";
6423 $countrycodetouse = ((empty($seller) || empty($seller->country_code)) ? $mysoc->country_code : $seller->country_code);
6424 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($countrycodetouse).
"'";
6426 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
6428 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
6432 $resql = $db->query(
$sql);
6434 $obj = $db->fetch_object($resql);
6437 $vateratestring = $obj->rate.($obj->code ?
' ('.$obj->code.
')' :
'');
6440 return array($obj->localtax1_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
6441 } elseif ($local == 2) {
6442 return array($obj->localtax2_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
6444 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);
6464 global $db, $conf, $mysoc;
6466 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
6474 $product->fetch($idprod);
6476 if ($mysoc->country_code == $thirdpartytouse->country_code) {
6478 if ($idprodfournprice > 0) {
6479 $result = $product->get_buyprice($idprodfournprice, 0, 0, 0);
6481 $ret = $product->vatrate_supplier;
6482 if ($product->default_vat_code_supplier) {
6483 $ret .=
' ('.$product->default_vat_code_supplier.
')';
6489 $ret = $product->tva_tx;
6490 if ($product->default_vat_code) {
6491 $ret .=
' ('.$product->default_vat_code.
')';
6502 if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS)) {
6504 $sql =
"SELECT t.taux as vat_rate, t.code as default_vat_code";
6505 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
6506 $sql .=
" WHERE t.active = 1 AND t.fk_pays = c.rowid AND c.code = '".$db->escape($thirdpartytouse->country_code).
"'";
6507 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
6508 $sql .= $db->plimit(1);
6510 $resql = $db->query(
$sql);
6512 $obj = $db->fetch_object($resql);
6514 $ret = $obj->vat_rate;
6515 if ($obj->default_vat_code) {
6516 $ret .=
' ('.$obj->default_vat_code.
')';
6528 if ($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS !=
'none') {
6529 $defaulttx = $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;
6540 dol_syslog(
"get_product_vat_for_country: ret=".$ret);
6557 if (!class_exists(
'Product')) {
6558 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
6567 $result = $product->fetch($idprod);
6569 if ($mysoc->country_code == $thirdpartytouse->country_code) {
6583 $sql =
"SELECT taux as vat_rate, localtax1, localtax2";
6584 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
6585 $sql .=
" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$db->escape($thirdpartytouse->country_code).
"'";
6586 $sql .=
" ORDER BY t.taux DESC, t.recuperableonly ASC";
6587 $sql .= $db->plimit(1);
6589 $resql = $db->query(
$sql);
6591 $obj = $db->fetch_object($resql);
6594 $ret = $obj->localtax1;
6595 } elseif ($local == 2) {
6596 $ret = $obj->localtax2;
6604 dol_syslog(
"get_product_localtax_for_country: ret=".$ret);
6628 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
6631 $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;
6633 $seller_country_code = $thirdparty_seller->country_code;
6634 $seller_in_cee =
isInEEC($thirdparty_seller);
6636 $buyer_country_code = $thirdparty_buyer->country_code;
6637 $buyer_in_cee =
isInEEC($thirdparty_buyer);
6639 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 :
''));
6643 if (!empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC)) {
6644 if ($seller_in_cee && $buyer_in_cee) {
6645 $isacompany = $thirdparty_buyer->
isACompany();
6646 if ($isacompany &&
getDolGlobalString(
'MAIN_USE_VAT_COMPANIES_IN_EEC_WITH_INVALID_VAT_ID_ARE_INDIVIDUAL')) {
6647 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
6661 if (!$seller_use_vat) {
6667 if (($seller_country_code == $buyer_country_code)
6668 || (in_array($seller_country_code, array(
'FR',
'MC')) && in_array($buyer_country_code, array(
'FR',
'MC')))) {
6672 if ($seller_country_code ==
'IN' &&
getDolGlobalString(
'MAIN_SALETAX_AUTOSWITCH_I_CS_FOR_INDIA')) {
6676 if (preg_match(
'/C+S-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id != $thirdparty_buyer->state_id) {
6678 $tmpvat = str_replace(
"C+S",
"I", $tmpvat);
6679 } elseif (preg_match(
'/I-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id == $thirdparty_buyer->state_id) {
6681 $tmpvat = str_replace(
"I",
"C+S", $tmpvat);
6693 if (($seller_in_cee && $buyer_in_cee)) {
6694 $isacompany = $thirdparty_buyer->
isACompany();
6695 if ($isacompany &&
getDolGlobalString(
'MAIN_USE_VAT_COMPANIES_IN_EEC_WITH_INVALID_VAT_ID_ARE_INDIVIDUAL')) {
6696 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
6713 if (!empty($conf->global->MAIN_USE_VAT_OF_PRODUCT_FOR_INDIVIDUAL_CUSTOMER_OUT_OF_EEC) && empty($buyer_in_cee)) {
6714 $isacompany = $thirdparty_buyer->
isACompany();
6742 if ($idprodfournprice > 0) {
6743 if (!class_exists(
'ProductFournisseur')) {
6744 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
6747 $prodprice->fetch_product_fournisseur_price($idprodfournprice);
6748 return $prodprice->fourn_tva_npr;
6749 } elseif ($idprod > 0) {
6750 if (!class_exists(
'Product')) {
6751 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
6754 $prod->fetch($idprod);
6755 return $prod->tva_npr;
6778 if (!is_object($thirdparty_seller)) {
6781 if (!is_object($thirdparty_buyer)) {
6786 if ($mysoc->country_code ==
'ES') {
6787 if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) {
6792 if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) {
6795 if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj ==
'localtax1off') {
6799 } elseif ($local == 2) {
6801 if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) {
6804 if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj ==
'localtax2off') {
6809 if ($thirdparty_seller->country_code == $thirdparty_buyer->country_code) {
6824 function yn($yesno, $case = 1, $color = 0)
6828 $result =
'unknown';
6830 if ($yesno == 1 || (isset($yesno) && (strtolower($yesno) ==
'yes' || strtolower($yesno) ==
'true'))) {
6831 $result = $langs->trans(
'yes');
6832 if ($case == 1 || $case == 3) {
6833 $result = $langs->trans(
"Yes");
6836 $result =
'<input type="checkbox" value="1" checked disabled>';
6839 $result =
'<input type="checkbox" value="1" checked disabled> '.$result;
6843 } elseif ($yesno == 0 || strtolower($yesno) ==
'no' || strtolower($yesno) ==
'false') {
6844 $result = $langs->trans(
"no");
6845 if ($case == 1 || $case == 3) {
6846 $result = $langs->trans(
"No");
6849 $result =
'<input type="checkbox" value="0" disabled>';
6852 $result =
'<input type="checkbox" value="0" disabled> '.$result;
6858 $classname =
'error';
6862 return '<span class="'.$classname.
'">'.$result.
'</span>';
6882 function get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart =
'')
6886 if (empty($modulepart) && !empty($object->module)) {
6887 $modulepart = $object->module;
6892 $arrayforoldpath = array(
'cheque',
'category',
'holiday',
'supplier_invoice',
'invoice_supplier',
'mailing',
'supplier_payment');
6894 $arrayforoldpath[] =
'product';
6896 if (!empty($level) && in_array($modulepart, $arrayforoldpath)) {
6898 if (empty($alpha)) {
6899 $num = preg_replace(
'/([^0-9])/i',
'', $num);
6901 $num = preg_replace(
'/^.*\-/i',
'', $num);
6903 $num = substr(
"000".$num, -$level);
6905 $path = substr($num, 0, 1);
6908 $path = substr($num, 1, 1).
'/'.substr($num, 0, 1);
6911 $path = substr($num, 2, 1).
'/'.substr($num, 1, 1).
'/'.substr($num, 0, 1);
6921 if (empty($withoutslash) && !empty($path)) {
6940 dol_syslog(
"functions.lib::dol_mkdir: dir=".$dir, LOG_INFO);
6943 if (@is_dir($dir_osencoded)) {
6951 if (!empty($dataroot)) {
6953 $dir = str_replace($dataroot.
'/',
'', $dir);
6954 $ccdir = $dataroot.
'/';
6957 $cdir = explode(
"/", $dir);
6958 $num = count($cdir);
6959 for ($i = 0; $i < $num; $i++) {
6961 $ccdir .=
'/'.$cdir[$i];
6963 $ccdir .= $cdir[$i];
6965 if (preg_match(
"/^.:$/", $ccdir, $regs)) {
6973 if (!@is_dir($ccdir_osencoded)) {
6974 dol_syslog(
"functions.lib::dol_mkdir: Directory '".$ccdir.
"' does not exists or is outside open_basedir PHP setting.", LOG_DEBUG);
6977 $dirmaskdec = octdec((
string) $newmask);
6978 if (empty($newmask)) {
6979 $dirmaskdec = empty($conf->global->MAIN_UMASK) ? octdec(
'0755') : octdec($conf->global->MAIN_UMASK);