45 include_once DOL_DOCUMENT_ROOT.
'/core/lib/json.lib.php';
48 if (!function_exists(
'utf8_encode')) {
55 function utf8_encode($elements)
57 return mb_convert_encoding($elements,
'UTF-8',
'ISO-8859-1');
61 if (!function_exists(
'utf8_decode')) {
68 function utf8_decode($elements)
70 return mb_convert_encoding($elements,
'ISO-8859-1',
'UTF-8');
85 if (!is_object($object) && empty($module)) {
88 if (empty($module) && !empty($object->element)) {
89 $module = $object->element;
91 return $conf->$module->multidir_output[(!empty($object->entity) ? $object->entity : $conf->entity)];
105 return (
string) (empty($conf->global->$key) ? $default : $conf->global->$key);
119 return (
int) (empty($conf->global->$key) ? $default : $conf->global->$key);
132 if (empty($tmpuser)) {
138 return (
string) (empty($tmpuser->conf->$key) ? $default : $tmpuser->conf->$key);
151 if (empty($tmpuser)) {
157 return (
int) (empty($tmpuser->conf->$key) ? $default : $tmpuser->conf->$key);
169 return !empty($conf->$module->enabled);
185 require_once DOL_DOCUMENT_ROOT.
"/core/db/".$type.
'.class.php';
187 $class =
'DoliDB'.ucfirst($type);
188 $dolidb =
new $class($type, $host, $user, $pass, $name, $port);
209 function getEntity($element, $shared = 1, $currentobject =
null)
211 global $conf, $mc, $hookmanager, $object, $action, $db;
213 if (!is_object($hookmanager)) {
214 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
221 $element =
'contract';
223 case 'order_supplier':
224 $element =
'supplier_order';
226 case 'invoice_supplier':
227 $element =
'supplier_invoice';
231 if (is_object($mc)) {
232 $out = $mc->getEntity($element, $shared, $currentobject);
235 $addzero = array(
'user',
'usergroup',
'c_email_templates',
'email_template',
'default_values');
236 if (in_array($element, $addzero)) {
239 $out .= ((int) $conf->entity);
244 'element' => $element,
247 'currentobject' => $currentobject,
250 $reshook = $hookmanager->executeHooks(
'hookGetEntity', $parameters, $currentobject, $action);
252 if (is_numeric($reshook)) {
253 if ($reshook == 0 && !empty($hookmanager->resPrint)) {
254 $out .=
','.$hookmanager->resPrint;
255 } elseif ($reshook == 1) {
256 $out = $hookmanager->resPrint;
273 if (is_object($mc) && method_exists($mc,
'setEntity')) {
274 return $mc->setEntity($currentobject);
276 return ((is_object($currentobject) && $currentobject->id > 0 && $currentobject->entity > 0) ? $currentobject->entity : $conf->entity);
288 return preg_match(
'/(_pass|password|_pw|_key|securekey|serverkey|secret\d?|p12key|exportkey|_PW_[a-z]+|token)$/i', $keyname);
300 for ($r =
""; $n >= 0; $n = intval($n / 26) - 1)
301 $r = chr($n % 26 + 0x41) . $r;
324 include_once DOL_DOCUMENT_ROOT.
'/includes/mobiledetect/mobiledetectlib/Mobile_Detect.php';
331 $user_agent = substr($user_agent, 0, 512);
333 $detectmobile =
new Mobile_Detect(
null, $user_agent);
334 $tablet = $detectmobile->isTablet();
336 if ($detectmobile->isMobile()) {
340 if ($detectmobile->is(
'AndroidOS')) {
341 $os = $phone =
'android';
342 } elseif ($detectmobile->is(
'BlackBerryOS')) {
343 $os = $phone =
'blackberry';
344 } elseif ($detectmobile->is(
'iOS')) {
347 } elseif ($detectmobile->is(
'PalmOS')) {
348 $os = $phone =
'palm';
349 } elseif ($detectmobile->is(
'SymbianOS')) {
351 } elseif ($detectmobile->is(
'webOS')) {
353 } elseif ($detectmobile->is(
'MaemoOS')) {
355 } elseif ($detectmobile->is(
'WindowsMobileOS') || $detectmobile->is(
'WindowsPhoneOS')) {
361 if (preg_match(
'/linux/i', $user_agent)) {
363 } elseif (preg_match(
'/macintosh/i', $user_agent)) {
365 } elseif (preg_match(
'/windows/i', $user_agent)) {
371 if (preg_match(
'/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
373 $version = empty($reg[2]) ?
'' : $reg[2];
374 } elseif (preg_match(
'/edge(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
376 $version = empty($reg[2]) ?
'' : $reg[2];
377 } elseif (preg_match(
'/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg)) {
379 $version = empty($reg[2]) ?
'' : $reg[2];
380 } elseif (preg_match(
'/chrome/i', $user_agent, $reg)) {
383 } elseif (preg_match(
'/iceweasel/i', $user_agent)) {
385 } elseif (preg_match(
'/epiphany/i', $user_agent)) {
387 } elseif (preg_match(
'/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
389 $version = empty($reg[2]) ?
'' : $reg[2];
390 } elseif (preg_match(
'/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
393 $version = empty($reg[2]) ?
'' : $reg[2];
394 } elseif (preg_match(
'/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
396 $version = end($reg);
397 } elseif (preg_match(
'/(Windows NT\s([0-9]+\.[0-9])).*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
400 $version = end($reg);
401 } elseif (preg_match(
'/l[iy]n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) {
404 $version = empty($reg[3]) ?
'' : $reg[3];
416 'browsername' => $name,
417 'browserversion' => $version,
432 global $conf, $user, $langs, $db;
433 $disconnectdone =
false;
435 if (is_object($db) && !empty($db->connected)) {
436 $depth = $db->transaction_opened;
437 $disconnectdone = $db->close();
439 dol_syslog(
"--- End access to ".$_SERVER[
"PHP_SELF"].(($disconnectdone && $depth) ?
' (Warn: db disconnection forced, transaction depth was '.$depth.
')' :
''), (($disconnectdone && $depth) ? LOG_WARNING : LOG_INFO));
455 $relativepathstring = $_SERVER[
"PHP_SELF"];
457 if (constant(
'DOL_URL_ROOT')) {
458 $relativepathstring = preg_replace(
'/^'.preg_quote(constant(
'DOL_URL_ROOT'),
'/').
'/',
'', $relativepathstring);
460 $relativepathstring = preg_replace(
'/^\//',
'', $relativepathstring);
461 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
467 if (!empty($_GET[
'restore_lastsearch_values'])) {
468 if (!empty($_SESSION[
'lastsearch_values_'.$relativepathstring])) {
469 $tmp = json_decode($_SESSION[
'lastsearch_values_'.$relativepathstring],
true);
470 if (is_array($tmp)) {
471 foreach ($tmp as $key => $val) {
472 if ($key == $paramname) {
480 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_'.$relativepathstring])) {
482 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_'.$relativepathstring])) {
484 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_'.$relativepathstring])) {
486 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_'.$relativepathstring])) {
490 $isset = (isset($_POST[$paramname]) || isset($_GET[$paramname]));
507 if (empty($method)) {
508 $val = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
509 } elseif ($method == 1) {
510 $val = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
511 } elseif ($method == 2) {
512 $val = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
513 } elseif ($method == 3) {
514 $val = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
516 $val =
'BadFirstParameterForGETPOST';
519 return is_array($val);
551 function GETPOST($paramname, $check =
'alphanohtml', $method = 0, $filter =
null, $options =
null, $noreplace = 0)
553 global $mysoc, $user, $conf;
555 if (empty($paramname)) {
556 return 'BadFirstParameterForGETPOST';
559 dol_syslog(
"Deprecated use of GETPOST, called with 1st param = ".$paramname.
" and 2nd param is '', when calling page ".$_SERVER[
"PHP_SELF"], LOG_WARNING);
564 if (empty($method)) {
565 $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
566 } elseif ($method == 1) {
567 $out = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
568 } elseif ($method == 2) {
569 $out = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
570 } elseif ($method == 3) {
571 $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
573 return 'BadThirdParameterForGETPOST';
576 if (empty($method) || $method == 3 || $method == 4) {
577 $relativepathstring = $_SERVER[
"PHP_SELF"];
579 if (constant(
'DOL_URL_ROOT')) {
580 $relativepathstring = preg_replace(
'/^'.preg_quote(constant(
'DOL_URL_ROOT'),
'/').
'/',
'', $relativepathstring);
582 $relativepathstring = preg_replace(
'/^\//',
'', $relativepathstring);
583 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
589 if (!empty($_GET[
'restore_lastsearch_values'])) {
590 if (!empty($_SESSION[
'lastsearch_values_'.$relativepathstring])) {
591 $tmp = json_decode($_SESSION[
'lastsearch_values_'.$relativepathstring],
true);
592 if (is_array($tmp)) {
593 foreach ($tmp as $key => $val) {
594 if ($key == $paramname) {
602 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_'.$relativepathstring])) {
603 $out = $_SESSION[
'lastsearch_contextpage_'.$relativepathstring];
604 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_'.$relativepathstring])) {
605 $out = $_SESSION[
'lastsearch_limit_'.$relativepathstring];
606 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_'.$relativepathstring])) {
607 $out = $_SESSION[
'lastsearch_page_'.$relativepathstring];
608 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_'.$relativepathstring])) {
609 $out = $_SESSION[
'lastsearch_mode_'.$relativepathstring];
611 } elseif (!isset($_GET[
'sortfield'])) {
614 if (!empty($_GET[
'action']) && $_GET[
'action'] ==
'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
617 if (is_object($object) && isset($object->fields[$paramname][
'default'])) {
618 $out = $object->fields[$paramname][
'default'];
621 if (!empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) {
622 if (!empty($_GET[
'action']) && (preg_match(
'/^create|^add_price|^make/', $_GET[
'action']) || preg_match(
'/^presend/', $_GET[
'action'])) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
624 if (!empty($user->default_values)) {
625 if (isset($user->default_values[$relativepathstring][
'createform'])) {
626 foreach ($user->default_values[$relativepathstring][
'createform'] as $defkey => $defval) {
628 if ($defkey !=
'_noquery_') {
629 $tmpqueryarraytohave = explode(
'&', $defkey);
632 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
633 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
646 if (isset($user->default_values[$relativepathstring][
'createform'][$defkey][$paramname])) {
647 $out = $user->default_values[$relativepathstring][
'createform'][$defkey][$paramname];
654 } elseif (!empty($paramname) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
656 if (!empty($user->default_values)) {
659 if ($paramname ==
'sortfield' || $paramname ==
'sortorder') {
661 if (isset($user->default_values[$relativepathstring][
'sortorder'])) {
663 foreach ($user->default_values[$relativepathstring][
'sortorder'] as $defkey => $defval) {
665 if ($defkey !=
'_noquery_') {
666 $tmpqueryarraytohave = explode(
'&', $defkey);
669 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
670 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
683 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
684 foreach ($user->default_values[$relativepathstring][
'sortorder'][$defkey] as $key => $val) {
688 if ($paramname ==
'sortfield') {
691 if ($paramname ==
'sortorder') {
699 } elseif (isset($user->default_values[$relativepathstring][
'filters'])) {
700 foreach ($user->default_values[$relativepathstring][
'filters'] as $defkey => $defval) {
701 if (!empty($_GET[
'disabledefaultvalues'])) {
705 if ($defkey !=
'_noquery_') {
706 $tmpqueryarraytohave = explode(
'&', $defkey);
709 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
710 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
724 if (isset($_POST[
'sall']) || isset($_POST[
'search_all']) || isset($_GET[
'sall']) || isset($_GET[
'search_all'])) {
726 if (empty($conf->global->MAIN_DISABLE_DEFAULT_FILTER_FOR_QUICK_SEARCH)) {
727 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
728 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
731 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
732 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
747 if (!is_array($out) && empty($_POST[$paramname]) && empty($noreplace)) {
751 while (preg_match(
'/__([A-Z0-9]+_?[A-Z0-9]+)__/i', $out, $reg) && ($loopnb < $maxloop)) {
755 if ($reg[1] ==
'DAY') {
757 $newout = $tmp[
'mday'];
758 } elseif ($reg[1] ==
'MONTH') {
760 $newout = $tmp[
'mon'];
761 } elseif ($reg[1] ==
'YEAR') {
763 $newout = $tmp[
'year'];
764 } elseif ($reg[1] ==
'PREVIOUS_DAY') {
767 $newout = $tmp2[
'day'];
768 } elseif ($reg[1] ==
'PREVIOUS_MONTH') {
771 $newout = $tmp2[
'month'];
772 } elseif ($reg[1] ==
'PREVIOUS_YEAR') {
774 $newout = ($tmp[
'year'] - 1);
775 } elseif ($reg[1] ==
'NEXT_DAY') {
778 $newout = $tmp2[
'day'];
779 } elseif ($reg[1] ==
'NEXT_MONTH') {
782 $newout = $tmp2[
'month'];
783 } elseif ($reg[1] ==
'NEXT_YEAR') {
785 $newout = ($tmp[
'year'] + 1);
786 } elseif ($reg[1] ==
'MYCOMPANY_COUNTRY_ID' || $reg[1] ==
'MYCOUNTRY_ID' || $reg[1] ==
'MYCOUNTRYID') {
787 $newout = $mysoc->country_id;
788 } elseif ($reg[1] ==
'USER_ID' || $reg[1] ==
'USERID') {
790 } elseif ($reg[1] ==
'USER_SUPERVISOR_ID' || $reg[1] ==
'SUPERVISOR_ID' || $reg[1] ==
'SUPERVISORID') {
791 $newout = $user->fk_user;
792 } elseif ($reg[1] ==
'ENTITY_ID' || $reg[1] ==
'ENTITYID') {
793 $newout = $conf->entity;
798 $out = preg_replace(
'/__'.preg_quote($reg[1],
'/').
'__/', $newout, $out);
803 if (preg_match(
'/^array/', $check)) {
804 if (!is_array($out) || empty($out)) {
807 $tmparray = explode(
':', $check);
808 if (!empty($tmparray[1])) {
809 $tmpcheck = $tmparray[1];
811 $tmpcheck =
'alphanohtml';
813 foreach ($out as $outkey => $outval) {
814 $out[$outkey] =
sanitizeVal($outval, $tmpcheck, $filter, $options);
820 if (strpos($paramname,
'search_') === 0) {
821 $out = preg_replace(
'/([<>])([-+]?\d)/',
'\1 \2', $out);
824 $out =
sanitizeVal($out, $check, $filter, $options);
829 if ($paramname ==
'backtopage' || $paramname ==
'backtolist' || $paramname ==
'backtourl') {
830 $out = str_replace(
'\\',
'/', $out);
831 $out = str_replace(array(
':',
';',
'@',
"\t",
' '),
'', $out);
833 $oldstringtoclean = $out;
834 $out = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $out);
835 $out = preg_replace(array(
'/^[^\?]*%/'),
'', $out);
836 $out = preg_replace(array(
'/^[a-z]*\/\s*\/+/i'),
'', $out);
837 }
while ($oldstringtoclean != $out);
842 if (empty($method) || $method == 3 || $method == 4) {
843 if (preg_match(
'/^search_/', $paramname) || in_array($paramname, array(
'sortorder',
'sortfield'))) {
850 if ($out !=
'' && isset($user)) {
851 $user->lastsearch_values_tmp[$relativepathstring][$paramname] = $out;
870 return (
int)
GETPOST($paramname,
'int', $method,
null,
null, 0);
884 function checkVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
886 return sanitizeVal($out, $check, $filter, $options);
898 function sanitizeVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
908 if (!is_numeric($out)) {
913 if (preg_match(
'/[^0-9,-]+/i', $out)) {
918 $out = filter_var($out, FILTER_SANITIZE_STRING);
921 $out = filter_var($out, FILTER_SANITIZE_EMAIL);
924 if (!is_array($out)) {
926 if (preg_match(
'/[^a-z]+/i', $out)) {
932 if (!is_array($out)) {
934 if (preg_match(
'/[^a-z0-9_\-\.]+/i', $out)) {
940 if (!is_array($out)) {
942 if (preg_match(
'/[^a-z0-9_\-\.@]+/i', $out)) {
948 if (!is_array($out)) {
950 if (preg_match(
'/[^a-z0-9_\-\.,]+/i', $out)) {
960 if (!is_array($out)) {
963 $oldstringtoclean = $out;
970 $out = str_ireplace(array(
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'\',
'\',
'/',
'../',
'..\\'),
'', $out);
971 }
while ($oldstringtoclean != $out);
976 if (!is_array($out)) {
979 $oldstringtoclean = $out;
985 $out = str_ireplace(array(
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'\',
'\',
'/',
'../',
'..\\'),
'', $out);
986 }
while ($oldstringtoclean != $out);
990 case 'restricthtmlnolink':
991 case 'restricthtmlallowunvalid':
996 if (empty($filter)) {
997 return 'BadParameterForGETPOST - Param 3 of sanitizeVal()';
1002 $out = filter_var($out, $filter, $options);
1011 if (!function_exists(
'dol_getprefix')) {
1021 function dol_getprefix($mode =
'')
1024 if ($mode ==
'email') {
1027 if (!empty($conf->global->MAIL_PREFIX_FOR_EMAIL_ID)) {
1028 if ($conf->global->MAIL_PREFIX_FOR_EMAIL_ID !=
'SERVER_NAME') {
1029 return $conf->global->MAIL_PREFIX_FOR_EMAIL_ID;
1030 } elseif (isset($_SERVER[
"SERVER_NAME"])) {
1031 return $_SERVER[
"SERVER_NAME"];
1036 if (!empty($conf->file->instance_unique_id)) {
1037 return sha1(
'dolibarr'.$conf->file->instance_unique_id);
1041 return sha1(DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1045 global $dolibarr_main_instance_unique_id, $dolibarr_main_cookie_cryptkey;
1046 $tmp_instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ?
'' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id;
1049 if (!empty($tmp_instance_unique_id)) {
1050 return sha1(
'dolibarr'.$tmp_instance_unique_id);
1054 if (isset($_SERVER[
"SERVER_NAME"]) && isset($_SERVER[
"DOCUMENT_ROOT"])) {
1055 return sha1($_SERVER[
"SERVER_NAME"].$_SERVER[
"DOCUMENT_ROOT"].DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1057 return sha1(DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1074 global $conf, $langs, $user, $mysoc;
1078 if (!file_exists($fullpath)) {
1079 dol_syslog(
'functions::dol_include_once Tried to load unexisting file: '.$relpath, LOG_WARNING);
1083 if (!empty($classname) && !class_exists($classname)) {
1084 return include $fullpath;
1086 return include_once $fullpath;
1105 $path = preg_replace(
'/^\//',
'', $path);
1108 $res = DOL_DOCUMENT_ROOT.
'/'.$path;
1109 if (is_array($conf->file->dol_document_root)) {
1110 foreach ($conf->file->dol_document_root as $key => $dirroot) {
1111 if ($key ==
'main') {
1114 if (file_exists($dirroot.
'/'.$path)) {
1115 $res = $dirroot.
'/'.$path;
1120 if ($returnemptyifnotfound) {
1122 if ($returnemptyifnotfound == 1 || !file_exists($res)) {
1134 $res = DOL_URL_ROOT.
'/'.$path;
1137 $res = DOL_MAIN_URL_ROOT.
'/'.$path;
1140 $res = DOL_URL_ROOT.
'/'.$path;
1143 foreach ($conf->file->dol_document_root as $key => $dirroot) {
1144 if ($key ==
'main') {
1146 global $dolibarr_main_url_root;
1149 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1150 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1153 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : $urlwithroot).
'/'.$path;
1158 preg_match(
'/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i', $path, $regs);
1159 if (!empty($regs[1])) {
1161 if (file_exists($dirroot.
'/'.$regs[1])) {
1163 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : DOL_URL_ROOT).$conf->file->dol_url_root[$key].
'/'.$path;
1166 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : DOL_MAIN_URL_ROOT).$conf->file->dol_url_root[$key].
'/'.$path;
1169 global $dolibarr_main_url_root;
1172 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1173 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1176 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : $urlwithroot).$conf->file->dol_url_root[$key].
'/'.$path;
1203 if (isset($object->db) && isset($object->db->db) && is_object($object->db->db) && get_class($object->db->db) ==
'PgSql\Connection') {
1204 $tmpsavdb = $object->db;
1208 $myclone = unserialize(serialize($object));
1210 if (!empty($tmpsavdb)) {
1211 $object->db = $tmpsavdb;
1213 } elseif ($native == 2) {
1215 $myclone =
new stdClass();
1216 $tmparray = get_object_vars($object);
1218 if (is_array($tmparray)) {
1219 foreach ($tmparray as $propertykey => $propertyval) {
1220 if (is_scalar($propertyval) || is_array($propertyval)) {
1221 $myclone->$propertykey = $propertyval;
1226 $myclone = clone $object;
1244 if (empty($conf->dol_optimize_smallscreen)) {
1247 if ($type ==
'width' && $size > 250) {
1272 $filesystem_forbidden_chars = array(
'<',
'>',
'/',
'\\',
'?',
'*',
'|',
'"',
':',
'°',
'$',
';');
1274 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
1275 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $tmp);
1276 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1277 $tmp = str_replace(
'..',
'', $tmp);
1297 $filesystem_forbidden_chars = array(
'<',
'>',
'?',
'*',
'|',
'"',
'°',
'$',
';');
1299 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
1300 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $tmp);
1301 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1302 $tmp = str_replace(
'..',
'', $tmp);
1317 $stringtoclean = preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $stringtoclean);
1319 $stringtoclean = preg_replace(
'/<!--[^>]*-->/',
'', $stringtoclean);
1321 $stringtoclean = str_replace(
'\\',
'/', $stringtoclean);
1325 $stringtoclean = str_replace(array(
':',
';',
'@'),
'', $stringtoclean);
1329 $oldstringtoclean = $stringtoclean;
1332 $stringtoclean = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $stringtoclean);
1333 }
while ($oldstringtoclean != $stringtoclean);
1337 $stringtoclean = preg_replace(array(
'/^[a-z]*\/\/+/i'),
'', $stringtoclean);
1340 return $stringtoclean;
1352 $oldstringtoclean = $stringtoclean;
1353 $stringtoclean = str_ireplace(array(
'"',
':',
'[',
']',
"\n",
"\r",
'\\',
'\/'),
'', $stringtoclean);
1354 }
while ($oldstringtoclean != $stringtoclean);
1356 return $stringtoclean;
1371 if (is_null($str)) {
1376 if (extension_loaded(
'intl') && !empty($conf->global->MAIN_UNACCENT_USE_TRANSLITERATOR)) {
1377 $transliterator = \Transliterator::createFromRules(
':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', \Transliterator::FORWARD);
1378 return $transliterator->transliterate($str);
1381 $string = rawurlencode($str);
1382 $replacements = array(
1383 '%C3%80' =>
'A',
'%C3%81' =>
'A',
'%C3%82' =>
'A',
'%C3%83' =>
'A',
'%C3%84' =>
'A',
'%C3%85' =>
'A',
1385 '%C3%88' =>
'E',
'%C3%89' =>
'E',
'%C3%8A' =>
'E',
'%C3%8B' =>
'E',
1386 '%C3%8C' =>
'I',
'%C3%8D' =>
'I',
'%C3%8E' =>
'I',
'%C3%8F' =>
'I',
1388 '%C3%92' =>
'O',
'%C3%93' =>
'O',
'%C3%94' =>
'O',
'%C3%95' =>
'O',
'%C3%96' =>
'O',
1390 '%C3%99' =>
'U',
'%C3%9A' =>
'U',
'%C3%9B' =>
'U',
'%C3%9C' =>
'U',
1391 '%C3%9D' =>
'Y',
'%C5%B8' =>
'y',
1392 '%C3%A0' =>
'a',
'%C3%A1' =>
'a',
'%C3%A2' =>
'a',
'%C3%A3' =>
'a',
'%C3%A4' =>
'a',
'%C3%A5' =>
'a',
1394 '%C3%A8' =>
'e',
'%C3%A9' =>
'e',
'%C3%AA' =>
'e',
'%C3%AB' =>
'e',
1395 '%C3%AC' =>
'i',
'%C3%AD' =>
'i',
'%C3%AE' =>
'i',
'%C3%AF' =>
'i',
1397 '%C3%B2' =>
'o',
'%C3%B3' =>
'o',
'%C3%B4' =>
'o',
'%C3%B5' =>
'o',
'%C3%B6' =>
'o',
1399 '%C3%B9' =>
'u',
'%C3%BA' =>
'u',
'%C3%BB' =>
'u',
'%C3%BC' =>
'u',
1400 '%C3%BD' =>
'y',
'%C3%BF' =>
'y'
1402 $string = strtr($string, $replacements);
1403 return rawurldecode($string);
1408 "\xC0\xC1\xC2\xC3\xC4\xC5\xC7
1409 \xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1
1410 \xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD
1411 \xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB
1412 \xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8
1413 \xF9\xFA\xFB\xFC\xFD\xFF",
1421 $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"));
1440 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
",",
";",
"=",
'°',
'$',
';');
1441 $forbidden_chars_to_remove = array();
1444 if (is_array($badcharstoreplace)) {
1445 $forbidden_chars_to_replace = $badcharstoreplace;
1447 if (is_array($badcharstoremove)) {
1448 $forbidden_chars_to_remove = $badcharstoremove;
1451 return str_replace($forbidden_chars_to_replace, $newstr, str_replace($forbidden_chars_to_remove,
"", $str));
1470 if ($removetabcrlf) {
1471 return preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $str);
1473 return preg_replace(
'/[\x00-\x08\x11-\x12\x14-\x1F\x7F]/u',
'', $str);
1487 if (is_null($stringtoescape)) {
1492 $substitjs = array(
"'"=>
"\\'",
"\r"=>
'\\r');
1494 if (empty($noescapebackslashn)) {
1495 $substitjs[
"\n"] =
'\\n';
1496 $substitjs[
'\\'] =
'\\\\';
1499 $substitjs[
"'"] =
"\\'";
1500 $substitjs[
'"'] =
"\\'";
1501 } elseif ($mode == 1) {
1502 $substitjs[
"'"] =
"\\'";
1503 } elseif ($mode == 2) {
1504 $substitjs[
'"'] =
'\\"';
1505 } elseif ($mode == 3) {
1506 $substitjs[
"'"] =
"\\'";
1507 $substitjs[
'"'] =
"\\\"";
1509 return strtr($stringtoescape, $substitjs);
1520 return str_replace(
'"',
'\"', $stringtoescape);
1534 function dol_escape_htmltag($stringtoescape, $keepb = 0, $keepn = 0, $noescapetags =
'', $escapeonlyhtmltags = 0)
1536 if ($noescapetags ==
'common') {
1537 $noescapetags =
'html,body,a,b,em,hr,i,u,ul,li,br,div,img,font,p,span,strong,table,tr,td,th,tbody';
1541 if ($escapeonlyhtmltags) {
1542 $tmp = htmlspecialchars_decode((
string) $stringtoescape, ENT_COMPAT);
1544 $tmp = html_entity_decode((
string) $stringtoescape, ENT_COMPAT,
'UTF-8');
1547 $tmp = strtr($tmp, array(
"<b>"=>
'',
'</b>'=>
''));
1550 $tmp = strtr($tmp, array(
"\r"=>
'\\r',
"\n"=>
'\\n'));
1553 if ($escapeonlyhtmltags) {
1554 return htmlspecialchars($tmp, ENT_COMPAT,
'UTF-8');
1558 $tmparrayoftags = array();
1559 if ($noescapetags) {
1560 $tmparrayoftags = explode(
',', $noescapetags);
1562 if (count($tmparrayoftags)) {
1563 foreach ($tmparrayoftags as $tagtoreplace) {
1564 $tmp = str_ireplace(
'<'.$tagtoreplace.
'>',
'__BEGINTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
1565 $tmp = str_ireplace(
'</'.$tagtoreplace.
'>',
'__ENDTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
1566 $tmp = str_ireplace(
'<'.$tagtoreplace.
' />',
'__BEGINENDTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
1570 $result = htmlentities($tmp, ENT_COMPAT,
'UTF-8');
1572 if (count($tmparrayoftags)) {
1573 foreach ($tmparrayoftags as $tagtoreplace) {
1574 $result = str_ireplace(
'__BEGINTAGTOREPLACE'.$tagtoreplace.
'__',
'<'.$tagtoreplace.
'>', $result);
1575 $result = str_ireplace(
'__ENDTAGTOREPLACE'.$tagtoreplace.
'__',
'</'.$tagtoreplace.
'>', $result);
1576 $result = str_ireplace(
'__BEGINENDTAGTOREPLACE'.$tagtoreplace.
'__',
'<'.$tagtoreplace.
' />', $result);
1593 if (function_exists(
'mb_strtolower')) {
1594 return mb_strtolower($string, $encoding);
1596 return strtolower($string);
1609 if (function_exists(
'mb_strtoupper')) {
1610 return mb_strtoupper($string, $encoding);
1612 return strtoupper($string);
1625 if (function_exists(
'mb_substr')) {
1626 return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding).mb_substr($string, 1,
null, $encoding);
1628 return ucfirst($string);
1641 if (function_exists(
'mb_convert_case')) {
1642 return mb_convert_case($string, MB_CASE_TITLE, $encoding);
1644 return ucwords($string);
1669 function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename =
'', $restricttologhandler =
'', $logcontext =
null)
1671 global $conf, $user, $debugbar;
1679 if (defined(
'USEEXTERNALSERVER') && !defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
1680 global $website, $websitekey;
1681 if (is_object($website) && !empty($website->ref)) {
1682 $suffixinfilename .=
'_website_'.$website->ref;
1683 } elseif (!empty($websitekey)) {
1684 $suffixinfilename .=
'_website_'.$websitekey;
1689 if (defined(
'USESUFFIXINLOG')) {
1690 $suffixinfilename .= constant(
'USESUFFIXINLOG');
1694 foreach ($conf->loghandlers as $loghandlerinstance) {
1695 $loghandlerinstance->setIdent($ident);
1699 if (!empty($message)) {
1701 $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');
1702 if (!array_key_exists($level, $logLevels)) {
1703 throw new Exception(
'Incorrect log level');
1709 if (empty($conf->global->MAIN_SHOW_PASSWORD_INTO_LOG)) {
1710 $message = preg_replace(
'/password=\'[^\']*\'/',
'password=\'hidden\'', $message);
1714 if ((!empty($_REQUEST[
'logtohtml']) && !empty($conf->global->MAIN_ENABLE_LOG_TO_HTML))
1715 || (!empty($user->rights->debugbar->read) && is_object($debugbar))) {
1716 $conf->logbuffer[] =
dol_print_date(time(),
"%Y-%m-%d %H:%M:%S").
" ".$logLevels[$level].
" ".$message;
1721 if (!empty($conf->global->MAIN_ENABLE_LOG_INLINE_HTML) && !empty($_GET[
"log"])) {
1722 print
"\n\n<!-- Log start\n";
1724 print
"Log end -->\n";
1728 'message' => $message,
1729 'script' => (isset($_SERVER[
'PHP_SELF']) ? basename($_SERVER[
'PHP_SELF'],
'.php') :
false),
1731 'user' => ((is_object($user) && $user->id) ? $user->login :
false),
1736 if (!empty($remoteip)) {
1737 $data[
'ip'] = $remoteip;
1739 if (!empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) && $_SERVER[
'HTTP_X_FORWARDED_FOR'] != $remoteip) {
1740 $data[
'ip'] = $_SERVER[
'HTTP_X_FORWARDED_FOR'].
' -> '.$data[
'ip'];
1741 } elseif (!empty($_SERVER[
'HTTP_CLIENT_IP']) && $_SERVER[
'HTTP_CLIENT_IP'] != $remoteip) {
1742 $data[
'ip'] = $_SERVER[
'HTTP_CLIENT_IP'].
' -> '.$data[
'ip'];
1744 } elseif (!empty($_SERVER[
'SERVER_ADDR'])) {
1746 $data[
'ip'] = $_SERVER[
'SERVER_ADDR'];
1747 } elseif (!empty($_SERVER[
'COMPUTERNAME'])) {
1749 $data[
'ip'] = $_SERVER[
'COMPUTERNAME'].(empty($_SERVER[
'USERNAME']) ?
'' :
'@'.$_SERVER[
'USERNAME']);
1750 } elseif (!empty($_SERVER[
'LOGNAME'])) {
1752 $data[
'ip'] =
'???@'.$_SERVER[
'LOGNAME'];
1756 foreach ($conf->loghandlers as $loghandlerinstance) {
1757 if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
1760 $loghandlerinstance->export($data, $suffixinfilename);
1766 foreach ($conf->loghandlers as $loghandlerinstance) {
1767 $loghandlerinstance->setIdent($ident);
1788 function dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled =
'', $morecss =
'classlink button bordertransp', $jsonopen =
'', $backtopagejsfields =
'', $accesskey =
'')
1792 if (strpos($url,
'?') > 0) {
1793 $url .=
'&dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup='.urlencode($name);
1795 $url .=
'?dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup='.urlencode($name);
1800 $backtopagejsfieldsid =
''; $backtopagejsfieldslabel =
'';
1801 if ($backtopagejsfields) {
1802 $tmpbacktopagejsfields = explode(
':', $backtopagejsfields);
1803 if (empty($tmpbacktopagejsfields[1])) {
1804 $backtopagejsfields = $name.
":".$backtopagejsfields;
1805 $tmp2backtopagejsfields = explode(
',', $tmpbacktopagejsfields[0]);
1807 $tmp2backtopagejsfields = explode(
',', $tmpbacktopagejsfields[1]);
1809 $backtopagejsfieldsid = empty($tmp2backtopagejsfields[0]) ?
'' : $tmp2backtopagejsfields[0];
1810 $backtopagejsfieldslabel = empty($tmp2backtopagejsfields[1]) ?
'' : $tmp2backtopagejsfields[1];
1811 $url .=
'&backtopagejsfields='.urlencode($backtopagejsfields);
1815 $out .=
'<!-- a link for button to open url into a dialog popup with backtopagejsfields = '.$backtopagejsfields.
' -->';
1816 $out .=
'<a '.($accesskey ?
' accesskey="'.$accesskey.
'"' :
'').
' class="cursorpointer button_'.$name.($morecss ?
' '.$morecss :
'').
'"'.$disabled.
' title="'.
dol_escape_htmltag($label).
'"';
1817 if (empty($conf->use_javascript_ajax)) {
1818 $out .=
' href="'.DOL_URL_ROOT.$url.
'" target="_blank"';
1819 } elseif ($jsonopen) {
1820 $out .=
' href="#" onclick="javascript:'.$jsonopen.
'"';
1822 $out .=
' href="#"';
1824 $out .=
'>'.$buttonstring.
'</a>';
1826 if (!empty($conf->use_javascript_ajax)) {
1828 $out .=
'<!-- code to open popup and variables to retreive returned variables -->';
1829 $out .=
'<div id="idfordialog'.$name.
'" class="hidden">div for dialog</div>';
1830 $out .=
'<div id="varforreturndialogid'.$name.
'" class="hidden">div for returned id</div>';
1831 $out .=
'<div id="varforreturndialoglabel'.$name.
'" class="hidden">div for returned label</div>';
1832 $out .=
'<!-- Add js code to open dialog popup on dialog -->';
1833 $out .=
'<script nonce="'.getNonce().
'" type="text/javascript">
1834 jQuery(document).ready(function () {
1835 jQuery(".button_'.$name.
'").click(function () {
1836 console.log(\'Open popup with jQuery(...).dialog() on URL '.
dol_escape_js(DOL_URL_ROOT.$url).
'\');
1837 var $tmpdialog = $(\
'#idfordialog'.$name.
'\');
1838 $tmpdialog.html(\
'<iframe class="iframedialog" id="iframedialog'.$name.
'" style="border: 0px;" src="'.DOL_URL_ROOT.$url.
'" width="100%" height="98%"></iframe>\');
1842 height: (window.innerHeight - 150),
1845 open:
function (event, ui) {
1846 console.log(
"open popup name='.$name.', backtopagejsfields='.$backtopagejsfields.'");
1848 close:
function (event, ui) {
1849 returnedid = jQuery(
"#varforreturndialogid'.$name.'").text();
1850 returnedlabel = jQuery(
"#varforreturndialoglabel'.$name.'").text();
1851 console.log(
"popup has been closed. returnedid (js var defined into parent page)="+returnedid+
" returnedlabel="+returnedlabel);
1852 if (returnedid !=
"" && returnedid !=
"div for returned id") {
1853 jQuery(
"#'.(empty($backtopagejsfieldsid)?"none
":$backtopagejsfieldsid).'").val(returnedid);
1855 if (returnedlabel !=
"" && returnedlabel !=
"div for returned label") {
1856 jQuery(
"#'.(empty($backtopagejsfieldslabel)?"none
":$backtopagejsfieldslabel).'").val(returnedlabel);
1861 $tmpdialog.dialog(\
'open\');
1885 function dol_fiche_head($links = array(), $active =
'0', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'')
1887 print
dol_get_fiche_head($links, $active, $title, $notab, $picto, $pictoisfullpath, $morehtmlright, $morecss, $limittoshow, $moretabssuffix);
1906 function dol_get_fiche_head($links = array(), $active =
'', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'', $dragdropfile = 0)
1908 global $conf, $langs, $hookmanager;
1912 if (!empty($conf->dol_optimize_smallscreen)) {
1916 $out =
"\n".
'<!-- dol_fiche_head - dol_get_fiche_head -->';
1918 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
1919 $out .=
'<div class="tabs'.($picto ?
'' :
' nopaddingleft').
'" data-role="controlgroup" data-type="horizontal">'.
"\n";
1923 if ($morehtmlright) {
1924 $out .=
'<div class="inline-block floatright tabsElem">'.$morehtmlright.
'</div>';
1928 if (!empty($title) && $showtitle && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1930 $out .=
'<a class="tabTitle">';
1932 $noprefix = $pictoisfullpath;
1933 if (strpos($picto,
'fontawesome_') !==
false) {
1936 $out .=
img_picto($title, ($noprefix ?
'' :
'object_').$picto,
'', $pictoisfullpath, 0, 0,
'',
'imgTabTitle').
' ';
1938 $out .=
'<span class="tabTitleText">'.dol_escape_htmltag(
dol_trunc($title, $limittitle)).
'</span>';
1946 if (is_array($links) && !empty($links)) {
1947 $keys = array_keys($links);
1949 $maxkey = max($keys);
1955 if (empty($limittoshow)) {
1956 $limittoshow = (empty($conf->global->MAIN_MAXTABS_IN_CARD) ? 99 : $conf->global->MAIN_MAXTABS_IN_CARD);
1958 if (!empty($conf->dol_optimize_smallscreen)) {
1966 for ($i = 0; $i <= $maxkey; $i++) {
1967 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
1969 if ($i >= $limittoshow) {
1975 for ($i = 0; $i <= $maxkey; $i++) {
1976 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
1982 if ($i < $limittoshow || $isactive) {
1984 $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])).
' -->';
1986 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
1987 if (!empty($links[$i][0])) {
1988 $out .=
'<a class="tabimage'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">'.$links[$i][1].
'</a>'.
"\n";
1990 $out .=
'<span class="tabspan">'.$links[$i][1].
'</span>'.
"\n";
1992 } elseif (!empty($links[$i][1])) {
1994 $out .=
'<div class="tab tab'.($isactive?
'active':
'unactive').
'" style="margin: 0 !important">';
1995 if (!empty($links[$i][0])) {
1996 $titletoshow = preg_replace(
'/<.*$/',
'', $links[$i][1]);
1997 $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).
'">';
1999 $out .= $links[$i][1];
2000 if (!empty($links[$i][0])) {
2001 $out .=
'</a>'.
"\n";
2003 $out .= empty($links[$i][4]) ?
'' : $links[$i][4];
2012 $outmore .=
'<div class="popuptabset wordwrap">';
2014 $outmore .=
'<div class="popuptab wordwrap" style="display:inherit;">';
2015 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
2016 if (!empty($links[$i][0])) {
2017 $outmore .=
'<a class="tabimage'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">'.$links[$i][1].
'</a>'.
"\n";
2019 $outmore .=
'<span class="tabspan">'.$links[$i][1].
'</span>'.
"\n";
2021 } elseif (!empty($links[$i][1])) {
2022 $outmore .=
'<a'.(!empty($links[$i][2]) ?
' id="'.$links[$i][2].
'"' :
'').
' class="wordwrap inline-block'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">';
2023 $outmore .= preg_replace(
'/([a-z])\/([a-z])/i',
'\\1 / \\2', $links[$i][1]);
2024 $outmore .=
'</a>'.
"\n";
2026 $outmore .=
'</div>';
2033 $outmore .=
'</div>';
2037 $left = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'right' :
'left');
2038 $right = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right');
2039 $widthofpopup = 200;
2041 $tabsname = $moretabssuffix;
2042 if (empty($tabsname)) {
2043 $tabsname = str_replace(
"@",
"", $picto);
2045 $out .=
'<div id="moretabs'.$tabsname.
'" class="inline-block tabsElem valignmiddle">';
2046 $out .=
'<div class="tab"><a href="#" class="tab moretab inline-block tabunactive"><span class="hideonsmartphone">'.$langs->trans(
"More").
'</span>... ('.$nbintab.
')</a></div>';
2047 $out .=
'<div id="moretabsList'.$tabsname.
'" style="width: '.$widthofpopup.
'px; position: absolute; '.$left.
': -999em; text-align: '.$left.
'; margin:0px; padding:2px; z-index:10;">';
2050 $out .=
'<div></div>';
2053 $out .=
'<script nonce="'.getNonce().
'">';
2054 $out .=
"$('#moretabs".$tabsname.
"').mouseenter( function() {
2055 var x = this.offsetLeft, y = this.offsetTop;
2056 console.log('mouseenter ".$left.
" x='+x+' y='+y+' window.innerWidth='+window.innerWidth);
2057 if ((window.innerWidth - x) < ".($widthofpopup + 10).
") {
2058 $('#moretabsList".$tabsname.
"').css('".$right.
"','8px');
2060 $('#moretabsList".$tabsname.
"').css('".$left.
"','auto');
2063 $out .=
"$('#moretabs".$tabsname.
"').mouseleave( function() { console.log('mouseleave ".$left.
"'); $('#moretabsList".$tabsname.
"').css('".$left.
"','-999em');});";
2064 $out .=
"</script>";
2067 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
2071 if (!$notab || $notab == -1 || $notab == -2 || $notab == -3) {
2072 $out .=
"\n".
'<div id="dragDropAreaTabBar" class="tabBar'.($notab == -1 ?
'' : ($notab == -2 ?
' tabBarNoTop' : (($notab == -3 ?
' noborderbottom' :
'').
' tabBarWithBottom'))).
'">'.
"\n";
2074 if (!empty($dragdropfile)) {
2077 $parameters = array(
'tabname' => $active,
'out' => $out);
2078 $reshook = $hookmanager->executeHooks(
'printTabsHead', $parameters);
2080 $out = $hookmanager->resPrint;
2106 if (!$notab || $notab == -1) {
2107 return "\n</div>\n";
2132 function dol_banner_tab($object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $onlybanner = 0, $morehtmlright =
'')
2134 global $conf,
$form, $user, $langs, $hookmanager, $action;
2138 $maxvisiblephotos = 1;
2140 $entity = (empty($object->entity) ? $conf->entity : $object->entity);
2141 $showbarcode = empty($conf->barcode->enabled) ? 0 : (empty($object->barcode) ? 0 : 1);
2142 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
2145 $modulepart =
'unknown';
2147 if ($object->element ==
'societe' || $object->element ==
'contact' || $object->element ==
'product' || $object->element ==
'ticket') {
2148 $modulepart = $object->element;
2149 } elseif ($object->element ==
'member') {
2150 $modulepart =
'memberphoto';
2151 } elseif ($object->element ==
'user') {
2152 $modulepart =
'userphoto';
2155 if (class_exists(
"Imagick")) {
2156 if ($object->element ==
'expensereport' || $object->element ==
'propal' || $object->element ==
'commande' || $object->element ==
'facture' || $object->element ==
'supplier_proposal') {
2157 $modulepart = $object->element;
2158 } elseif ($object->element ==
'fichinter') {
2159 $modulepart =
'ficheinter';
2160 } elseif ($object->element ==
'contrat') {
2161 $modulepart =
'contract';
2162 } elseif ($object->element ==
'order_supplier') {
2163 $modulepart =
'supplier_order';
2164 } elseif ($object->element ==
'invoice_supplier') {
2165 $modulepart =
'supplier_invoice';
2169 if ($object->element ==
'product') {
2171 $cssclass =
'photowithmargin photoref';
2172 $showimage = $object->is_photo_available($conf->product->multidir_output[$entity]);
2173 $maxvisiblephotos = (isset($conf->global->PRODUCT_MAX_VISIBLE_PHOTO) ? $conf->global->PRODUCT_MAX_VISIBLE_PHOTO : 5);
2174 if ($conf->browser->layout ==
'phone') {
2175 $maxvisiblephotos = 1;
2178 $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>';
2180 if (!empty($conf->global->PRODUCT_NODISPLAYIFNOPHOTO)) {
2182 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
2184 $nophoto =
'/public/theme/common/nophoto.png';
2185 $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>';
2188 } elseif ($object->element ==
'ticket') {
2190 $cssclass =
'photoref';
2191 $showimage = $object->is_photo_available($conf->ticket->multidir_output[$entity].
'/'.$object->ref);
2192 $maxvisiblephotos = (isset($conf->global->TICKET_MAX_VISIBLE_PHOTO) ? $conf->global->TICKET_MAX_VISIBLE_PHOTO : 2);
2193 if ($conf->browser->layout ==
'phone') {
2194 $maxvisiblephotos = 1;
2198 $showphoto = $object->show_photos(
'ticket', $conf->ticket->multidir_output[$entity],
'small', $maxvisiblephotos, 0, 0, 0, $width, 0);
2199 if ($object->nbphoto > 0) {
2200 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$showphoto.
'</div>';
2206 if (!empty($conf->global->TICKET_NODISPLAYIFNOPHOTO)) {
2208 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
2210 $nophoto =
img_picto(
'No photo',
'object_ticket');
2211 $morehtmlleft .=
'<!-- No photo to show -->';
2212 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
2213 $morehtmlleft .= $nophoto;
2214 $morehtmlleft .=
'</div></div>';
2219 if ($modulepart !=
'unknown') {
2222 if (in_array($modulepart, array(
'propal',
'commande',
'facture',
'ficheinter',
'contract',
'supplier_order',
'supplier_proposal',
'supplier_invoice',
'expensereport')) && class_exists(
"Imagick")) {
2224 $dir_output = (empty($conf->$modulepart->multidir_output[$entity]) ? $conf->$modulepart->dir_output : $conf->$modulepart->multidir_output[$entity]).
"/";
2225 if (in_array($modulepart, array(
'invoice_supplier',
'supplier_invoice'))) {
2226 $subdir =
get_exdir($object->id, 2, 0, 1, $object, $modulepart);
2227 $subdir .= ((!empty($subdir) && !preg_match(
'/\/$/', $subdir)) ?
'/' :
'').$objectref;
2229 $subdir =
get_exdir($object->id, 0, 0, 1, $object, $modulepart);
2231 if (empty($subdir)) {
2232 $subdir =
'errorgettingsubdirofobject';
2235 $filepath = $dir_output.$subdir.
"/";
2237 $filepdf = $filepath.$objectref.
".pdf";
2238 $relativepath = $subdir.
'/'.$objectref.
'.pdf';
2241 $fileimage = $filepdf.
'_preview.png';
2242 $relativepathimage = $relativepath.
'_preview.png';
2244 $pdfexists = file_exists($filepdf);
2249 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
2250 if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) {
2251 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2260 if ($pdfexists && !$error) {
2261 $heightforphotref = 80;
2262 if (!empty($conf->dol_optimize_smallscreen)) {
2263 $heightforphotref = 60;
2266 if (file_exists($fileimage)) {
2267 $phototoshow =
'<div class="photoref">';
2268 $phototoshow .=
'<img height="'.$heightforphotref.
'" class="photo photowithborder" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart=apercu'.$modulepart.
'&file='.urlencode($relativepathimage).
'">';
2269 $phototoshow .=
'</div>';
2272 } elseif (!$phototoshow) {
2273 $phototoshow .=
$form->showphoto($modulepart, $object, 0, 0, 0,
'photowithmargin photoref',
'small', 1, 0, $maxvisiblephotos);
2277 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">';
2278 $morehtmlleft .= $phototoshow;
2279 $morehtmlleft .=
'</div>';
2283 if (empty($phototoshow)) {
2284 if ($object->element ==
'action') {
2286 $cssclass =
'photorefcenter';
2287 $nophoto =
img_picto(
'No photo',
'title_agenda');
2290 $cssclass =
'photorefcenter';
2291 $picto = $object->picto;
2292 $prefix =
'object_';
2293 if ($object->element ==
'project' && !$object->public) {
2296 if (strpos($picto,
'fontawesome_') !==
false) {
2299 $nophoto =
img_picto(
'No photo', $prefix.$picto);
2301 $morehtmlleft .=
'<!-- No photo to show -->';
2302 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
2303 $morehtmlleft .= $nophoto;
2304 $morehtmlleft .=
'</div></div>';
2311 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$form->showbarcode($object, 100,
'photoref valignmiddle').
'</div>';
2314 if ($object->element ==
'societe') {
2315 if (!empty($conf->use_javascript_ajax) && $user->hasRight(
'societe',
'creer') && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
2316 $morehtmlstatus .=
ajax_object_onoff($object,
'status',
'status',
'InActivity',
'ActivityCeased');
2318 $morehtmlstatus .= $object->getLibStatut(6);
2320 } elseif ($object->element ==
'product') {
2322 if (!empty($conf->use_javascript_ajax) && $user->rights->produit->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
2323 $morehtmlstatus .=
ajax_object_onoff($object,
'status',
'tosell',
'ProductStatusOnSell',
'ProductStatusNotOnSell');
2325 $morehtmlstatus .=
'<span class="statusrefsell">'.$object->getLibStatut(6, 0).
'</span>';
2327 $morehtmlstatus .=
' ';
2329 if (!empty($conf->use_javascript_ajax) && $user->rights->produit->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
2330 $morehtmlstatus .=
ajax_object_onoff($object,
'status_buy',
'tobuy',
'ProductStatusOnBuy',
'ProductStatusNotOnBuy');
2332 $morehtmlstatus .=
'<span class="statusrefbuy">'.$object->getLibStatut(6, 1).
'</span>';
2334 } elseif (in_array($object->element, array(
'facture',
'invoice',
'invoice_supplier',
'chargesociales',
'loan',
'tva',
'salary'))) {
2335 $tmptxt = $object->getLibStatut(6, $object->totalpaid);
2336 if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
2337 $tmptxt = $object->getLibStatut(5, $object->totalpaid);
2339 $morehtmlstatus .= $tmptxt;
2340 } elseif ($object->element ==
'contrat' || $object->element ==
'contract') {
2341 if ($object->statut == 0) {
2342 $morehtmlstatus .= $object->getLibStatut(5);
2344 $morehtmlstatus .= $object->getLibStatut(4);
2346 } elseif ($object->element ==
'facturerec') {
2347 if ($object->frequency == 0) {
2348 $morehtmlstatus .= $object->getLibStatut(2);
2350 $morehtmlstatus .= $object->getLibStatut(5);
2352 } elseif ($object->element ==
'project_task') {
2353 $object->fk_statut = 1;
2354 if ($object->progress > 0) {
2355 $object->fk_statut = 2;
2357 if ($object->progress >= 100) {
2358 $object->fk_statut = 3;
2360 $tmptxt = $object->getLibStatut(5);
2361 $morehtmlstatus .= $tmptxt;
2362 } elseif (method_exists($object,
'getLibStatut')) {
2363 $tmptxt = $object->getLibStatut(6);
2364 if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
2365 $tmptxt = $object->getLibStatut(5);
2367 $morehtmlstatus .= $tmptxt;
2371 if (
isModEnabled(
'accounting') && in_array($object->element, array(
'bank',
'paiementcharge',
'facture',
'invoice',
'invoice_supplier',
'expensereport',
'payment_various'))) {
2373 if (method_exists($object,
'getVentilExportCompta')) {
2374 $accounted = $object->getVentilExportCompta();
2375 $langs->load(
"accountancy");
2376 $morehtmlstatus .=
'</div><div class="statusref statusrefbis"><span class="opacitymedium">'.($accounted > 0 ? $langs->trans(
"Accounted") : $langs->trans(
"NotYetAccounted")).
'</span>';
2381 if (!empty($object->name_alias)) {
2382 $morehtmlref .=
'<div class="refidno opacitymedium">'.dol_escape_htmltag($object->name_alias).
'</div>';
2386 if (in_array($object->element, array(
'product',
'bank_account',
'project_task'))) {
2387 if (!empty($object->label)) {
2388 $morehtmlref .=
'<div class="refidno opacitymedium">'.$object->label.
'</div>';
2393 if (method_exists($object,
'getBannerAddress') && !in_array($object->element, array(
'product',
'bookmark',
'ecm_directories',
'ecm_files'))) {
2394 $moreaddress = $object->getBannerAddress(
'refaddress', $object);
2396 $morehtmlref .=
'<div class="refidno refaddress">';
2397 $morehtmlref .= $moreaddress;
2398 $morehtmlref .=
'</div>';
2401 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)) {
2402 $morehtmlref .=
'<div style="clear: both;"></div>';
2403 $morehtmlref .=
'<div class="refidno opacitymedium">';
2404 $morehtmlref .= $langs->trans(
"TechnicalID").
': '.((int) $object->id);
2405 $morehtmlref .=
'</div>';
2408 $parameters=array(
'morehtmlref'=>$morehtmlref);
2409 $reshook = $hookmanager->executeHooks(
'formDolBanner', $parameters, $object, $action);
2412 } elseif (empty($reshook)) {
2413 $morehtmlref .= $hookmanager->resPrint;
2414 } elseif ($reshook > 0) {
2415 $morehtmlref = $hookmanager->resPrint;
2419 print
'<div class="'.($onlybanner ?
'arearefnobottom ' :
'arearef ').
'heightref valignmiddle centpercent">';
2420 print
$form->showrefnav($object, $paramid, $morehtml, $shownav, $fieldid, $fieldref, $morehtmlref, $moreparam, $nodbprefix, $morehtmlleft, $morehtmlstatus, $morehtmlright);
2422 print
'<div class="underrefbanner clearboth"></div>';
2438 if ($fieldrequired) {
2439 $ret .=
'<span class="fieldrequired">';
2441 $ret .=
'<label for="'.$fieldkey.
'">';
2442 $ret .= $langs->trans($langkey);
2444 if ($fieldrequired) {
2460 $ret =
' '.$bc[$var];
2462 $ret = preg_replace(
'/class=\"/',
'class="'.$moreclass.
' ', $ret);
2480 function dol_format_address($object, $withcountry = 0, $sep =
"\n", $outputlangs =
'', $mode = 0, $extralangcode =
'')
2482 global $conf, $langs, $hookmanager;
2485 $countriesusingstate = array(
'AU',
'CA',
'US',
'IN',
'GB',
'ES',
'UK',
'TR',
'CN');
2490 $ret .= ($extralangcode ? $object->array_languages[
'address'][$extralangcode] : (empty($object->address) ?
'' : $object->address));
2493 if (isset($object->country_code) && in_array($object->country_code, array(
'AU',
'CA',
'US',
'CN')) || !empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS)) {
2495 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2496 $ret .= (($ret && $town) ? $sep :
'').$town;
2498 if (!empty($object->state)) {
2499 $ret .= ($ret ? ($town ?
", " : $sep) :
'').$object->state;
2501 if (!empty($object->zip)) {
2502 $ret .= ($ret ? (($town || $object->state) ?
", " : $sep) :
'').$object->zip;
2504 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'GB',
'UK'))) {
2506 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2507 $ret .= ($ret ? $sep :
'').$town;
2508 if (!empty($object->state)) {
2509 $ret .= ($ret ?
", " :
'').$object->state;
2511 if (!empty($object->zip)) {
2512 $ret .= ($ret ? $sep :
'').$object->zip;
2514 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'ES',
'TR'))) {
2516 $ret .= ($ret ? $sep :
'').$object->zip;
2517 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2518 $ret .= ($town ? (($object->zip ?
' ' :
'').$town) :
'');
2519 if (!empty($object->state)) {
2520 $ret .=
"\n".$object->state;
2522 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'JP'))) {
2525 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2526 $ret .= ($ret ? $sep :
'').($object->state ? $object->state.
', ' :
'').$town.($object->zip ?
' ' :
'').$object->zip;
2527 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'IT'))) {
2529 $ret .= ($ret ? $sep :
'').$object->zip;
2530 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2531 $ret .= ($town ? (($object->zip ?
' ' :
'').$town) :
'');
2532 $ret .= (empty($object->state_code) ?
'' : (
' '.$object->state_code));
2535 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2536 $ret .= !empty($object->zip) ? (($ret ? $sep :
'').$object->zip) :
'';
2537 $ret .= ($town ? (($object->zip ?
' ' : ($ret ? $sep :
'')).$town) :
'');
2538 if (!empty($object->state) && in_array($object->country_code, $countriesusingstate)) {
2539 $ret .= ($ret ?
", " :
'').$object->state;
2542 if (!is_object($outputlangs)) {
2543 $outputlangs = $langs;
2546 $langs->load(
"dict");
2547 $ret .= (empty($object->country_code) ?
'' : ($ret ? $sep :
'').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv(
"Country".$object->country_code)));
2550 $parameters = array(
'withcountry' => $withcountry,
'sep' => $sep,
'outputlangs' => $outputlangs,
'mode' => $mode,
'extralangcode' => $extralangcode);
2551 $reshook = $hookmanager->executeHooks(
'formatAddress', $parameters, $object);
2555 $ret .= $hookmanager->resPrint;
2573 if ((abs($ts) <= 0x7FFFFFFF)) {
2574 return ($is_gmt) ? @gmstrftime($fmt, $ts) : @strftime($fmt, $ts);
2576 return 'Error date into a not supported range';
2601 function dol_print_date($time, $format =
'', $tzoutput =
'auto', $outputlangs =
'', $encodetooutput =
false)
2603 global $conf, $langs;
2610 if ($tzoutput ===
'auto') {
2611 $tzoutput = (empty($conf) ?
'tzserver' : (isset($conf->tzuserinputkey) ? $conf->tzuserinputkey :
'tzserver'));
2616 $offsettz = $offsetdst = 0;
2619 if (is_string($tzoutput)) {
2620 if ($tzoutput ==
'tzserver') {
2622 $offsettzstring = @date_default_timezone_get();
2625 } elseif ($tzoutput ==
'tzuser' || $tzoutput ==
'tzuserrel') {
2627 $offsettzstring = (empty($_SESSION[
'dol_tz_string']) ?
'UTC' : $_SESSION[
'dol_tz_string']);
2629 if (class_exists(
'DateTimeZone')) {
2630 $user_date_tz =
new DateTimeZone($offsettzstring);
2631 $user_dt =
new DateTime();
2632 $user_dt->setTimezone($user_date_tz);
2633 $user_dt->setTimestamp($tzoutput ==
'tzuser' ?
dol_now() : (
int) $time);
2634 $offsettz = $user_dt->getOffset();
2636 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
2637 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
2642 if (!is_object($outputlangs)) {
2643 $outputlangs = $langs;
2646 $format =
'daytextshort';
2651 $reduceformat = (!empty($conf->dol_optimize_smallscreen) && in_array($format, array(
'day',
'dayhour'))) ? 1 : 0;
2652 $format = preg_replace(
'/inputnoreduce/',
'', $format);
2653 $formatwithoutreduce = preg_replace(
'/reduceformat/',
'', $format);
2654 if ($formatwithoutreduce != $format) {
2655 $format = $formatwithoutreduce;
2661 if ($format ==
'day') {
2662 $format = ($outputlangs->trans(
"FormatDateShort") !=
"FormatDateShort" ? $outputlangs->trans(
"FormatDateShort") : $conf->format_date_short);
2663 } elseif ($format ==
'hour') {
2664 $format = ($outputlangs->trans(
"FormatHourShort") !=
"FormatHourShort" ? $outputlangs->trans(
"FormatHourShort") : $conf->format_hour_short);
2665 } elseif ($format ==
'hourduration') {
2666 $format = ($outputlangs->trans(
"FormatHourShortDuration") !=
"FormatHourShortDuration" ? $outputlangs->trans(
"FormatHourShortDuration") : $conf->format_hour_short_duration);
2667 } elseif ($format ==
'daytext') {
2668 $format = ($outputlangs->trans(
"FormatDateText") !=
"FormatDateText" ? $outputlangs->trans(
"FormatDateText") : $conf->format_date_text);
2669 } elseif ($format ==
'daytextshort') {
2670 $format = ($outputlangs->trans(
"FormatDateTextShort") !=
"FormatDateTextShort" ? $outputlangs->trans(
"FormatDateTextShort") : $conf->format_date_text_short);
2671 } elseif ($format ==
'dayhour') {
2672 $format = ($outputlangs->trans(
"FormatDateHourShort") !=
"FormatDateHourShort" ? $outputlangs->trans(
"FormatDateHourShort") : $conf->format_date_hour_short);
2673 } elseif ($format ==
'dayhoursec') {
2674 $format = ($outputlangs->trans(
"FormatDateHourSecShort") !=
"FormatDateHourSecShort" ? $outputlangs->trans(
"FormatDateHourSecShort") : $conf->format_date_hour_sec_short);
2675 } elseif ($format ==
'dayhourtext') {
2676 $format = ($outputlangs->trans(
"FormatDateHourText") !=
"FormatDateHourText" ? $outputlangs->trans(
"FormatDateHourText") : $conf->format_date_hour_text);
2677 } elseif ($format ==
'dayhourtextshort') {
2678 $format = ($outputlangs->trans(
"FormatDateHourTextShort") !=
"FormatDateHourTextShort" ? $outputlangs->trans(
"FormatDateHourTextShort") : $conf->format_date_hour_text_short);
2679 } elseif ($format ==
'dayhourlog') {
2681 $format =
'%Y%m%d%H%M%S';
2682 } elseif ($format ==
'dayhourlogsmall') {
2684 $format =
'%y%m%d%H%M';
2685 } elseif ($format ==
'dayhourldap') {
2686 $format =
'%Y%m%d%H%M%SZ';
2687 } elseif ($format ==
'dayhourxcard') {
2688 $format =
'%Y%m%dT%H%M%SZ';
2689 } elseif ($format ==
'dayxcard') {
2691 } elseif ($format ==
'dayrfc') {
2692 $format =
'%Y-%m-%d';
2693 } elseif ($format ==
'dayhourrfc') {
2694 $format =
'%Y-%m-%dT%H:%M:%SZ';
2695 } elseif ($format ==
'standard') {
2696 $format =
'%Y-%m-%d %H:%M:%S';
2699 if ($reduceformat) {
2700 $format = str_replace(
'%Y',
'%y', $format);
2701 $format = str_replace(
'yyyy',
'yy', $format);
2705 if (preg_match(
'/%b/i', $format)) {
2707 $format = str_replace(
'%b',
'__b__', $format);
2708 $format = str_replace(
'%B',
'__B__', $format);
2710 if (preg_match(
'/%a/i', $format)) {
2712 $format = str_replace(
'%a',
'__a__', $format);
2713 $format = str_replace(
'%A',
'__A__', $format);
2718 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)) {
2719 dol_print_error(
'',
"Functions.lib::dol_print_date function called with a bad value from page ".$_SERVER[
"PHP_SELF"]);
2721 } elseif (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $time, $reg)) {
2723 dol_syslog(
"Functions.lib::dol_print_date function called with a bad value from page ".$_SERVER[
"PHP_SELF"], LOG_WARNING);
2726 $syear = (!empty($reg[1]) ? $reg[1] :
'');
2727 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
2728 $sday = (!empty($reg[3]) ? $reg[3] :
'');
2729 $shour = (!empty($reg[4]) ? $reg[4] :
'');
2730 $smin = (!empty($reg[5]) ? $reg[5] :
'');
2731 $ssec = (!empty($reg[6]) ? $reg[6] :
'');
2733 $time =
dol_mktime($shour, $smin, $ssec, $smonth, $sday, $syear,
true);
2736 $tzo =
new DateTimeZone(
'UTC');
2738 $tzo =
new DateTimeZone(date_default_timezone_get());
2740 $dtts =
new DateTime();
2741 $dtts->setTimestamp($time);
2742 $dtts->setTimezone($tzo);
2743 $newformat = str_replace(
2744 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2745 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2747 $ret = $dtts->format($newformat);
2749 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2750 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2755 if ($time < 100000000000) {
2756 $timetouse = $time + $offsettz + $offsetdst;
2759 $tzo =
new DateTimeZone(
'UTC');
2761 $tzo =
new DateTimeZone(date_default_timezone_get());
2763 $dtts =
new DateTime();
2764 $dtts->setTimestamp($timetouse);
2765 $dtts->setTimezone($tzo);
2766 $newformat = str_replace(
2767 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'%w',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2768 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'w',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2770 $ret = $dtts->format($newformat);
2772 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2773 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2778 $ret =
'Bad value '.$time.
' for date';
2782 if (preg_match(
'/__b__/i', $format)) {
2783 $timetouse = $time + $offsettz + $offsetdst;
2786 $tzo =
new DateTimeZone(
'UTC');
2788 $tzo =
new DateTimeZone(date_default_timezone_get());
2790 $dtts =
new DateTime();
2791 $dtts->setTimestamp($timetouse);
2792 $dtts->setTimezone($tzo);
2793 $month = $dtts->format(
"m");
2794 $month = sprintf(
"%02d", $month);
2795 if ($encodetooutput) {
2796 $monthtext = $outputlangs->transnoentities(
'Month'.$month);
2797 $monthtextshort = $outputlangs->transnoentities(
'MonthShort'.$month);
2799 $monthtext = $outputlangs->transnoentitiesnoconv(
'Month'.$month);
2800 $monthtextshort = $outputlangs->transnoentitiesnoconv(
'MonthShort'.$month);
2803 $ret = str_replace(
'__b__', $monthtextshort, $ret);
2804 $ret = str_replace(
'__B__', $monthtext, $ret);
2808 if (preg_match(
'/__a__/i', $format)) {
2810 $timetouse = $time + $offsettz + $offsetdst;
2813 $tzo =
new DateTimeZone(
'UTC');
2815 $tzo =
new DateTimeZone(date_default_timezone_get());
2817 $dtts =
new DateTime();
2818 $dtts->setTimestamp($timetouse);
2819 $dtts->setTimezone($tzo);
2820 $w = $dtts->format(
"w");
2821 $dayweek = $outputlangs->transnoentitiesnoconv(
'Day'.$w);
2823 $ret = str_replace(
'__A__', $dayweek, $ret);
2824 $ret = str_replace(
'__a__',
dol_substr($dayweek, 0, 3), $ret);
2853 $datetimeobj =
new DateTime();
2854 $datetimeobj->setTimestamp($timestamp);
2855 if ($forcetimezone) {
2856 $datetimeobj->setTimezone(
new DateTimeZone($forcetimezone ==
'gmt' ?
'UTC' : $forcetimezone));
2859 'year'=>((
int) date_format($datetimeobj,
'Y')),
2860 'mon'=>((
int) date_format($datetimeobj,
'm')),
2861 'mday'=>((
int) date_format($datetimeobj,
'd')),
2862 'wday'=>((
int) date_format($datetimeobj,
'w')),
2863 'yday'=>((
int) date_format($datetimeobj,
'z')),
2864 'hours'=>((
int) date_format($datetimeobj,
'H')),
2865 'minutes'=>((
int) date_format($datetimeobj,
'i')),
2866 'seconds'=>((
int) date_format($datetimeobj,
's')),
2894 function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm =
'auto', $check = 1)
2899 if ($gm ===
'auto') {
2900 $gm = (empty($conf) ?
'tzserver' : $conf->tzuserinputkey);
2905 if ($hour == -1 || empty($hour)) {
2908 if ($minute == -1 || empty($minute)) {
2911 if ($second == -1 || empty($second)) {
2917 if (!$month || !$day) {
2926 if ($hour < 0 || $hour > 24) {
2929 if ($minute < 0 || $minute > 60) {
2932 if ($second < 0 || $second > 60) {
2937 if (empty($gm) || ($gm ===
'server' || $gm ===
'tzserver')) {
2938 $default_timezone = @date_default_timezone_get();
2939 $localtz =
new DateTimeZone($default_timezone);
2940 } elseif ($gm ===
'user' || $gm ===
'tzuser' || $gm ===
'tzuserrel') {
2942 $default_timezone = (empty($_SESSION[
"dol_tz_string"]) ? @date_default_timezone_get() : $_SESSION[
"dol_tz_string"]);
2944 $localtz =
new DateTimeZone($default_timezone);
2946 dol_syslog(
"Warning dol_tz_string contains an invalid value ".$_SESSION[
"dol_tz_string"], LOG_WARNING);
2947 $default_timezone = @date_default_timezone_get();
2949 } elseif (strrpos($gm,
"tz,") !==
false) {
2950 $timezone = str_replace(
"tz,",
"", $gm);
2952 $localtz =
new DateTimeZone($timezone);
2954 dol_syslog(
"Warning passed timezone contains an invalid value ".$timezone, LOG_WARNING);
2958 if (empty($localtz)) {
2959 $localtz =
new DateTimeZone(
'UTC');
2963 $dt =
new DateTime(
'now', $localtz);
2964 $dt->setDate((
int) $year, (
int) $month, (
int) $day);
2965 $dt->setTime((
int) $hour, (
int) $minute, (
int) $second);
2966 $date = $dt->getTimestamp();
2986 if ($mode ===
'auto') {
2990 if ($mode ==
'gmt') {
2992 } elseif ($mode ==
'tzserver') {
2993 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2995 $ret = (int) (
dol_now(
'gmt') + ($tzsecond * 3600));
3001 } elseif ($mode ==
'tzuser' || $mode ==
'tzuserrel') {
3004 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
3005 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
3006 $ret = (int) (
dol_now(
'gmt') + ($offsettz + $offsetdst));
3023 global $conf, $langs;
3026 if (!empty($conf->dol_optimize_smallscreen)) {
3031 if (empty($shortvalue) || $size < ($level * 10)) {
3033 $textunitshort = $langs->trans(
"b");
3034 $textunitlong = $langs->trans(
"Bytes");
3036 $ret = round($size / $level, 0);
3037 $textunitshort = $langs->trans(
"Kb");
3038 $textunitlong = $langs->trans(
"KiloBytes");
3041 if (empty($shortunit)) {
3042 $ret .=
' '.$textunitlong;
3044 $ret .=
' '.$textunitshort;
3060 function dol_print_url($url, $target =
'_blank', $max = 32, $withpicto = 0, $morecss =
'float')
3068 $link =
'<a href="';
3069 if (!preg_match(
'/^http/i', $url)) {
3075 $link .=
' target="'.$target.
'"';
3078 if (!preg_match(
'/^http/i', $url)) {
3084 if ($morecss ==
'float') {
3085 return '<div class="nospan'.($morecss ?
' '.$morecss :
'').
'" style="margin-right: 10px">'.($withpicto ?
img_picto($langs->trans(
"Url"),
'globe').
' ' :
'').$link.
'</div>';
3087 return '<span class="nospan'.($morecss ?
' '.$morecss :
'').
'" style="margin-right: 10px">'.($withpicto ?
img_picto($langs->trans(
"Url"),
'globe').
' ' :
'').$link.
'</span>';
3103 function dol_print_email($email, $cid = 0, $socid = 0, $addlink = 0, $max = 64, $showinvalid = 1, $withpicto = 0)
3105 global $conf, $user, $langs, $hookmanager;
3109 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) {
3113 if (empty($email)) {
3117 if (!empty($addlink)) {
3118 $newemail =
'<a style="text-overflow: ellipsis;" href="';
3119 if (!preg_match(
'/^mailto:/i', $email)) {
3120 $newemail .=
'mailto:';
3122 $newemail .= $email;
3125 $newemail .=
'</a>';
3127 $langs->load(
"errors");
3128 $newemail .=
img_warning($langs->trans(
"ErrorBadEMail", $email));
3131 if (($cid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
3134 if (!empty($conf->global->AGENDA_ADDACTIONFOREMAIL)) {
3135 $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>';
3138 $newemail =
'<div>'.$newemail.
' '.$link.
'</div>';
3143 $langs->load(
"errors");
3144 $newemail .=
img_warning($langs->trans(
"ErrorBadEMail", $email));
3149 $rep = ($withpicto ?
img_picto($langs->trans(
"EMail").
' : '.$email, (is_numeric($withpicto) ?
'email' : $withpicto)).
' ' :
'').$newemail;
3152 $parameters = array(
'cid' => $cid,
'socid' => $socid,
'addlink' => $addlink,
'picto' => $withpicto);
3154 $reshook = $hookmanager->executeHooks(
'printEmail', $parameters, $email);
3158 $rep .= $hookmanager->resPrint;
3173 $socialnetworks = array();
3175 require_once DOL_DOCUMENT_ROOT.
'/core/lib/memory.lib.php';
3176 $cachekey =
'socialnetworks_' . $conf->entity;
3178 if (!is_null($dataretrieved)) {
3179 $socialnetworks = $dataretrieved;
3181 $sql =
"SELECT rowid, code, label, url, icon, active FROM ".MAIN_DB_PREFIX.
"c_socialnetworks";
3182 $sql .=
" WHERE entity=".$conf->entity;
3183 $resql = $db->query(
$sql);
3185 while ($obj = $db->fetch_object($resql)) {
3186 $socialnetworks[$obj->code] = array(
3187 'rowid' => $obj->rowid,
3188 'label' => $obj->label,
3190 'icon' => $obj->icon,
3191 'active' => $obj->active,
3198 return $socialnetworks;
3213 global $conf, $user, $langs;
3217 if (empty($value)) {
3221 if (!empty($type)) {
3222 $htmllink =
'<div class="divsocialnetwork inline-block valignmiddle">';
3224 $htmllink .=
'<span class="fa pictofixedwidth '.($dictsocialnetworks[$type][
'icon'] ? $dictsocialnetworks[$type][
'icon'] :
'fa-link').
'"></span>';
3225 if ($type ==
'skype') {
3227 $htmllink .=
' <a href="skype:';
3229 $htmllink .=
'?call" alt="'.$langs->trans(
"Call").
' '.$value.
'" title="'.
dol_escape_htmltag($langs->trans(
"Call").
' '.$value).
'">';
3230 $htmllink .=
'<img src="'.DOL_URL_ROOT.
'/theme/common/skype_callbutton.png" border="0">';
3231 $htmllink .=
'</a><a href="skype:';
3233 $htmllink .=
'?chat" alt="'.$langs->trans(
"Chat").
' '.$value.
'" title="'.
dol_escape_htmltag($langs->trans(
"Chat").
' '.$value).
'">';
3234 $htmllink .=
'<img class="paddingleft" src="'.DOL_URL_ROOT.
'/theme/common/skype_chatbutton.png" border="0">';
3235 $htmllink .=
'</a>';
3236 if (($cid || $socid) &&
isModEnabled(
'agenda') && $user->rights->agenda->myactions->create) {
3237 $addlink =
'AC_SKYPE';
3239 if (!empty($conf->global->AGENDA_ADDACTIONFORSKYPE)) {
3240 $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>';
3242 $htmllink .= ($link ?
' '.$link :
'');
3245 if (!empty($dictsocialnetworks[$type][
'url'])) {
3246 $tmpvirginurl = preg_replace(
'/\/?{socialid}/',
'', $dictsocialnetworks[$type][
'url']);
3247 if ($tmpvirginurl) {
3248 $value = preg_replace(
'/^www\.'.preg_quote($tmpvirginurl,
'/').
'\/?/',
'', $value);
3249 $value = preg_replace(
'/^'.preg_quote($tmpvirginurl,
'/').
'\/?/',
'', $value);
3251 $tmpvirginurl3 = preg_replace(
'/^https:\/\//i',
'https://www.', $tmpvirginurl);
3252 if ($tmpvirginurl3) {
3253 $value = preg_replace(
'/^www\.'.preg_quote($tmpvirginurl3,
'/').
'\/?/',
'', $value);
3254 $value = preg_replace(
'/^'.preg_quote($tmpvirginurl3,
'/').
'\/?/',
'', $value);
3257 $tmpvirginurl2 = preg_replace(
'/^https?:\/\//i',
'', $tmpvirginurl);
3258 if ($tmpvirginurl2) {
3259 $value = preg_replace(
'/^www\.'.preg_quote($tmpvirginurl2,
'/').
'\/?/',
'', $value);
3260 $value = preg_replace(
'/^'.preg_quote($tmpvirginurl2,
'/').
'\/?/',
'', $value);
3263 $link = str_replace(
'{socialid}', $value, $dictsocialnetworks[$type][
'url']);
3264 if (preg_match(
'/^https?:\/\//i', $link)) {
3265 $htmllink .=
'<a href="'.dol_sanitizeUrl($link, 0).
'" target="_blank" rel="noopener noreferrer">'.
dol_escape_htmltag($value).
'</a>';
3267 $htmllink .=
'<a href="'.dol_sanitizeUrl($link, 1).
'" target="_blank" rel="noopener noreferrer">'.
dol_escape_htmltag($value).
'</a>';
3273 $htmllink .=
'</div>';
3275 $langs->load(
"errors");
3276 $htmllink .=
img_warning($langs->trans(
"ErrorBadSocialNetworkValue", $value));
3291 function dol_print_profids($profID, $profIDtype, $countrycode =
'', $addcpButton = 1, $separ =
' ')
3295 if (empty($profID) || empty($profIDtype)) {
3298 if (empty($countrycode)) $countrycode = $mysoc->country_code;
3299 $newProfID = $profID;
3300 $id = substr($profIDtype, -1);
3302 if (strtoupper($countrycode) ==
'FR') {
3304 if ($id == 1 &&
dol_strlen($newProfID) == 9) $newProfID = substr($newProfID, 0, 3).$separ.substr($newProfID, 3, 3).$separ.substr($newProfID, 6, 3);
3305 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);
3306 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);
3309 else $ret = $newProfID;
3327 function dol_print_phone($phone, $countrycode =
'', $cid = 0, $socid = 0, $addlink =
'', $separ =
" ", $withpicto =
'', $titlealt =
'', $adddivfloat = 0)
3329 global $conf, $user, $langs, $mysoc, $hookmanager;
3332 $phone = is_null($phone) ?
'' : preg_replace(
"/[\s.-]/",
"", trim($phone));
3333 if (empty($phone)) {
3336 if (!empty($conf->global->MAIN_PHONE_SEPAR)) {
3337 $separ = $conf->global->MAIN_PHONE_SEPAR;
3339 if (empty($countrycode) && is_object($mysoc)) {
3340 $countrycode = $mysoc->country_code;
3344 if ($conf->dol_optimize_smallscreen) {
3349 if (strtoupper($countrycode) ==
"FR") {
3352 $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);
3354 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 2).$separ.substr($newphone, 5, 2);
3356 $newphone = substr($newphone, 0, 2).$separ.substr($newphone, 2, 3).$separ.substr($newphone, 5, 2).$separ.substr($newphone, 7, 2);
3358 $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);
3360 $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);
3362 $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);
3364 } elseif (strtoupper($countrycode) ==
"CA") {
3366 $newphone = ($separ !=
'' ?
'(' :
'').substr($newphone, 0, 3).($separ !=
'' ?
')' :
'').$separ.substr($newphone, 3, 3).($separ !=
'' ?
'-' :
'').substr($newphone, 6, 4);
3368 } elseif (strtoupper($countrycode) ==
"PT") {
3370 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3372 } elseif (strtoupper($countrycode) ==
"SR") {
3374 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3);
3376 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 4);
3378 } elseif (strtoupper($countrycode) ==
"DE") {
3380 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 4).$separ.substr($newphone, 11, 3);
3382 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 4).$separ.substr($newphone, 10, 3);
3384 } elseif (strtoupper($countrycode) ==
"ES") {
3386 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3388 } elseif (strtoupper($countrycode) ==
"BF") {
3390 $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);
3392 } elseif (strtoupper($countrycode) ==
"RO") {
3394 $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);
3396 } elseif (strtoupper($countrycode) ==
"TR") {
3398 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 4);
3400 } elseif (strtoupper($countrycode) ==
"US") {
3402 $newphone = substr($newphone, 0, 2).$separ.substr($newphone, 2, 3).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 4);
3404 } elseif (strtoupper($countrycode) ==
"MX") {
3406 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 2);
3408 $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);
3410 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 4);
3412 } elseif (strtoupper($countrycode) ==
"ML") {
3414 $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);
3416 } elseif (strtoupper($countrycode) ==
"TH") {
3418 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 3);
3420 $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);
3422 } elseif (strtoupper($countrycode) ==
"MU") {
3425 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 2).$separ.substr($newphone, 9, 2);
3427 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 4).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 2);
3429 } elseif (strtoupper($countrycode) ==
"ZA") {
3431 $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);
3433 } elseif (strtoupper($countrycode) ==
"SY") {
3435 $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);
3437 $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);
3439 } elseif (strtoupper($countrycode) ==
"AE") {
3441 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 2);
3443 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3445 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 4);
3447 } elseif (strtoupper($countrycode) ==
"DZ") {
3449 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3451 } elseif (strtoupper($countrycode) ==
"BE") {
3453 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 3);
3455 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3457 } elseif (strtoupper($countrycode) ==
"PF") {
3459 $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);
3461 } elseif (strtoupper($countrycode) ==
"CO") {
3463 $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);
3465 } elseif (strtoupper($countrycode) ==
"JO") {
3467 $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);
3469 } elseif (strtoupper($countrycode) ==
"JM") {
3471 $newphone = substr($newphone, 0, 5).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 4);
3473 } elseif (strtoupper($countrycode) ==
"MG") {
3475 $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);
3477 } elseif (strtoupper($countrycode) ==
"GB") {
3479 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3481 } elseif (strtoupper($countrycode) ==
"CH") {
3483 $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);
3485 $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);
3487 } elseif (strtoupper($countrycode) ==
"TN") {
3489 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3491 } elseif (strtoupper($countrycode) ==
"GF") {
3493 $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);
3495 } elseif (strtoupper($countrycode) ==
"GP") {
3497 $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);
3499 } elseif (strtoupper($countrycode) ==
"MQ") {
3501 $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);
3503 } elseif (strtoupper($countrycode) ==
"IT") {
3505 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3507 $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);
3509 } elseif (strtoupper($countrycode) ==
"AU") {
3513 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 1).$separ.substr($newphone, 4, 4).$separ.substr($newphone, 8, 4);
3515 } elseif (strtoupper($countrycode) ==
"LU") {
3518 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 2);
3520 $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);
3522 $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);
3524 $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);
3527 if (!empty($addlink)) {
3528 if ($addlink ==
'tel' || $conf->browser->layout ==
'phone' || (
isModEnabled(
'clicktodial') && !empty($conf->global->CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS))) {
3529 $newphoneform = $newphone;
3530 $newphone =
'<a href="tel:'.$phone.
'"';
3531 $newphone .=
'>'.$newphoneform.
'</a>';
3532 } elseif (
isModEnabled(
'clicktodial') && $addlink ==
'AC_TEL') {
3533 if (empty($user->clicktodial_loaded)) {
3534 $user->fetch_clicktodial();
3538 $urlmask =
'ErrorClickToDialModuleNotConfigured';
3539 if (!empty($conf->global->CLICKTODIAL_URL)) {
3540 $urlmask = $conf->global->CLICKTODIAL_URL;
3542 if (!empty($user->clicktodial_url)) {
3543 $urlmask = $user->clicktodial_url;
3546 $clicktodial_poste = (!empty($user->clicktodial_poste) ?urlencode($user->clicktodial_poste) :
'');
3547 $clicktodial_login = (!empty($user->clicktodial_login) ?urlencode($user->clicktodial_login) :
'');
3548 $clicktodial_password = (!empty($user->clicktodial_password) ?urlencode($user->clicktodial_password) :
'');
3550 $url = sprintf($urlmask, urlencode($phone), $clicktodial_poste, $clicktodial_login, $clicktodial_password);
3552 $substitarray = array(
'__PHONEFROM__'=>$clicktodial_poste,
3553 '__PHONETO__'=>urlencode($phone),
3554 '__LOGIN__'=>$clicktodial_login,
3555 '__PASS__'=>$clicktodial_password);
3557 $newphonesav = $newphone;
3558 if (empty($conf->global->CLICKTODIAL_DO_NOT_USE_AJAX_CALL)) {
3560 $newphone =
'<a href="'.$url.
'" class="cssforclicktodial"';
3561 $newphone .=
'>'.$newphonesav.
'</a>';
3564 $newphone =
'<a href="'.$url.
'"';
3565 if (!empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) {
3566 $newphone .=
' target="_blank" rel="noopener noreferrer"';
3568 $newphone .=
'>'.$newphonesav.
'</a>';
3573 if (
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
3576 if ($addlink ==
'AC_FAX') {
3579 if (!empty($conf->global->AGENDA_ADDACTIONFORPHONE)) {
3580 $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>';
3583 $newphone =
'<div>'.$newphone.
' '.$link.
'</div>';
3588 if (empty($titlealt)) {
3589 $titlealt = ($withpicto ==
'fax' ? $langs->trans(
"Fax") : $langs->trans(
"Phone"));
3594 $parameters = array(
'countrycode' => $countrycode,
'cid' => $cid,
'socid' => $socid,
'titlealt' => $titlealt,
'picto' => $withpicto);
3595 $reshook = $hookmanager->executeHooks(
'printPhone', $parameters, $phone);
3596 $rep .= $hookmanager->resPrint;
3598 if (empty($reshook)) {
3601 if ($withpicto ==
'fax') {
3602 $picto =
'phoning_fax';
3603 } elseif ($withpicto ==
'phone') {
3605 } elseif ($withpicto ==
'mobile') {
3606 $picto =
'phoning_mobile';
3611 if ($adddivfloat == 1) {
3612 $rep .=
'<div class="nospan float" style="margin-right: 10px">';
3613 } elseif (empty($adddivfloat)) {
3614 $rep .=
'<span style="margin-right: 10px;">';
3616 $rep .= ($withpicto ?
img_picto($titlealt,
'object_'.$picto.
'.png').
' ' :
'').$newphone;
3617 if ($adddivfloat == 1) {
3619 } elseif (empty($adddivfloat)) {
3636 global $conf, $langs;
3647 if (file_exists(DOL_DOCUMENT_ROOT.
'/theme/common/flags/'.$countrycode.
'.png')) {
3648 $ret .=
' '.img_picto($countrycode.
' '.$langs->trans(
"AccordingToGeoIPDatabase"), DOL_URL_ROOT.
'/theme/common/flags/'.$countrycode.
'.png',
'', 1);
3650 $ret .=
' ('.$countrycode.
')';
3670 if (empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) || preg_match(
'/[^0-9\.\:,\[\]]/', $_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
3671 if (empty($_SERVER[
'HTTP_CLIENT_IP']) || preg_match(
'/[^0-9\.\:,\[\]]/', $_SERVER[
'HTTP_CLIENT_IP'])) {
3672 if (empty($_SERVER[
"HTTP_CF_CONNECTING_IP"])) {
3673 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
3675 $ip = $_SERVER[
"HTTP_CF_CONNECTING_IP"];
3678 $ip = $_SERVER[
'HTTP_CLIENT_IP'];
3681 $ip = $_SERVER[
'HTTP_X_FORWARDED_FOR'];
3697 if (isset($_SERVER[
'HTTPS']) && $_SERVER[
'HTTPS'] ==
'on') {
3699 } 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') {
3717 if (!empty($conf->geoipmaxmind->enabled)) {
3721 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeoip.class.php';
3722 $geoip =
new DolGeoIP(
'country', $datafile);
3724 $countrycode = $geoip->getCountryCodeFromIP($ip);
3727 return $countrycode;
3739 global $conf, $langs, $user;
3743 if (!empty($conf->geoipmaxmind->enabled)) {
3748 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeoip.class.php';
3749 $geoip =
new DolGeoIP(
'country', $datafile);
3750 $countrycode = $geoip->getCountryCodeFromIP($ip);
3751 $ret = $countrycode;
3770 global $conf, $user, $langs, $hookmanager;
3776 $parameters = array(
'element' => $element,
'id' => $id);
3777 $reshook = $hookmanager->executeHooks(
'printAddress', $parameters, $address);
3778 $out .= $hookmanager->resPrint;
3780 if (empty($reshook)) {
3781 if (empty($charfornl)) {
3782 $out .= nl2br($address);
3784 $out .= preg_replace(
'/[\r\n]+/', $charfornl, $address);
3788 $showgmap = $showomap = 0;
3789 if (($element ==
'thirdparty' || $element ==
'societe') && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS)) {
3792 if ($element ==
'contact' && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS)) {
3795 if ($element ==
'member' && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS)) {
3798 if (($element ==
'thirdparty' || $element ==
'societe') && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS)) {
3801 if ($element ==
'contact' && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS)) {
3804 if ($element ==
'member' && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS)) {
3808 $url =
dol_buildpath(
'/google/gmaps.php?mode='.$element.
'&id='.$id, 1);
3809 $out .=
' <a href="'.$url.
'" target="_gmaps"><img id="'.$htmlid.
'" class="valigntextbottom" src="'.DOL_URL_ROOT.
'/theme/common/gmap.png"></a>';
3812 $url =
dol_buildpath(
'/openstreetmap/maps.php?mode='.$element.
'&id='.$id, 1);
3813 $out .=
' <a href="'.$url.
'" target="_gmaps"><img id="'.$htmlid.
'_openstreetmap" class="valigntextbottom" src="'.DOL_URL_ROOT.
'/theme/common/gmap.png"></a>';
3834 function isValidEmail($address, $acceptsupervisorkey = 0, $acceptuserkey = 0)
3836 if ($acceptsupervisorkey && $address ==
'__SUPERVISOREMAIL__') {
3839 if ($acceptuserkey && $address ==
'__USER_EMAIL__') {
3842 if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
3859 if (function_exists(
'idn_to_ascii') && function_exists(
'checkdnsrr')) {
3860 if (!checkdnsrr(idn_to_ascii($domain),
'MX')) {
3863 if (function_exists(
'getmxrr')) {
3866 getmxrr(idn_to_ascii($domain), $mxhosts, $weight);
3867 if (count($mxhosts) > 1) {
3870 if (count($mxhosts) == 1 && !empty($mxhosts[0])) {
3907 $tmparray = explode(
' ', $s);
3908 foreach ($tmparray as $tmps) {
3925 if (is_null($string)) {
3929 if (function_exists(
'mb_strlen')) {
3930 return mb_strlen($string, $stringencoding);
3932 return strlen($string);
3946 function dol_substr($string, $start, $length =
null, $stringencoding =
'', $trunconbytes = 0)
3950 if (empty($stringencoding)) {
3951 $stringencoding = $langs->charset_output;
3955 if (empty($trunconbytes)) {
3956 if (function_exists(
'mb_substr')) {
3957 $ret = mb_substr($string, $start, $length, $stringencoding);
3959 $ret = substr($string, $start, $length);
3962 if (function_exists(
'mb_strcut')) {
3963 $ret = mb_strcut($string, $start, $length, $stringencoding);
3965 $ret = substr($string, $start, $length);
3985 function dol_trunc($string, $size = 40, $trunc =
'right', $stringencoding =
'UTF-8', $nodot = 0, $display = 0)
3989 if (empty($size) || !empty($conf->global->MAIN_DISABLE_TRUNC)) {
3993 if (empty($stringencoding)) {
3994 $stringencoding =
'UTF-8';
3997 if ($conf->dol_optimize_smallscreen == 1 && $display == 1) {
3998 $size = round($size / 3);
4002 if ($trunc ==
'right') {
4004 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
4006 return dol_substr($newstring, 0, $size, $stringencoding).($nodot ?
'' :
'…');
4011 } elseif ($trunc ==
'middle') {
4013 if (
dol_strlen($newstring, $stringencoding) > 2 &&
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
4014 $size1 = round($size / 2);
4015 $size2 = round($size / 2);
4016 return dol_substr($newstring, 0, $size1, $stringencoding).
'…'.
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
4020 } elseif ($trunc ==
'left') {
4022 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
4024 return '…'.dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
4028 } elseif ($trunc ==
'wrap') {
4030 if (
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
4036 return 'BadParam3CallingDolTrunc';
4061 function img_picto($titlealt, $picto, $moreatt =
'', $pictoisfullpath =
false, $srconly = 0, $notitle = 0, $alt =
'', $morecss =
'', $marginleftonlyshort = 2)
4063 global $conf, $langs;
4066 $url = DOL_URL_ROOT;
4067 $theme = isset($conf->theme) ? $conf->theme :
null;
4068 $path =
'theme/'.$theme;
4070 if ($pictoisfullpath) {
4072 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
4075 $fullpathpicto = $picto;
4077 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
4078 $morecss .= ($morecss ?
' ' :
'').$reg[1];
4079 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
4082 $pictowithouttext = preg_replace(
'/(\.png|\.gif|\.svg)$/',
'', $picto);
4083 $pictowithouttext = str_replace(
'object_',
'', $pictowithouttext);
4084 $pictowithouttext = str_replace(
'_nocolor',
'', $pictowithouttext);
4086 if (strpos($pictowithouttext,
'fontawesome_') !==
false || preg_match(
'/^fa-/', $pictowithouttext)) {
4088 $pictowithouttext = str_replace(
'fontawesome_',
'', $pictowithouttext);
4089 $pictowithouttext = str_replace(
'fa-',
'', $pictowithouttext);
4091 $pictowithouttextarray = explode(
'_', $pictowithouttext);
4092 $marginleftonlyshort = 0;
4094 if (!empty($pictowithouttextarray[1])) {
4096 $fakey =
'fa-'.$pictowithouttextarray[0];
4097 $fa = empty($pictowithouttextarray[1]) ?
'fa' : $pictowithouttextarray[1];
4098 $facolor = empty($pictowithouttextarray[2]) ?
'' : $pictowithouttextarray[2];
4099 $fasize = empty($pictowithouttextarray[3]) ?
'' : $pictowithouttextarray[3];
4101 $fakey =
'fa-'.$pictowithouttext;
4111 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
4112 $morecss .= ($morecss ?
' ' :
'').$reg[1];
4113 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
4115 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
4116 $morestyle = $reg[1];
4117 $moreatt = str_replace(
'style="'.$reg[1].
'"',
'', $moreatt);
4119 $moreatt = trim($moreatt);
4121 $enabledisablehtml =
'<span class="'.$fa.
' '.$fakey.($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
4122 $enabledisablehtml .= ($morecss ?
' '.$morecss :
'').
'" style="'.($fasize ? (
'font-size: '.$fasize.
';') :
'').($facolor ? (
' color: '.$facolor.
';') :
'').($morestyle ?
' '.$morestyle :
'').
'"'.(($notitle || empty($titlealt)) ?
'' :
' title="'.
dol_escape_htmltag($titlealt).
'"').($moreatt ?
' '.$moreatt :
'').
'>';
4126 $enabledisablehtml .=
'</span>';
4128 return $enabledisablehtml;
4131 if (empty($srconly) && in_array($pictowithouttext, array(
4132 '1downarrow',
'1uparrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected',
4133 'accountancy',
'accounting_account',
'account',
'accountline',
'action',
'add',
'address',
'angle-double-down',
'angle-double-up',
'asset',
4134 'bank_account',
'barcode',
'bank',
'bell',
'bill',
'billa',
'billr',
'billd',
'birthday-cake',
'bookmark',
'bom',
'briefcase-medical',
'bug',
'building',
4135 'card',
'calendarlist',
'calendar',
'calendarmonth',
'calendarweek',
'calendarday',
'calendarperuser',
'calendarpertype',
4136 'cash-register',
'category',
'chart',
'check',
'clock',
'close_title',
'cog',
'collab',
'company',
'contact',
'country',
'contract',
'conversation',
'cron',
'cross',
'cubes',
4137 'currency',
'multicurrency',
4138 'delete',
'dolly',
'dollyrevert',
'donation',
'download',
'dynamicprice',
4139 'edit',
'ellipsis-h',
'email',
'entity',
'envelope',
'eraser',
'establishment',
'expensereport',
'external-link-alt',
'external-link-square-alt',
'eye',
4140 'filter',
'file-code',
'file-export',
'file-import',
'file-upload',
'autofill',
'folder',
'folder-open',
'folder-plus',
4141 'gears',
'generate',
'globe',
'globe-americas',
'graph',
'grip',
'grip_title',
'group',
4142 'hands-helping',
'help',
'holiday',
4143 'id-card',
'images',
'incoterm',
'info',
'intervention',
'inventory',
'intracommreport',
'jobprofile',
4144 'knowledgemanagement',
4145 'label',
'language',
'line',
'link',
'list',
'list-alt',
'listlight',
'loan',
'lock',
'lot',
'long-arrow-alt-right',
4146 'margin',
'map-marker-alt',
'member',
'meeting',
'money-bill-alt',
'movement',
'mrp',
'note',
'next',
4147 'off',
'on',
'order',
4148 'paiment',
'paragraph',
'play',
'pdf',
'phone',
'phoning',
'phoning_mobile',
'phoning_fax',
'playdisabled',
'previous',
'poll',
'pos',
'printer',
'product',
'propal',
'proposal',
'puce',
4149 'stock',
'resize',
'service',
'stats',
'trip',
4150 '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',
4151 'github',
'google',
'jabber',
'microsoft',
'skype',
'twitter',
'facebook',
'linkedin',
'instagram',
'snapchat',
'youtube',
'google-plus-g',
'whatsapp',
4152 'chevron-left',
'chevron-right',
'chevron-down',
'chevron-top',
'commercial',
'companies',
4153 'generic',
'home',
'hrm',
'members',
'products',
'invoicing',
4154 'partnership',
'payment',
'payment_vat',
'pencil-ruler',
'pictoconfirm',
'preview',
'project',
'projectpub',
'projecttask',
'question',
'refresh',
'region',
4155 'salary',
'shipment',
'state',
'supplier_invoice',
'supplier_invoicea',
'supplier_invoicer',
'supplier_invoiced',
4156 'technic',
'ticket',
4158 'recent',
'reception',
'recruitmentcandidature',
'recruitmentjobposition',
'replacement',
'resource',
'recurring',
'rss',
4159 'shapes',
'skill',
'square',
'stop-circle',
'supplier',
'supplier_proposal',
'supplier_order',
'supplier_invoice',
4160 'timespent',
'title_setup',
'title_accountancy',
'title_bank',
'title_hrm',
'title_agenda',
4161 'uncheck',
'url',
'user-cog',
'user-injured',
'user-md',
'vat',
'website',
'workstation',
'webhook',
'world',
'private',
4162 'conferenceorbooth',
'eventorganization',
4163 'stamp',
'signature'
4165 $fakey = $pictowithouttext;
4169 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'))) {
4172 if (in_array($pictowithouttext, array(
'black-tie',
'github',
'google',
'microsoft',
'skype',
'twitter',
'facebook',
'linkedin',
'instagram',
'snapchat',
'stripe',
'stripe-s',
'youtube',
'google-plus-g',
'whatsapp'))) {
4176 $arrayconvpictotofa = array(
4177 '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',
4178 'bank_account'=>
'university',
4179 'bill'=>
'file-invoice-dollar',
'billa'=>
'file-excel',
'billr'=>
'file-invoice-dollar',
'billd'=>
'file-medical',
4180 'supplier_invoice'=>
'file-invoice-dollar',
'supplier_invoicea'=>
'file-excel',
'supplier_invoicer'=>
'file-invoice-dollar',
'supplier_invoiced'=>
'file-medical',
4182 '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',
4183 'donation'=>
'file-alt',
'dynamicprice'=>
'hand-holding-usd',
4184 'setup'=>
'cog',
'companies'=>
'building',
'products'=>
'cube',
'commercial'=>
'suitcase',
'invoicing'=>
'coins',
4185 'accounting'=>
'search-dollar',
'category'=>
'tag',
'dollyrevert'=>
'dolly',
4186 'generate'=>
'plus-square',
'hrm'=>
'user-tie',
'incoterm'=>
'truck-loading',
4187 'margin'=>
'calculator',
'members'=>
'user-friends',
'ticket'=>
'ticket-alt',
'globe'=>
'external-link-alt',
'lot'=>
'barcode',
4188 'email'=>
'at',
'establishment'=>
'building',
'edit'=>
'pencil-alt',
'entity'=>
'globe',
4189 'graph'=>
'chart-line',
'grip_title'=>
'arrows-alt',
'grip'=>
'arrows-alt',
'help'=>
'question-circle',
4190 'generic'=>
'file',
'holiday'=>
'umbrella-beach',
4191 'info'=>
'info-circle',
'inventory'=>
'boxes',
'intracommreport'=>
'globe-europe',
'jobprofile'=>
'cogs',
4192 'knowledgemanagement'=>
'ticket-alt',
'label'=>
'layer-group',
'line'=>
'bars',
'loan'=>
'money-bill-alt',
4193 'member'=>
'user-alt',
'meeting'=>
'chalkboard-teacher',
'mrp'=>
'cubes',
'next'=>
'arrow-alt-circle-right',
4194 'trip'=>
'wallet',
'expensereport'=>
'wallet',
'group'=>
'users',
'movement'=>
'people-carry',
4195 'sign-out'=>
'sign-out-alt',
4196 'switch_off'=>
'toggle-off',
'switch_on'=>
'toggle-on',
'switch_on_warning'=>
'toggle-on',
'switch_on_red'=>
'toggle-on',
'check'=>
'check',
'bookmark'=>
'star',
4197 'bank'=>
'university',
'close_title'=>
'times',
'delete'=>
'trash',
'filter'=>
'filter',
4198 'list-alt'=>
'list-alt',
'calendarlist'=>
'bars',
'calendar'=>
'calendar-alt',
'calendarmonth'=>
'calendar-alt',
'calendarweek'=>
'calendar-week',
'calendarday'=>
'calendar-day',
'calendarperuser'=>
'table',
4199 'intervention'=>
'ambulance',
'invoice'=>
'file-invoice-dollar',
'currency'=>
'dollar-sign',
'multicurrency'=>
'dollar-sign',
'order'=>
'file-invoice',
4200 'error'=>
'exclamation-triangle',
'warning'=>
'exclamation-triangle',
4202 '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',
4203 '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',
4204 'recent' =>
'check-square',
'reception'=>
'dolly',
'recruitmentjobposition'=>
'id-card-alt',
'recruitmentcandidature'=>
'id-badge',
4205 'resize'=>
'crop',
'supplier_order'=>
'dol-order_supplier',
'supplier_proposal'=>
'file-signature',
4206 'refresh'=>
'redo',
'region'=>
'map-marked',
'replacement'=>
'exchange-alt',
'resource'=>
'laptop-house',
'recurring'=>
'history',
4207 'service'=>
'concierge-bell',
4208 'skill'=>
'shapes',
'state'=>
'map-marked-alt',
'security'=>
'key',
'salary'=>
'wallet',
'shipment'=>
'dolly',
'stock'=>
'box-open',
'stats' =>
'chart-bar',
'split'=>
'code-branch',
'stripe'=>
'stripe-s',
4209 'supplier'=>
'building',
'technic'=>
'cogs',
4210 'timespent'=>
'clock',
'title_setup'=>
'tools',
'title_accountancy'=>
'money-check-alt',
'title_bank'=>
'university',
'title_hrm'=>
'umbrella-beach',
4211 'title_agenda'=>
'calendar-alt',
4212 'uncheck'=>
'times',
'uparrow'=>
'share',
'url'=>
'external-link-alt',
'vat'=>
'money-check-alt',
'vcard'=>
'arrow-alt-circle-down',
4213 'jabber'=>
'comment-o',
4214 'website'=>
'globe-americas',
'workstation'=>
'pallet',
'webhook'=>
'bullseye',
'world'=>
'globe',
'private'=>
'user-lock',
4215 'conferenceorbooth'=>
'chalkboard-teacher',
'eventorganization'=>
'project-diagram'
4217 if ($pictowithouttext ==
'off') {
4218 $fakey =
'fa-square';
4220 } elseif ($pictowithouttext ==
'on') {
4221 $fakey =
'fa-check-square';
4223 } elseif ($pictowithouttext ==
'listlight') {
4224 $fakey =
'fa-download';
4225 $marginleftonlyshort = 1;
4226 } elseif ($pictowithouttext ==
'printer') {
4227 $fakey =
'fa-print';
4229 } elseif ($pictowithouttext ==
'note') {
4230 $fakey =
'fa-sticky-note';
4231 $marginleftonlyshort = 1;
4232 } elseif (in_array($pictowithouttext, array(
'1uparrow',
'1downarrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected'))) {
4233 $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');
4234 $fakey =
'fa-'.$convertarray[$pictowithouttext];
4235 if (preg_match(
'/selected/', $pictowithouttext)) {
4238 $marginleftonlyshort = 1;
4239 } elseif (!empty($arrayconvpictotofa[$pictowithouttext])) {
4240 $fakey =
'fa-'.$arrayconvpictotofa[$pictowithouttext];
4242 $fakey =
'fa-'.$pictowithouttext;
4245 if (in_array($pictowithouttext, array(
'dollyrevert',
'member',
'members',
'contract',
'group',
'resource',
'shipment'))) {
4246 $morecss .=
' em092';
4248 if (in_array($pictowithouttext, array(
'conferenceorbooth',
'collab',
'eventorganization',
'holiday',
'info',
'project',
'workstation'))) {
4249 $morecss .=
' em088';
4251 if (in_array($pictowithouttext, array(
'asset',
'intervention',
'payment',
'loan',
'partnership',
'stock',
'technic'))) {
4252 $morecss .=
' em080';
4256 $arrayconvpictotomarginleftonly = array(
4257 'bank',
'check',
'delete',
'generic',
'grip',
'grip_title',
'jabber',
4258 'grip_title',
'grip',
'listlight',
'note',
'on',
'off',
'playdisabled',
'printer',
'resize',
'sign-out',
'stats',
'switch_on',
'switch_on_red',
'switch_off',
4259 'uparrow',
'1uparrow',
'1downarrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected'
4261 if (!isset($arrayconvpictotomarginleftonly[$pictowithouttext])) {
4262 $marginleftonlyshort = 0;
4266 $arrayconvpictotomorcess = array(
4267 'action'=>
'infobox-action',
'account'=>
'infobox-bank_account',
'accounting_account'=>
'infobox-bank_account',
'accountline'=>
'infobox-bank_account',
'accountancy'=>
'infobox-bank_account',
'asset'=>
'infobox-bank_account',
4268 'bank_account'=>
'infobox-bank_account',
4269 'bill'=>
'infobox-commande',
'billa'=>
'infobox-commande',
'billr'=>
'infobox-commande',
'billd'=>
'infobox-commande',
4270 'margin'=>
'infobox-bank_account',
'conferenceorbooth'=>
'infobox-project',
4271 'cash-register'=>
'infobox-bank_account',
'contract'=>
'infobox-contrat',
'check'=>
'font-status4',
'collab'=>
'infobox-action',
'conversation'=>
'infobox-contrat',
4272 'donation'=>
'infobox-commande',
'dolly'=>
'infobox-commande',
'dollyrevert'=>
'flip infobox-order_supplier',
4273 'ecm'=>
'infobox-action',
'eventorganization'=>
'infobox-project',
4274 'hrm'=>
'infobox-adherent',
'group'=>
'infobox-adherent',
'intervention'=>
'infobox-contrat',
4275 'incoterm'=>
'infobox-supplier_proposal',
4276 'currency'=>
'infobox-bank_account',
'multicurrency'=>
'infobox-bank_account',
4277 'members'=>
'infobox-adherent',
'member'=>
'infobox-adherent',
'money-bill-alt'=>
'infobox-bank_account',
4278 'order'=>
'infobox-commande',
4279 'user'=>
'infobox-adherent',
'users'=>
'infobox-adherent',
4280 'error'=>
'pictoerror',
'warning'=>
'pictowarning',
'switch_on'=>
'font-status4',
'switch_on_warning'=>
'font-status4 warning',
'switch_on_red'=>
'font-status8',
4281 'holiday'=>
'infobox-holiday',
'info'=>
'opacityhigh',
'invoice'=>
'infobox-commande',
4282 'knowledgemanagement'=>
'infobox-contrat rotate90',
'loan'=>
'infobox-bank_account',
4283 'payment'=>
'infobox-bank_account',
'payment_vat'=>
'infobox-bank_account',
'poll'=>
'infobox-adherent',
'pos'=>
'infobox-bank_account',
'project'=>
'infobox-project',
'projecttask'=>
'infobox-project',
4284 'propal'=>
'infobox-propal',
'proposal'=>
'infobox-propal',
'private'=>
'infobox-project',
4285 'reception'=>
'flip',
'recruitmentjobposition'=>
'infobox-adherent',
'recruitmentcandidature'=>
'infobox-adherent',
4286 'resource'=>
'infobox-action',
4287 'salary'=>
'infobox-bank_account',
'shipment'=>
'infobox-commande',
'supplier_invoice'=>
'infobox-order_supplier',
'supplier_invoicea'=>
'infobox-order_supplier',
'supplier_invoiced'=>
'infobox-order_supplier',
4288 'supplier'=>
'infobox-order_supplier',
'supplier_order'=>
'infobox-order_supplier',
'supplier_proposal'=>
'infobox-supplier_proposal',
4289 'ticket'=>
'infobox-contrat',
'title_accountancy'=>
'infobox-bank_account',
'title_hrm'=>
'infobox-holiday',
'expensereport'=>
'infobox-expensereport',
'trip'=>
'infobox-expensereport',
'title_agenda'=>
'infobox-action',
4290 'vat'=>
'infobox-bank_account',
4292 'list-alt'=>
'imgforviewmode',
'calendar'=>
'imgforviewmode',
'calendarweek'=>
'imgforviewmode',
'calendarmonth'=>
'imgforviewmode',
'calendarday'=>
'imgforviewmode',
'calendarperuser'=>
'imgforviewmode'
4294 if (!empty($arrayconvpictotomorcess[$pictowithouttext]) && strpos($picto,
'_nocolor') ===
false) {
4295 $morecss .= ($morecss ?
' ' :
'').$arrayconvpictotomorcess[$pictowithouttext];
4299 $arrayconvpictotocolor = array(
4300 'address'=>
'#6c6aa8',
'building'=>
'#6c6aa8',
'bom'=>
'#a69944',
4301 'cog'=>
'#999',
'companies'=>
'#6c6aa8',
'company'=>
'#6c6aa8',
'contact'=>
'#6c6aa8',
'cron'=>
'#555',
4302 'dynamicprice'=>
'#a69944',
4303 'edit'=>
'#444',
'note'=>
'#999',
'error'=>
'',
'help'=>
'#bbb',
'listlight'=>
'#999',
'language'=>
'#555',
4305 'lock'=>
'#ddd',
'lot'=>
'#a69944',
4306 'map-marker-alt'=>
'#aaa',
'mrp'=>
'#a69944',
'product'=>
'#a69944',
'service'=>
'#a69944',
'inventory'=>
'#a69944',
'stock'=>
'#a69944',
'movement'=>
'#a69944',
4307 'other'=>
'#ddd',
'world'=>
'#986c6a',
4308 'partnership'=>
'#6c6aa8',
'playdisabled'=>
'#ccc',
'printer'=>
'#444',
'projectpub'=>
'#986c6a',
'reception'=>
'#a69944',
'resize'=>
'#444',
'rss'=>
'#cba',
4310 'security'=>
'#999',
'square'=>
'#888',
'stop-circle'=>
'#888',
'stats'=>
'#444',
'switch_off'=>
'#999',
'technic'=>
'#999',
'timespent'=>
'#555',
4311 'uncheck'=>
'#800',
'uparrow'=>
'#555',
'user-cog'=>
'#999',
'country'=>
'#aaa',
'globe-americas'=>
'#aaa',
'region'=>
'#aaa',
'state'=>
'#aaa',
4312 'website'=>
'#304',
'workstation'=>
'#a69944'
4314 if (isset($arrayconvpictotocolor[$pictowithouttext]) && strpos($picto,
'_nocolor') ===
false) {
4315 $facolor = $arrayconvpictotocolor[$pictowithouttext];
4322 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
4323 $morecss .= ($morecss ?
' ' :
'').$reg[1];
4324 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
4326 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
4327 $morestyle = $reg[1];
4328 $moreatt = str_replace(
'style="'.$reg[1].
'"',
'', $moreatt);
4330 $moreatt = trim($moreatt);
4332 $enabledisablehtml =
'<span class="'.$fa.
' '.$fakey.($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
4333 $enabledisablehtml .= ($morecss ?
' '.$morecss :
'').
'" style="'.($fasize ? (
'font-size: '.$fasize.
';') :
'').($facolor ? (
' color: '.$facolor.
';') :
'').($morestyle ?
' '.$morestyle :
'').
'"'.(($notitle || empty($titlealt)) ?
'' :
' title="'.
dol_escape_htmltag($titlealt).
'"').($moreatt ?
' '.$moreatt :
'').
'>';
4337 $enabledisablehtml .=
'</span>';
4339 return $enabledisablehtml;
4342 if (!empty($conf->global->MAIN_OVERWRITE_THEME_PATH)) {
4343 $path = $conf->global->MAIN_OVERWRITE_THEME_PATH.
'/theme/'.$theme;
4344 } elseif (!empty($conf->global->MAIN_OVERWRITE_THEME_RES)) {
4345 $path = $conf->global->MAIN_OVERWRITE_THEME_RES.
'/theme/'.$conf->global->MAIN_OVERWRITE_THEME_RES;
4346 } elseif (!empty($conf->modules_parts[
'theme']) && array_key_exists($theme, $conf->modules_parts[
'theme'])) {
4347 $path = $theme.
'/theme/'.$theme;
4352 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $picto, $regs)) {
4358 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
4363 foreach ($conf->file->dol_document_root as $type => $dirroot) {
4364 if ($type ==
'main') {
4368 if (file_exists($dirroot.
'/'.$path.
'/img/'.$picto)) {
4369 $url = DOL_URL_ROOT.$conf->file->dol_url_root[$type];
4375 $fullpathpicto = $url.
'/'.$path.
'/img/'.$picto;
4379 return $fullpathpicto;
4382 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 :
'').
'"').
'>';
4398 function img_object($titlealt, $picto, $moreatt =
'', $pictoisfullpath =
false, $srconly = 0, $notitle = 0)
4400 if (strpos($picto,
'^') === 0) {
4401 return img_picto($titlealt, str_replace(
'^',
'', $picto), $moreatt, $pictoisfullpath, $srconly, $notitle);
4403 return img_picto($titlealt,
'object_'.$picto, $moreatt, $pictoisfullpath, $srconly, $notitle);
4418 function img_weather($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $morecss =
'')
4422 if (is_numeric($picto)) {
4425 return '<i class="fa fa-weather-level'.$picto.
'"></i>';
4426 } elseif (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
4430 $path = DOL_URL_ROOT.
'/theme/'.$conf->theme.
'/img/weather/'.$picto;
4432 return img_picto($titlealt, $path, $moreatt, 1, 0, 0,
'', $morecss);
4446 function img_picto_common($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $notitle = 0)
4450 if (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
4454 if ($pictoisfullpath) {
4457 $path = DOL_URL_ROOT.
'/theme/common/'.$picto;
4459 if (!empty($conf->global->MAIN_MODULE_CAN_OVERWRITE_COMMONICONS)) {
4460 $themepath = DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/img/'.$picto;
4462 if (file_exists($themepath)) {
4468 return img_picto($titlealt, $path, $moreatt, 1, 0, $notitle);
4487 if (empty($titlealt) || $titlealt ==
'default') {
4488 if ($numaction ==
'-1' || $numaction ==
'ST_NO') {
4490 $titlealt = $langs->transnoentitiesnoconv(
'ChangeDoNotContact');
4491 } elseif ($numaction ==
'0' || $numaction ==
'ST_NEVER') {
4493 $titlealt = $langs->transnoentitiesnoconv(
'ChangeNeverContacted');
4494 } elseif ($numaction ==
'1' || $numaction ==
'ST_TODO') {
4496 $titlealt = $langs->transnoentitiesnoconv(
'ChangeToContact');
4497 } elseif ($numaction ==
'2' || $numaction ==
'ST_PEND') {
4499 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactInProcess');
4500 } elseif ($numaction ==
'3' || $numaction ==
'ST_DONE') {
4502 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactDone');
4504 $titlealt = $langs->transnoentitiesnoconv(
'ChangeStatus '.$numaction);
4508 if (!is_numeric($numaction)) {
4512 return img_picto($titlealt, !empty($picto) ? $picto :
'stcomm'.$numaction.
'.png');
4522 function img_pdf($titlealt =
'default', $size = 3)
4526 if ($titlealt ==
'default') {
4527 $titlealt = $langs->trans(
'Show');
4530 return img_picto($titlealt,
'pdf'.$size.
'.png');
4544 if ($titlealt ==
'default') {
4545 $titlealt = $langs->trans(
'Add');
4548 return img_picto($titlealt,
'edit_add.png', $other);
4561 if ($titlealt ==
'default') {
4562 $titlealt = $langs->trans(
'Remove');
4565 return img_picto($titlealt,
'edit_remove.png', $other);
4576 function img_edit($titlealt =
'default', $float = 0, $other =
'')
4580 if ($titlealt ==
'default') {
4581 $titlealt = $langs->trans(
'Modify');
4584 return img_picto($titlealt,
'edit.png', ($float ?
'style="float: '.($langs->tab_translate[
"DIRECTION"] ==
'rtl' ?
'left' :
'right').
'"' :
"").($other ?
' '.$other :
''));
4595 function img_view($titlealt =
'default', $float = 0, $other =
'class="valignmiddle"')
4599 if ($titlealt ==
'default') {
4600 $titlealt = $langs->trans(
'View');
4603 $moreatt = ($float ?
'style="float: right" ' :
'').$other;
4605 return img_picto($titlealt,
'eye', $moreatt);
4616 function img_delete($titlealt =
'default', $other =
'class="pictodelete"', $morecss =
'')
4620 if ($titlealt ==
'default') {
4621 $titlealt = $langs->trans(
'Delete');
4624 return img_picto($titlealt,
'delete.png', $other,
false, 0, 0,
'', $morecss);
4637 if ($titlealt ==
"default") {
4638 $titlealt = $langs->trans(
"Print");
4640 return img_picto($titlealt,
'printer.png', $other);
4650 function img_split($titlealt =
'default', $other =
'class="pictosplit"')
4654 if ($titlealt ==
'default') {
4655 $titlealt = $langs->trans(
'Split');
4658 return img_picto($titlealt,
'split.png', $other);
4668 function img_help($usehelpcursor = 1, $usealttitle = 1)
4673 if (is_string($usealttitle)) {
4676 $usealttitle = $langs->trans(
'Info');
4680 return img_picto($usealttitle,
'info.png',
'style="vertical-align: middle;'.($usehelpcursor == 1 ?
' cursor: help' : ($usehelpcursor == 2 ?
' cursor: pointer' :
'')).
'"');
4693 if ($titlealt ==
'default') {
4694 $titlealt = $langs->trans(
'Informations');
4697 return img_picto($titlealt,
'info.png',
'style="vertical-align: middle;"');
4708 function img_warning($titlealt =
'default', $moreatt =
'', $morecss =
'pictowarning')
4712 if ($titlealt ==
'default') {
4713 $titlealt = $langs->trans(
'Warning');
4717 return img_picto($titlealt,
'warning.png',
'class="'.$morecss.
'"'.($moreatt ? ($moreatt ==
'1' ?
' style="float: right"' :
' '.$moreatt) :
''));
4730 if ($titlealt ==
'default') {
4731 $titlealt = $langs->trans(
'Error');
4734 return img_picto($titlealt,
'error.png');
4744 function img_next($titlealt =
'default', $moreatt =
'')
4748 if ($titlealt ==
'default') {
4749 $titlealt = $langs->trans(
'Next');
4753 return '<span class="fa fa-chevron-right paddingright paddingleft" title="'.dol_escape_htmltag($titlealt).
'"></span>';
4767 if ($titlealt ==
'default') {
4768 $titlealt = $langs->trans(
'Previous');
4772 return '<span class="fa fa-chevron-left paddingright paddingleft" title="'.dol_escape_htmltag($titlealt).
'"></span>';
4783 function img_down($titlealt =
'default', $selected = 0, $moreclass =
'')
4787 if ($titlealt ==
'default') {
4788 $titlealt = $langs->trans(
'Down');
4791 return img_picto($titlealt, ($selected ?
'1downarrow_selected.png' :
'1downarrow.png'),
'class="imgdown'.($moreclass ?
" ".$moreclass :
"").
'"');
4802 function img_up($titlealt =
'default', $selected = 0, $moreclass =
'')
4806 if ($titlealt ==
'default') {
4807 $titlealt = $langs->trans(
'Up');
4810 return img_picto($titlealt, ($selected ?
'1uparrow_selected.png' :
'1uparrow.png'),
'class="imgup'.($moreclass ?
" ".$moreclass :
"").
'"');
4821 function img_left($titlealt =
'default', $selected = 0, $moreatt =
'')
4825 if ($titlealt ==
'default') {
4826 $titlealt = $langs->trans(
'Left');
4829 return img_picto($titlealt, ($selected ?
'1leftarrow_selected.png' :
'1leftarrow.png'), $moreatt);
4840 function img_right($titlealt =
'default', $selected = 0, $moreatt =
'')
4844 if ($titlealt ==
'default') {
4845 $titlealt = $langs->trans(
'Right');
4848 return img_picto($titlealt, ($selected ?
'1rightarrow_selected.png' :
'1rightarrow.png'), $moreatt);
4862 if ($titlealt ==
'default') {
4863 $titlealt = $langs->trans(
'Active');
4867 return img_picto($titlealt,
'tick.png');
4882 if (is_null($morecss)) {
4886 if ($brand ==
'visa' || $brand ==
'Visa') {
4888 } elseif ($brand ==
'mastercard' || $brand ==
'MasterCard') {
4889 $brand =
'cc-mastercard';
4890 } elseif ($brand ==
'amex' || $brand ==
'American Express') {
4892 } elseif ($brand ==
'discover' || $brand ==
'Discover') {
4893 $brand =
'cc-discover';
4894 } elseif ($brand ==
'jcb' || $brand ==
'JCB') {
4896 } elseif ($brand ==
'diners' || $brand ==
'Diners club') {
4897 $brand =
'cc-diners-club';
4898 } elseif (!in_array($brand, array(
'cc-visa',
'cc-mastercard',
'cc-amex',
'cc-discover',
'cc-jcb',
'cc-diners-club'))) {
4899 $brand =
'credit-card';
4902 return '<span class="fa fa-'.$brand.
' fa-fw'.($morecss ?
' '.$morecss :
'').
'"></span>';
4913 function img_mime($file, $titlealt =
'', $morecss =
'')
4915 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
4921 if (empty($titlealt)) {
4922 $titlealt =
'Mime type: '.$mimetype;
4926 return '<i class="fa fa-'.$mimefa.
' paddingright'.($morecss ?
' '.$morecss :
'').
'"'.($titlealt ?
' title="'.$titlealt.
'"' :
'').
'></i>';
4939 global $conf, $langs;
4941 if ($titlealt ==
'default') {
4942 $titlealt = $langs->trans(
'Search');
4945 $img =
img_picto($titlealt,
'search.png', $other,
false, 1);
4947 $input =
'<input type="image" class="liste_titre" name="button_search" src="'.$img.
'" ';
4948 $input .=
'value="'.dol_escape_htmltag($titlealt).
'" title="'.
dol_escape_htmltag($titlealt).
'" >';
4962 global $conf, $langs;
4964 if ($titlealt ==
'default') {
4965 $titlealt = $langs->trans(
'Search');
4968 $img =
img_picto($titlealt,
'searchclear.png', $other,
false, 1);
4970 $input =
'<input type="image" class="liste_titre" name="button_removefilter" src="'.$img.
'" ';
4971 $input .=
'value="'.dol_escape_htmltag($titlealt).
'" title="'.
dol_escape_htmltag($titlealt).
'" >';
4987 function info_admin($text, $infoonimgalt = 0, $nodiv = 0, $admin =
'1', $morecss =
'hideonsmartphone', $textfordropdown =
'')
4989 global $conf, $langs;
4991 if ($infoonimgalt) {
4992 $result =
img_picto($text,
'info',
'class="'.($morecss ?
' '.$morecss :
'').
'"');
4994 if (empty($conf->use_javascript_ajax)) {
4995 $textfordropdown =
'';
4998 $class = (empty($admin) ?
'undefined' : ($admin ==
'1' ?
'info' : $admin));
4999 $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>');
5001 if ($textfordropdown) {
5002 $tmpresult =
'<span class="'.$class.
'text opacitymedium cursorpointer">'.$langs->trans($textfordropdown).
' '.
img_picto($langs->trans($textfordropdown),
'1downarrow').
'</span>';
5003 $tmpresult .=
'<script nonce="'.getNonce().
'" type="text/javascript">
5004 jQuery(document).ready(function() {
5005 jQuery(".'.$class.
'text").click(function() {
5006 console.log("toggle text");
5007 jQuery(".'.$class.
'").toggle();
5012 $result = $tmpresult.$result;
5033 global $conf, $langs, $argv;
5034 global $dolibarr_main_prod;
5041 require_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
5043 $langs->load(
"main");
5047 $langs->loadLangs(array(
'main',
'errors'));
5049 if ($_SERVER[
'DOCUMENT_ROOT']) {
5050 $out .= $langs->trans(
"DolibarrHasDetectedError").
".<br>\n";
5052 $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";
5054 $out .= $langs->trans(
"InformationToHelpDiagnose").
":<br>\n";
5056 $out .=
"<b>".$langs->trans(
"Date").
":</b> ".
dol_print_date(time(),
'dayhourlog').
"<br>\n";
5057 $out .=
"<b>".$langs->trans(
"Dolibarr").
":</b> ".DOL_VERSION.
" - https://www.dolibarr.org<br>\n";
5058 if (isset($conf->global->MAIN_FEATURES_LEVEL)) {
5059 $out .=
"<b>".$langs->trans(
"LevelOfFeature").
":</b> ".
getDolGlobalInt(
'MAIN_FEATURES_LEVEL').
"<br>\n";
5061 if (function_exists(
"phpversion")) {
5062 $out .=
"<b>".$langs->trans(
"PHP").
":</b> ".phpversion().
"<br>\n";
5064 $out .=
"<b>".$langs->trans(
"Server").
":</b> ".(isset($_SERVER[
"SERVER_SOFTWARE"]) ?
dol_htmlentities($_SERVER[
"SERVER_SOFTWARE"], ENT_COMPAT) :
'').
"<br>\n";
5065 if (function_exists(
"php_uname")) {
5066 $out .=
"<b>".$langs->trans(
"OS").
":</b> ".php_uname().
"<br>\n";
5068 $out .=
"<b>".$langs->trans(
"UserAgent").
":</b> ".(isset($_SERVER[
"HTTP_USER_AGENT"]) ?
dol_htmlentities($_SERVER[
"HTTP_USER_AGENT"], ENT_COMPAT) :
'').
"<br>\n";
5070 $out .=
"<b>".$langs->trans(
"RequestedUrl").
":</b> ".
dol_htmlentities($_SERVER[
"REQUEST_URI"], ENT_COMPAT).
"<br>\n";
5071 $out .=
"<b>".$langs->trans(
"Referer").
":</b> ".(isset($_SERVER[
"HTTP_REFERER"]) ?
dol_htmlentities($_SERVER[
"HTTP_REFERER"], ENT_COMPAT) :
'').
"<br>\n";
5072 $out .=
"<b>".$langs->trans(
"MenuManager").
":</b> ".(isset($conf->standard_menu) ?
dol_htmlentities($conf->standard_menu, ENT_COMPAT) :
'').
"<br>\n";
5074 $syslog .=
"url=".dol_escape_htmltag($_SERVER[
"REQUEST_URI"]);
5075 $syslog .=
", query_string=".dol_escape_htmltag($_SERVER[
"QUERY_STRING"]);
5077 $out .=
'> '.$langs->transnoentities(
"ErrorInternalErrorDetected").
":\n".$argv[0].
"\n";
5078 $syslog .=
"pid=".dol_getmypid();
5081 if (!empty($conf->modules)) {
5082 $out .=
"<b>".$langs->trans(
"Modules").
":</b> ".join(
', ', $conf->modules).
"<br>\n";
5085 if (is_object($db)) {
5086 if ($_SERVER[
'DOCUMENT_ROOT']) {
5087 $out .=
"<b>".$langs->trans(
"DatabaseTypeManager").
":</b> ".$db->type.
"<br>\n";
5088 $lastqueryerror = $db->lastqueryerror();
5090 $lastqueryerror =
"SQL error string is not a valid UTF8 string. We can't show it.";
5092 $out .=
"<b>".$langs->trans(
"RequestLastAccessInError").
":</b> ".($lastqueryerror ?
dol_escape_htmltag($lastqueryerror) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
5093 $out .=
"<b>".$langs->trans(
"ReturnCodeLastAccessInError").
":</b> ".($db->lasterrno() ?
dol_escape_htmltag($db->lasterrno()) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
5094 $out .=
"<b>".$langs->trans(
"InformationLastAccessInError").
":</b> ".($db->lasterror() ?
dol_escape_htmltag($db->lasterror()) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
5098 $out .=
'> '.$langs->transnoentities(
"DatabaseTypeManager").
":\n".$db->type.
"\n";
5099 $out .=
'> '.$langs->transnoentities(
"RequestLastAccessInError").
":\n".($db->lastqueryerror() ? $db->lastqueryerror() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
5100 $out .=
'> '.$langs->transnoentities(
"ReturnCodeLastAccessInError").
":\n".($db->lasterrno() ? $db->lasterrno() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
5101 $out .=
'> '.$langs->transnoentities(
"InformationLastAccessInError").
":\n".($db->lasterror() ? $db->lasterror() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
5103 $syslog .=
", sql=".$db->lastquery();
5104 $syslog .=
", db_error=".$db->lasterror();
5107 if ($error || $errors) {
5108 $langs->load(
"errors");
5111 if (is_array($error) && is_array($errors)) {
5112 $errors = array_merge($error, $errors);
5113 } elseif (is_array($error)) {
5115 } elseif (is_array($errors)) {
5116 $errors = array_merge(array($error), $errors);
5118 $errors = array_merge(array($error), array($errors));
5121 foreach ($errors as $msg) {
5125 if ($_SERVER[
'DOCUMENT_ROOT']) {
5129 $out .=
'> '.$langs->transnoentities(
"Message").
":\n".$msg.
"\n";
5131 $syslog .=
", msg=".$msg;
5134 if (empty($dolibarr_main_prod) && $_SERVER[
'DOCUMENT_ROOT'] && function_exists(
'xdebug_print_function_stack') && function_exists(
'xdebug_call_file')) {
5135 xdebug_print_function_stack();
5136 $out .=
'<b>XDebug informations:</b>'.
"<br>\n";
5137 $out .=
'File: '.xdebug_call_file().
"<br>\n";
5138 $out .=
'Line: '.xdebug_call_line().
"<br>\n";
5139 $out .=
'Function: '.xdebug_call_function().
"<br>\n";
5144 if (!headers_sent()) {
5145 if (function_exists(
'top_httphead')) {
5148 http_response_code(500);
5151 if (empty($dolibarr_main_prod)) {
5154 if (empty($langs->defaultlang)) {
5155 $langs->setDefaultLang();
5157 $langs->loadLangs(array(
"main",
"errors"));
5159 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";
5160 print $langs->trans(
"DolibarrHasDetectedError").
'. ';
5161 print $langs->trans(
"YouCanSetOptionDolibarrMainProdToZero");
5162 define(
"MAIN_CORE_ERROR", 1);
5178 function dol_print_error_email($prefixcode, $errormessage =
'', $errormessages = array(), $morecss =
'error', $email =
'')
5180 global $langs, $conf;
5182 if (empty($email)) {
5183 $email = $conf->global->MAIN_INFO_SOCIETE_MAIL;
5186 $langs->load(
"errors");
5189 print
'<br><div class="center login_main_message"><div class="'.$morecss.
'">';
5190 print $langs->trans(
"ErrorContactEMail", $email, $prefixcode.dol_print_date($now,
'%Y%m%d%H%M%S'));
5191 if ($errormessage) {
5192 print
'<br><br>'.$errormessage;
5194 if (is_array($errormessages) && count($errormessages)) {
5195 foreach ($errormessages as $mesgtoshow) {
5196 print
'<br><br>'.$mesgtoshow;
5199 print
'</div></div>';
5218 function print_liste_field_titre($name, $file =
"", $field =
"", $begin =
"", $moreparam =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $tooltip =
"", $forcenowrapcolumntitle = 0)
5220 print
getTitleFieldOfList($name, 0, $file, $field, $begin, $moreparam, $moreattrib, $sortfield, $sortorder, $prefix, 0, $tooltip, $forcenowrapcolumntitle);
5241 function getTitleFieldOfList($name, $thead = 0, $file =
"", $field =
"", $begin =
"", $moreparam =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $disablesortlink = 0, $tooltip =
'', $forcenowrapcolumntitle = 0)
5243 global $conf, $langs,
$form;
5246 if ($moreattrib ==
'class="right"') {
5247 $prefix .=
'right ';
5250 $sortorder = strtoupper($sortorder);
5259 $tmpsortfield = explode(
',', $sortfield);
5260 $sortfield1 = trim($tmpsortfield[0]);
5261 $tmpfield = explode(
',', $field);
5262 $field1 = trim($tmpfield[0]);
5264 if (empty($conf->global->MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE) && empty($forcenowrapcolumntitle)) {
5265 $prefix =
'wrapcolumntitle '.$prefix;
5271 $liste_titre =
'liste_titre';
5272 if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace(
"/^[^\.]+\./",
"", $field1))) {
5273 $liste_titre =
'liste_titre_sel';
5276 $tagstart =
'<'.$tag.
' class="'.$prefix.$liste_titre.
'" '.$moreattrib;
5278 $tagstart .= ($name && empty($conf->global->MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE) && empty($forcenowrapcolumntitle) && !
dol_textishtml($name)) ?
' title="'.
dol_escape_htmltag($langs->trans($name)).
'"' :
'';
5281 if (empty($thead) && $field && empty($disablesortlink)) {
5282 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
5283 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
5284 $options = preg_replace(
'/&+/i',
'&', $options);
5285 if (!preg_match(
'/^&/', $options)) {
5286 $options =
'&'.$options;
5289 $sortordertouseinlink =
'';
5290 if ($field1 != $sortfield1) {
5291 if (preg_match(
'/^DESC/i', $sortorder)) {
5292 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
5294 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
5297 if (preg_match(
'/^ASC/i', $sortorder)) {
5298 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
5300 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
5303 $sortordertouseinlink = preg_replace(
'/,$/',
'', $sortordertouseinlink);
5304 $out .=
'<a class="reposition" href="'.$file.
'?sortfield='.$field.
'&sortorder='.$sortordertouseinlink.
'&begin='.$begin.$options.
'"';
5310 if (preg_match(
'/:\w+$/', $tooltip)) {
5311 $tmptooltip = explode(
':', $tooltip);
5313 $tmptooltip = array($tooltip);
5315 $out .=
$form->textwithpicto($langs->trans($name), $langs->trans($tmptooltip[0]), 1,
'help',
'', 0, 3, (empty($tmptooltip[1]) ?
'' :
'extra_'.str_replace(
'.',
'_', $field).
'_'.$tmptooltip[1]));
5317 $out .= $langs->trans($name);
5320 if (empty($thead) && $field && empty($disablesortlink)) {
5324 if (empty($thead) && $field) {
5325 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
5326 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
5327 $options = preg_replace(
'/&+/i',
'&', $options);
5328 if (!preg_match(
'/^&/', $options)) {
5329 $options =
'&'.$options;
5332 if (!$sortorder || $field1 != $sortfield1) {
5336 if (preg_match(
'/^DESC/', $sortorder)) {
5339 $sortimg .=
'<span class="nowrap">'.img_up(
"Z-A", 0,
'paddingright').
'</span>';
5341 if (preg_match(
'/^ASC/', $sortorder)) {
5344 $sortimg .=
'<span class="nowrap">'.img_down(
"A-Z", 0,
'paddingright').
'</span>';
5349 $tagend =
'</'.$tag.
'>';
5351 $out = $tagstart.$sortimg.$out.$tagend;
5366 dol_syslog(__FUNCTION__.
" is deprecated", LOG_WARNING);
5368 print
'<div class="titre">'.$title.
'</div>';
5400 function load_fiche_titre($titre, $morehtmlright =
'', $picto =
'generic', $pictoisfullpath = 0, $id =
'', $morecssontable =
'', $morehtmlcenter =
'')
5406 if ($picto ==
'setup') {
5411 $return .=
'<table '.($id ?
'id="'.$id.
'" ' :
'').
'class="centpercent notopnoleftnoright table-fiche-title'.($morecssontable ?
' '.$morecssontable :
'').
'">';
5412 $return .=
'<tr class="titre">';
5414 $return .=
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">'.img_picto(
'', $picto,
'class="valignmiddle widthpictotitle pictotitle"', $pictoisfullpath).
'</td>';
5416 $return .=
'<td class="nobordernopadding valignmiddle col-title">';
5417 $return .=
'<div class="titre inline-block">'.$titre.
'</div>';
5420 $return .=
'<td class="nobordernopadding center valignmiddle col-center">'.$morehtmlcenter.
'</td>';
5423 $return .=
'<td class="nobordernopadding titre_right wordbreakimp right valignmiddle col-right">'.$morehtmlright.
'</td>';
5425 $return .=
'</tr></table>'.
"\n";
5453 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 =
'')
5455 global $conf, $langs;
5458 $savtotalnboflines = $totalnboflines;
5459 $totalnboflines = abs((
int) $totalnboflines);
5461 if ($picto ==
'setup') {
5462 $picto =
'title_setup.png';
5464 if (($conf->browser->name ==
'ie') && $picto ==
'generic') {
5465 $picto =
'title.gif';
5468 $limit = $conf->liste_limit;
5471 if ($savlimit != 0 && (($num > $limit) || ($num == -1) || ($limit == 0))) {
5479 print
"<!-- Begin title -->\n";
5480 print
'<table class="centpercent notopnoleftnoright table-fiche-title'.($morecss ?
' '.$morecss :
'').
'"><tr>';
5484 if ($picto && $titre) {
5485 print
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">'.img_picto(
'', $picto,
'class="valignmiddle pictotitle widthpictotitle"', $pictoisfullpath).
'</td>';
5488 print
'<td class="nobordernopadding valignmiddle col-title">';
5489 print
'<div class="titre inline-block">'.$titre;
5490 if (!empty($titre) && $savtotalnboflines >= 0 && (string) $savtotalnboflines !=
'') {
5491 print
'<span class="opacitymedium colorblack paddingleft">('.$totalnboflines.
')</span>';
5493 print
'</div></td>';
5496 if ($morehtmlcenter && empty($conf->dol_optimize_smallscreen)) {
5497 print
'<td class="nobordernopadding center valignmiddle col-center">'.$morehtmlcenter.
'</td>';
5501 print
'<td class="nobordernopadding valignmiddle right col-right">';
5502 print
'<input type="hidden" name="pageplusoneold" value="'.((int) $page + 1).
'">';
5504 $options .=
"&sortfield=".urlencode($sortfield);
5507 $options .=
"&sortorder=".urlencode($sortorder);
5511 if ($savlimit != 0 && ((
int) $page > 0 || $num > $limit)) {
5512 if ($totalnboflines) {
5514 $maxnbofpage = (empty($conf->dol_optimize_smallscreen) ? 4 : 0);
5517 $nbpages = ceil($totalnboflines / $limit);
5521 $cpt = ($page - $maxnbofpage);
5527 if (empty($pagenavastextinput)) {
5528 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page=0'.$options.
'">1</a></li>';
5530 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
5531 } elseif ($cpt == 2) {
5532 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page=1'.$options.
'">2</a></li>';
5538 if ($pagenavastextinput) {
5539 if ($cpt == $page) {
5540 $pagelist .=
'<li class="pagination"><input type="text" class="width25 center pageplusone" name="pageplusone" value="'.($page + 1).
'"></li>';
5544 if ($cpt == $page) {
5545 $pagelist .=
'<li class="pagination"><span class="active">'.($page + 1).
'</span></li>';
5547 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page='.$cpt.$options.
'">'.($cpt + 1).
'</a></li>';
5551 }
while ($cpt < $nbpages && $cpt <= ($page + $maxnbofpage));
5553 if (empty($pagenavastextinput)) {
5554 if ($cpt < $nbpages) {
5555 if ($cpt < $nbpages - 2) {
5556 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
5557 } elseif ($cpt == $nbpages - 2) {
5558 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page='.($nbpages - 2).$options.
'">'.($nbpages - 1).
'</a></li>';
5560 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page='.($nbpages - 1).$options.
'">'.$nbpages.
'</a></li>';
5564 $pagelist .=
'<li class="pagination paginationlastpage"><a href="'.$file.
'?page='.($nbpages - 1).$options.
'">'.$nbpages.
'</a></li>';
5567 $pagelist .=
'<li class="pagination"><span class="active">'.($page + 1).
"</li>";
5571 if ($savlimit || $morehtmlright || $morehtmlrightbeforearrow) {
5572 print_fleche_navigation((
int) $page, $file, $options, $nextpage, $pagelist, $morehtmlright, $savlimit, $totalnboflines, $hideselectlimit, $morehtmlrightbeforearrow, $hidenavigation);
5576 if ($pagenavastextinput) {
5583 print
'</table>'.
"\n";
5586 if ($morehtmlcenter && !empty($conf->dol_optimize_smallscreen)) {
5587 print
'<div class="nobordernopadding marginbottomonly center valignmiddle col-center centpercent">'.$morehtmlcenter.
'</div>';
5590 print
"<!-- End title -->\n\n";
5609 function print_fleche_navigation($page, $file, $options =
'', $nextpage = 0, $betweenarrows =
'', $afterarrows =
'', $limit = -1, $totalnboflines = 0, $hideselectlimit = 0, $beforearrows =
'', $hidenavigation = 0)
5611 global $conf, $langs;
5613 print
'<div class="pagination"><ul>';
5614 if ($beforearrows) {
5615 print
'<li class="paginationbeforearrows">';
5616 print $beforearrows;
5620 if (empty($hidenavigation)) {
5621 if ((
int) $limit > 0 && empty($hideselectlimit)) {
5622 $pagesizechoices =
'10:10,15:15,20:20,30:30,40:40,50:50,100:100,250:250,500:500,1000:1000';
5623 $pagesizechoices .=
',5000:5000,10000:10000,20000:20000';
5626 if (!empty($conf->global->MAIN_PAGESIZE_CHOICES)) {
5627 $pagesizechoices = $conf->global->MAIN_PAGESIZE_CHOICES;
5630 print
'<li class="pagination">';
5631 print
'<select class="flat selectlimit" name="limit" title="'.dol_escape_htmltag($langs->trans(
"MaxNbOfRecordPerPage")).
'">';
5632 $tmpchoice = explode(
',', $pagesizechoices);
5633 $tmpkey = $limit.
':'.$limit;
5634 if (!in_array($tmpkey, $tmpchoice)) {
5635 $tmpchoice[] = $tmpkey;
5637 $tmpkey = $conf->liste_limit.
':'.$conf->liste_limit;
5638 if (!in_array($tmpkey, $tmpchoice)) {
5639 $tmpchoice[] = $tmpkey;
5641 asort($tmpchoice, SORT_NUMERIC);
5642 foreach ($tmpchoice as $val) {
5644 $tmp = explode(
':', $val);
5647 if ($key !=
'' && $val !=
'') {
5648 if ((
int) $key == (
int) $limit) {
5649 $selected =
' selected="selected"';
5651 print
'<option name="'.$key.
'"'.$selected.
'>'.
dol_escape_htmltag($val).
'</option>'.
"\n";
5655 if ($conf->use_javascript_ajax) {
5656 print
'<!-- JS CODE TO ENABLE select limit to launch submit of page -->
5658 jQuery(document).ready(function () {
5659 jQuery(".selectlimit").change(function() {
5660 console.log("Change limit. Send submit");
5661 $(this).parents(\'form:first\').submit();
5670 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>';
5672 if ($betweenarrows) {
5673 print
'<!--<div class="betweenarrows nowraponall inline-block">-->';
5674 print $betweenarrows;
5675 print
'<!--</div>-->';
5677 if ($nextpage > 0) {
5678 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>';
5681 print
'<li class="paginationafterarrows">';
5686 print
'</ul></div>'.
"\n";
5701 function vatrate($rate, $addpercent =
false, $info_bits = 0, $usestarfornpr = 0, $html = 0)
5705 if (preg_match(
'/%/', $rate)) {
5706 $rate = str_replace(
'%',
'', $rate);
5710 if (preg_match(
'/\((.*)\)/', $rate, $reg)) {
5711 $morelabel =
' ('.$reg[1].
')';
5712 $rate = preg_replace(
'/\s*'.preg_quote($morelabel,
'/').
'/',
'', $rate);
5713 $morelabel =
' '.($html ?
'<span class="opacitymedium">' :
'').
'('.$reg[1].
')'.($html ?
'</span>' :
'');
5715 if (preg_match(
'/\*/', $rate)) {
5716 $rate = str_replace(
'*',
'', $rate);
5721 if (!preg_match(
'/\//', $rate)) {
5722 $ret =
price($rate, 0,
'', 0, 0).($addpercent ?
'%' :
'');
5725 $ret = $rate.($addpercent ?
'%' :
'');
5727 if (($info_bits & 1) && $usestarfornpr >= 0) {
5750 function price($amount,
$form = 0, $outlangs =
'', $trunc = 1, $rounding = -1, $forcerounding = -1, $currency_code =
'')
5752 global $langs, $conf;
5755 if (empty($amount)) {
5758 $amount = (is_numeric($amount) ? $amount : 0);
5759 if ($rounding == -1) {
5760 $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
5762 $nbdecimal = $rounding;
5764 if ($outlangs ===
'none') {
5774 if (!is_object($outlangs)) {
5778 if ($outlangs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
5779 $dec = $outlangs->transnoentitiesnoconv(
"SeparatorDecimal");
5781 if ($outlangs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
5782 $thousand = $outlangs->transnoentitiesnoconv(
"SeparatorThousand");
5784 if ($thousand ==
'None') {
5786 } elseif ($thousand ==
'Space') {
5793 $amount = str_replace(
',',
'.', $amount);
5795 $datas = explode(
'.', $amount);
5796 $decpart = isset($datas[1]) ? $datas[1] :
'';
5797 $decpart = preg_replace(
'/0+$/i',
'', $decpart);
5806 if ($trunc && $nbdecimal > $conf->global->MAIN_MAX_DECIMALS_SHOWN) {
5807 $nbdecimal = $conf->global->MAIN_MAX_DECIMALS_SHOWN;
5808 if (preg_match(
'/\.\.\./i', $conf->global->MAIN_MAX_DECIMALS_SHOWN)) {
5815 if ((
string) $forcerounding !=
'-1') {
5816 if ($forcerounding ===
'MU') {
5817 $nbdecimal = $conf->global->MAIN_MAX_DECIMALS_UNIT;
5818 } elseif ($forcerounding ===
'MT') {
5819 $nbdecimal = $conf->global->MAIN_MAX_DECIMALS_TOT;
5820 } elseif ($forcerounding >= 0) {
5821 $nbdecimal = $forcerounding;
5826 $output = number_format($amount, $nbdecimal, $dec, $thousand);
5828 $output = preg_replace(
'/\s/',
' ', $output);
5829 $output = preg_replace(
'/\'/',
''', $output);
5832 $cursymbolbefore = $cursymbolafter =
'';
5833 if ($currency_code && is_object($outlangs)) {
5834 if ($currency_code ==
'auto') {
5835 $currency_code = $conf->currency;
5838 $listofcurrenciesbefore = array(
'AUD',
'CAD',
'CNY',
'COP',
'CLP',
'GBP',
'HKD',
'MXN',
'PEN',
'USD',
'CRC');
5839 $listoflanguagesbefore = array(
'nl_NL');
5840 if (in_array($currency_code, $listofcurrenciesbefore) || in_array($outlangs->defaultlang, $listoflanguagesbefore)) {
5841 $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
5843 $tmpcur = $outlangs->getCurrencySymbol($currency_code);
5844 $cursymbolafter .= ($tmpcur == $currency_code ?
' '.$tmpcur : $tmpcur);
5847 $output = $cursymbolbefore.$output.$end.($cursymbolafter ?
' ' :
'').$cursymbolafter;
5878 global $langs, $conf;
5881 if (is_null($amount)) {
5890 if (is_null($langs)) {
5894 if ($langs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
5895 $dec = $langs->transnoentitiesnoconv(
"SeparatorDecimal");
5897 if ($langs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
5898 $thousand = $langs->transnoentitiesnoconv(
"SeparatorThousand");
5901 if ($thousand ==
'None') {
5903 } elseif ($thousand ==
'Space') {
5911 if (!is_numeric($amount)) {
5912 $amount = preg_replace(
'/[a-zA-Z\/\\\*\(\)<>\_]/',
'', $amount);
5915 if ($option == 2 && $thousand ==
'.' && preg_match(
'/\.(\d\d\d)$/', (
string) $amount)) {
5916 $amount = str_replace($thousand,
'', $amount);
5922 if (is_numeric($amount)) {
5924 $temps = sprintf(
"%0.10F", $amount - intval($amount));
5925 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
5927 $amount = number_format($amount, $nbofdec, $dec, $thousand);
5932 if ($thousand !=
',' && $thousand !=
'.') {
5933 $amount = str_replace(
',',
'.', $amount);
5936 $amount = str_replace(
' ',
'', $amount);
5937 $amount = str_replace($thousand,
'', $amount);
5938 $amount = str_replace($dec,
'.', $amount);
5940 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
5946 $nbofdectoround =
'';
5947 if ($rounding ==
'MU') {
5948 $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_UNIT;
5949 } elseif ($rounding ==
'MT') {
5950 $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_TOT;
5951 } elseif ($rounding ==
'MS') {
5952 $nbofdectoround = isset($conf->global->MAIN_MAX_DECIMALS_STOCK) ? $conf->global->MAIN_MAX_DECIMALS_STOCK : 5;
5953 } elseif ($rounding ==
'CU') {
5954 $nbofdectoround = max($conf->global->MAIN_MAX_DECIMALS_UNIT, 8);
5955 } elseif ($rounding ==
'CT') {
5956 $nbofdectoround = max($conf->global->MAIN_MAX_DECIMALS_TOT, 8);
5957 } elseif (is_numeric($rounding)) {
5958 $nbofdectoround = (int) $rounding;
5963 $amount = round(is_string($amount) ? (
float) $amount : $amount, $nbofdectoround);
5965 return 'ErrorBadParameterProvidedToFunction';
5971 if (is_numeric($amount)) {
5973 $temps = sprintf(
"%0.10F", $amount - intval($amount));
5974 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
5976 $amount = number_format($amount, min($nbofdec, $nbofdectoround), $dec, $thousand);
5982 if ($thousand !=
',' && $thousand !=
'.') {
5983 $amount = str_replace(
',',
'.', $amount);
5986 $amount = str_replace(
' ',
'', $amount);
5987 $amount = str_replace($thousand,
'', $amount);
5988 $amount = str_replace($dec,
'.', $amount);
5990 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
6008 function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round = -1, $forceunitoutput =
'no', $use_short_label = 0)
6010 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
6012 if (($forceunitoutput ==
'no' && $dimension < 1 / 10000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -6)) {
6013 $dimension = $dimension * 1000000;
6015 } elseif (($forceunitoutput ==
'no' && $dimension < 1 / 10 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -3)) {
6016 $dimension = $dimension * 1000;
6018 } elseif (($forceunitoutput ==
'no' && $dimension > 100000000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 6)) {
6019 $dimension = $dimension / 1000000;
6021 } elseif (($forceunitoutput ==
'no' && $dimension > 100000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 3)) {
6022 $dimension = $dimension / 1000;
6038 $ret =
price($dimension, 0, $outputlangs, 0, 0, $round);
6039 $ret .=
' '.measuringUnitString(0, $type, $unit, $use_short_label, $outputlangs);
6057 function get_localtax($vatrate, $local, $thirdparty_buyer =
"", $thirdparty_seller =
"", $vatnpr = 0)
6059 global $db, $conf, $mysoc;
6061 if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) {
6062 $thirdparty_seller = $mysoc;
6065 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);
6067 $vatratecleaned = $vatrate;
6069 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
6070 $vatratecleaned = trim($reg[1]);
6071 $vatratecode = $reg[2];
6080 if ($mysoc->country_code ==
'ES') {
6082 if (!$mysoc->localtax1_assuj || (
string) $vatratecleaned ==
"0") {
6085 if ($thirdparty_seller->id == $mysoc->id) {
6086 if (!$thirdparty_buyer->localtax1_assuj) {
6090 if (!$thirdparty_seller->localtax1_assuj) {
6098 if (!$mysoc->localtax2_assuj) {
6101 if ($thirdparty_seller->id == $mysoc->id) {
6102 if (!$thirdparty_buyer->localtax2_assuj) {
6106 if (!$thirdparty_seller->localtax2_assuj) {
6112 if ($local == 1 && !$thirdparty_seller->localtax1_assuj) {
6115 if ($local == 2 && !$thirdparty_seller->localtax2_assuj) {
6121 if (in_array($mysoc->country_code, array(
'ES'))) {
6122 $conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY = 1;
6126 if (!empty($conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY)) {
6128 if ($thirdparty_seller != $mysoc) {
6130 return $thirdparty_seller->localtax1_value;
6134 return $conf->global->MAIN_INFO_VALUE_LOCALTAX1;
6139 if ($thirdparty_seller != $mysoc) {
6142 return $thirdparty_seller->localtax2_value;
6145 if (in_array($mysoc->country_code, array(
'ES'))) {
6146 return $thirdparty_buyer->localtax2_value;
6148 return $conf->global->MAIN_INFO_VALUE_LOCALTAX2;
6155 $sql =
"SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
6156 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
6157 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($thirdparty_seller->country_code).
"'";
6158 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
6159 if (!empty($vatratecode)) {
6160 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
6162 $sql .=
" AND t.recuperableonly = '".$db->escape($vatnpr).
"'";
6165 $resql = $db->query(
$sql);
6168 $obj = $db->fetch_object($resql);
6171 return $obj->localtax1;
6172 } elseif ($local == 2) {
6173 return $obj->localtax2;
6194 $valors = explode(
":", $tax);
6196 if (count($valors) > 1) {
6213 $sql =
" SELECT t.localtax".$local.
" as localtax";
6214 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t INNER JOIN ".MAIN_DB_PREFIX.
"c_country as c ON c.rowid = t.fk_pays";
6215 $sql .=
" WHERE c.code = '".$db->escape($mysoc->country_code).
"' AND t.active = 1 AND t.taux = (";
6216 $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";
6217 $sql .=
" WHERE c.code = '".$db->escape($mysoc->country_code).
"' AND tt.active = 1)";
6218 $sql .=
" AND t.localtax".$local.
"_type <> '0'";
6219 $sql .=
" ORDER BY t.rowid DESC";
6221 $resql = $db->query(
$sql);
6223 $obj = $db->fetch_object($resql);
6224 return $obj->localtax;
6244 function getTaxesFromId($vatrate, $buyer =
null, $seller =
null, $firstparamisid = 1)
6248 dol_syslog(
"getTaxesFromId vat id or rate = ".$vatrate);
6251 $sql =
"SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy,";
6252 $sql .=
" t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type";
6253 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t";
6254 if ($firstparamisid) {
6255 $sql .=
" WHERE t.rowid = ".(int) $vatrate;
6257 $vatratecleaned = $vatrate;
6260 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
6261 $vatratecleaned = $reg[1];
6262 $vatratecode = $reg[2];
6265 $sql .=
", ".MAIN_DB_PREFIX.
"c_country as c";
6268 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($seller->country_code).
"'";
6269 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
6271 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
6275 $resql = $db->query(
$sql);
6277 $obj = $db->fetch_object($resql);
6280 'rowid'=>$obj->rowid,
6283 'localtax1'=>$obj->localtax1,
6284 'localtax1_type'=>$obj->localtax1_type,
6285 'localtax2'=>$obj->localtax2,
6286 'localtax2_type'=>$obj->localtax2_type,
6288 'accountancy_code_sell'=>$obj->accountancy_code_sell,
6289 'accountancy_code_buy'=>$obj->accountancy_code_buy
6321 dol_syslog(
"getLocalTaxesFromRate vatrate=".$vatrate.
" local=".$local);
6324 $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";
6325 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t";
6326 if ($firstparamisid) {
6327 $sql .=
" WHERE t.rowid = ".(int) $vatrate;
6329 $vatratecleaned = $vatrate;
6332 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
6333 $vatratecleaned = $reg[1];
6334 $vatratecode = $reg[2];
6337 $sql .=
", ".MAIN_DB_PREFIX.
"c_country as c";
6338 if (!empty($mysoc) && $mysoc->country_code ==
'ES') {
6339 $countrycodetouse = ((empty($buyer) || empty($buyer->country_code)) ? $mysoc->country_code : $buyer->country_code);
6340 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($countrycodetouse).
"'";
6342 $countrycodetouse = ((empty($seller) || empty($seller->country_code)) ? $mysoc->country_code : $seller->country_code);
6343 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($countrycodetouse).
"'";
6345 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
6347 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
6351 $resql = $db->query(
$sql);
6353 $obj = $db->fetch_object($resql);
6356 $vateratestring = $obj->rate.($obj->code ?
' ('.$obj->code.
')' :
'');
6359 return array($obj->localtax1_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
6360 } elseif ($local == 2) {
6361 return array($obj->localtax2_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
6363 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);
6383 global $db, $conf, $mysoc;
6385 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
6393 $product->fetch($idprod);
6395 if ($mysoc->country_code == $thirdpartytouse->country_code) {
6397 if ($idprodfournprice > 0) {
6398 $result = $product->get_buyprice($idprodfournprice, 0, 0, 0);
6400 $ret = $product->vatrate_supplier;
6401 if ($product->default_vat_code_supplier) {
6402 $ret .=
' ('.$product->default_vat_code_supplier.
')';
6408 $ret = $product->tva_tx;
6409 if ($product->default_vat_code) {
6410 $ret .=
' ('.$product->default_vat_code.
')';
6421 if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS)) {
6423 $sql =
"SELECT t.taux as vat_rate, t.code as default_vat_code";
6424 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
6425 $sql .=
" WHERE t.active = 1 AND t.fk_pays = c.rowid AND c.code = '".$db->escape($thirdpartytouse->country_code).
"'";
6426 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
6427 $sql .= $db->plimit(1);
6429 $resql = $db->query(
$sql);
6431 $obj = $db->fetch_object($resql);
6433 $ret = $obj->vat_rate;
6434 if ($obj->default_vat_code) {
6435 $ret .=
' ('.$obj->default_vat_code.
')';
6447 if ($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS !=
'none') {
6448 $defaulttx = $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;
6459 dol_syslog(
"get_product_vat_for_country: ret=".$ret);
6476 if (!class_exists(
'Product')) {
6477 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
6486 $result = $product->fetch($idprod);
6488 if ($mysoc->country_code == $thirdpartytouse->country_code) {
6502 $sql =
"SELECT taux as vat_rate, localtax1, localtax2";
6503 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
6504 $sql .=
" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$db->escape($thirdpartytouse->country_code).
"'";
6505 $sql .=
" ORDER BY t.taux DESC, t.recuperableonly ASC";
6506 $sql .= $db->plimit(1);
6508 $resql = $db->query(
$sql);
6510 $obj = $db->fetch_object($resql);
6513 $ret = $obj->localtax1;
6514 } elseif ($local == 2) {
6515 $ret = $obj->localtax2;
6523 dol_syslog(
"get_product_localtax_for_country: ret=".$ret);
6547 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
6550 $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;
6552 $seller_country_code = $thirdparty_seller->country_code;
6553 $seller_in_cee =
isInEEC($thirdparty_seller);
6555 $buyer_country_code = $thirdparty_buyer->country_code;
6556 $buyer_in_cee =
isInEEC($thirdparty_buyer);
6558 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 :
''));
6562 if (!empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC)) {
6563 if ($seller_in_cee && $buyer_in_cee) {
6564 $isacompany = $thirdparty_buyer->
isACompany();
6565 if ($isacompany &&
getDolGlobalString(
'MAIN_USE_VAT_COMPANIES_IN_EEC_WITH_INVALID_VAT_ID_ARE_INDIVIDUAL')) {
6566 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
6580 if (!$seller_use_vat) {
6586 if (($seller_country_code == $buyer_country_code)
6587 || (in_array($seller_country_code, array(
'FR',
'MC')) && in_array($buyer_country_code, array(
'FR',
'MC')))) {
6591 if ($seller_country_code ==
'IN' &&
getDolGlobalString(
'MAIN_SALETAX_AUTOSWITCH_I_CS_FOR_INDIA')) {
6595 if (preg_match(
'/C+S-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id != $thirdparty_buyer->state_id) {
6597 $tmpvat = str_replace(
"C+S",
"I", $tmpvat);
6598 } elseif (preg_match(
'/I-(\d+)/', $tmpvat, $reg) && $thirdparty_seller->state_id == $thirdparty_buyer->state_id) {
6600 $tmpvat = str_replace(
"I",
"C+S", $tmpvat);
6612 if (($seller_in_cee && $buyer_in_cee)) {
6613 $isacompany = $thirdparty_buyer->
isACompany();
6614 if ($isacompany &&
getDolGlobalString(
'MAIN_USE_VAT_COMPANIES_IN_EEC_WITH_INVALID_VAT_ID_ARE_INDIVIDUAL')) {
6615 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
6632 if (!empty($conf->global->MAIN_USE_VAT_OF_PRODUCT_FOR_INDIVIDUAL_CUSTOMER_OUT_OF_EEC) && empty($buyer_in_cee)) {
6633 $isacompany = $thirdparty_buyer->
isACompany();
6661 if ($idprodfournprice > 0) {
6662 if (!class_exists(
'ProductFournisseur')) {
6663 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
6666 $prodprice->fetch_product_fournisseur_price($idprodfournprice);
6667 return $prodprice->fourn_tva_npr;
6668 } elseif ($idprod > 0) {
6669 if (!class_exists(
'Product')) {
6670 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
6673 $prod->fetch($idprod);
6674 return $prod->tva_npr;
6697 if (!is_object($thirdparty_seller)) {
6700 if (!is_object($thirdparty_buyer)) {
6705 if ($mysoc->country_code ==
'ES') {
6706 if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) {
6711 if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) {
6714 if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj ==
'localtax1off') {
6718 } elseif ($local == 2) {
6720 if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) {
6723 if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj ==
'localtax2off') {
6728 if ($thirdparty_seller->country_code == $thirdparty_buyer->country_code) {
6743 function yn($yesno, $case = 1, $color = 0)
6747 $result =
'unknown';
6749 if ($yesno == 1 || strtolower($yesno) ==
'yes' || strtolower($yesno) ==
'true') {
6750 $result = $langs->trans(
'yes');
6751 if ($case == 1 || $case == 3) {
6752 $result = $langs->trans(
"Yes");
6755 $result =
'<input type="checkbox" value="1" checked disabled>';
6758 $result =
'<input type="checkbox" value="1" checked disabled> '.$result;
6762 } elseif ($yesno == 0 || strtolower($yesno) ==
'no' || strtolower($yesno) ==
'false') {
6763 $result = $langs->trans(
"no");
6764 if ($case == 1 || $case == 3) {
6765 $result = $langs->trans(
"No");
6768 $result =
'<input type="checkbox" value="0" disabled>';
6771 $result =
'<input type="checkbox" value="0" disabled> '.$result;
6777 $classname =
'error';
6781 return '<span class="'.$classname.
'">'.$result.
'</span>';
6801 function get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart =
'')
6805 if (empty($modulepart) && !empty($object->module)) {
6806 $modulepart = $object->module;
6811 $arrayforoldpath = array(
'cheque',
'category',
'holiday',
'supplier_invoice',
'invoice_supplier',
'mailing',
'supplier_payment');
6813 $arrayforoldpath[] =
'product';
6815 if (!empty($level) && in_array($modulepart, $arrayforoldpath)) {
6817 if (empty($alpha)) {
6818 $num = preg_replace(
'/([^0-9])/i',
'', $num);
6820 $num = preg_replace(
'/^.*\-/i',
'', $num);
6822 $num = substr(
"000".$num, -$level);
6824 $path = substr($num, 0, 1);
6827 $path = substr($num, 1, 1).
'/'.substr($num, 0, 1);
6830 $path = substr($num, 2, 1).
'/'.substr($num, 1, 1).
'/'.substr($num, 0, 1);
6840 if (empty($withoutslash) && !empty($path)) {
6859 dol_syslog(
"functions.lib::dol_mkdir: dir=".$dir, LOG_INFO);
6862 if (@is_dir($dir_osencoded)) {
6870 if (!empty($dataroot)) {
6872 $dir = str_replace($dataroot.
'/',
'', $dir);
6873 $ccdir = $dataroot.
'/';
6876 $cdir = explode(
"/", $dir);
6877 $num = count($cdir);
6878 for ($i = 0; $i < $num; $i++) {
6880 $ccdir .=
'/'.$cdir[$i];
6882 $ccdir .= $cdir[$i];
6884 if (preg_match(
"/^.:$/", $ccdir, $regs)) {
6892 if (!@is_dir($ccdir_osencoded)) {
6893 dol_syslog(
"functions.lib::dol_mkdir: Directory '".$ccdir.
"' does not exists or is outside open_basedir PHP setting.", LOG_DEBUG);
6896 $dirmaskdec = octdec((
string) $newmask);
6897 if (empty($newmask)) {
6898 $dirmaskdec = empty($conf->global->MAIN_UMASK) ? octdec(
'0755') : octdec($conf->global->MAIN_UMASK);
6900 $dirmaskdec |= octdec(
'0111');
6901 if (!@mkdir($ccdir_osencoded, $dirmaskdec)) {
6903 dol_syslog(
"functions.lib::dol_mkdir: Fails to create directory '".$ccdir.
"' or directory already exists.", LOG_WARNING);
6906 dol_syslog(
"functions.lib::dol_mkdir: Directory '".$ccdir.
"' created", LOG_DEBUG);
6915 return ($nberr ? -$nberr : $nbcreated);
6930 if (!empty($newmask)) {
6931 @chmod($filepath, octdec($newmask));
6932 } elseif (!empty($conf->global->MAIN_UMASK)) {
6933 @chmod($filepath, octdec($conf->global->MAIN_UMASK));
6945 return '<span class="fieldrequired">*</span>';
6965 function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto =
'UTF-8', $strip_tags = 0, $removedoublespaces = 1)
6967 if (is_null($stringtoclean)) {
6971 if ($removelinefeed == 2) {
6972 $stringtoclean = preg_replace(
'/<br[^>]*>(\n|\r)+/ims',
'<br>', $stringtoclean);
6974 $temp = preg_replace(
'/<br[^>]*>/i',
"\n", $stringtoclean);
6979 $temp = str_replace(
'< ',
'__ltspace__', $temp);
6982 $temp = strip_tags($temp);
6985 $pattern =
"/<[^<>]+>/";