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');
86 return (
string) (empty($conf->global->$key) ? $default : $conf->global->$key);
100 return (
int) (empty($conf->global->$key) ? $default : $conf->global->$key);
114 return (
string) (empty($user->conf->$key) ? $default : $user->conf->$key);
128 return (
int) (empty($user->conf->$key) ? $default : $user->conf->$key);
140 return !empty($conf->$module->enabled);
156 require_once DOL_DOCUMENT_ROOT.
"/core/db/".$type.
'.class.php';
158 $class =
'DoliDB'.ucfirst($type);
159 $dolidb =
new $class($type, $host, $user, $pass, $name, $port);
180 function getEntity($element, $shared = 1, $currentobject =
null)
182 global $conf, $mc, $hookmanager, $object, $action, $db;
184 if (! is_object($hookmanager)) {
191 $element =
'contract';
193 case 'order_supplier':
194 $element =
'supplier_order';
196 case 'invoice_supplier':
197 $element =
'supplier_invoice';
201 if (is_object($mc)) {
202 $out = $mc->getEntity($element, $shared, $currentobject);
205 $addzero = array(
'user',
'usergroup',
'c_email_templates',
'email_template',
'default_values');
206 if (in_array($element, $addzero)) {
209 $out .= ((int) $conf->entity);
214 'element' => $element,
217 'currentobject' => $currentobject,
220 $reshook = $hookmanager->executeHooks(
'hookGetEntity', $parameters, $currentobject, $action);
222 if (is_numeric($reshook)) {
223 if ($reshook == 0 && !empty($hookmanager->resPrint)) {
224 $out .=
','.$hookmanager->resPrint;
225 } elseif ($reshook == 1) {
226 $out = $hookmanager->resPrint;
243 if (is_object($mc) && method_exists($mc,
'setEntity')) {
244 return $mc->setEntity($currentobject);
246 return ((is_object($currentobject) && $currentobject->id > 0 && $currentobject->entity > 0) ? $currentobject->entity : $conf->entity);
258 return preg_match(
'/(_pass|password|_pw|_key|securekey|serverkey|secret\d?|p12key|exportkey|_PW_[a-z]+|token)$/i', $keyname);
270 for ($r =
""; $n >= 0; $n = intval($n / 26) - 1)
271 $r = chr($n % 26 + 0x41) . $r;
294 include_once DOL_DOCUMENT_ROOT.
'/includes/mobiledetect/mobiledetectlib/Mobile_Detect.php';
301 $user_agent = substr($user_agent, 0, 512);
303 $detectmobile =
new Mobile_Detect(
null, $user_agent);
304 $tablet = $detectmobile->isTablet();
306 if ($detectmobile->isMobile()) {
310 if ($detectmobile->is(
'AndroidOS')) {
311 $os = $phone =
'android';
312 } elseif ($detectmobile->is(
'BlackBerryOS')) {
313 $os = $phone =
'blackberry';
314 } elseif ($detectmobile->is(
'iOS')) {
317 } elseif ($detectmobile->is(
'PalmOS')) {
318 $os = $phone =
'palm';
319 } elseif ($detectmobile->is(
'SymbianOS')) {
321 } elseif ($detectmobile->is(
'webOS')) {
323 } elseif ($detectmobile->is(
'MaemoOS')) {
325 } elseif ($detectmobile->is(
'WindowsMobileOS') || $detectmobile->is(
'WindowsPhoneOS')) {
331 if (preg_match(
'/linux/i', $user_agent)) {
333 } elseif (preg_match(
'/macintosh/i', $user_agent)) {
335 } elseif (preg_match(
'/windows/i', $user_agent)) {
341 if (preg_match(
'/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
343 $version = empty($reg[2]) ?
'' : $reg[2];
344 } elseif (preg_match(
'/edge(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
346 $version = empty($reg[2]) ?
'' : $reg[2];
347 } elseif (preg_match(
'/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg)) {
349 $version = empty($reg[2]) ?
'' : $reg[2];
350 } elseif (preg_match(
'/chrome/i', $user_agent, $reg)) {
353 } elseif (preg_match(
'/iceweasel/i', $user_agent)) {
355 } elseif (preg_match(
'/epiphany/i', $user_agent)) {
357 } elseif (preg_match(
'/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
359 $version = empty($reg[2]) ?
'' : $reg[2];
360 } elseif (preg_match(
'/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
363 $version = empty($reg[2]) ?
'' : $reg[2];
364 } elseif (preg_match(
'/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
366 $version = end($reg);
367 } elseif (preg_match(
'/(Windows NT\s([0-9]+\.[0-9])).*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
370 $version = end($reg);
371 } elseif (preg_match(
'/l[iy]n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) {
374 $version = empty($reg[3]) ?
'' : $reg[3];
386 'browsername' => $name,
387 'browserversion' => $version,
402 global $conf, $user, $langs, $db;
403 $disconnectdone =
false;
405 if (is_object($db) && !empty($db->connected)) {
406 $depth = $db->transaction_opened;
407 $disconnectdone = $db->close();
409 dol_syslog(
"--- End access to ".$_SERVER[
"PHP_SELF"].(($disconnectdone && $depth) ?
' (Warn: db disconnection forced, transaction depth was '.$depth.
')' :
''), (($disconnectdone && $depth) ? LOG_WARNING : LOG_INFO));
425 $relativepathstring = $_SERVER[
"PHP_SELF"];
427 if (constant(
'DOL_URL_ROOT')) {
428 $relativepathstring = preg_replace(
'/^'.preg_quote(constant(
'DOL_URL_ROOT'),
'/').
'/',
'', $relativepathstring);
430 $relativepathstring = preg_replace(
'/^\//',
'', $relativepathstring);
431 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
437 if (!empty($_GET[
'restore_lastsearch_values'])) {
438 if (!empty($_SESSION[
'lastsearch_values_'.$relativepathstring])) {
439 $tmp = json_decode($_SESSION[
'lastsearch_values_'.$relativepathstring],
true);
440 if (is_array($tmp)) {
441 foreach ($tmp as $key => $val) {
442 if ($key == $paramname) {
450 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_'.$relativepathstring])) {
452 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_'.$relativepathstring])) {
454 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_'.$relativepathstring])) {
456 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_'.$relativepathstring])) {
460 $isset = (isset($_POST[$paramname]) || isset($_GET[$paramname]));
477 if (empty($method)) {
478 $val = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
479 } elseif ($method == 1) {
480 $val = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
481 } elseif ($method == 2) {
482 $val = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
483 } elseif ($method == 3) {
484 $val = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
486 $val =
'BadFirstParameterForGETPOST';
489 return is_array($val);
520 function GETPOST($paramname, $check =
'alphanohtml', $method = 0, $filter =
null, $options =
null, $noreplace = 0)
522 global $mysoc, $user, $conf;
524 if (empty($paramname)) {
525 return 'BadFirstParameterForGETPOST';
528 dol_syslog(
"Deprecated use of GETPOST, called with 1st param = ".$paramname.
" and 2nd param is '', when calling page ".$_SERVER[
"PHP_SELF"], LOG_WARNING);
533 if (empty($method)) {
534 $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
535 } elseif ($method == 1) {
536 $out = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
537 } elseif ($method == 2) {
538 $out = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
539 } elseif ($method == 3) {
540 $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
542 return 'BadThirdParameterForGETPOST';
545 if (empty($method) || $method == 3 || $method == 4) {
546 $relativepathstring = $_SERVER[
"PHP_SELF"];
548 if (constant(
'DOL_URL_ROOT')) {
549 $relativepathstring = preg_replace(
'/^'.preg_quote(constant(
'DOL_URL_ROOT'),
'/').
'/',
'', $relativepathstring);
551 $relativepathstring = preg_replace(
'/^\//',
'', $relativepathstring);
552 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
558 if (!empty($_GET[
'restore_lastsearch_values'])) {
559 if (!empty($_SESSION[
'lastsearch_values_'.$relativepathstring])) {
560 $tmp = json_decode($_SESSION[
'lastsearch_values_'.$relativepathstring],
true);
561 if (is_array($tmp)) {
562 foreach ($tmp as $key => $val) {
563 if ($key == $paramname) {
571 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_'.$relativepathstring])) {
572 $out = $_SESSION[
'lastsearch_contextpage_'.$relativepathstring];
573 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_'.$relativepathstring])) {
574 $out = $_SESSION[
'lastsearch_limit_'.$relativepathstring];
575 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_'.$relativepathstring])) {
576 $out = $_SESSION[
'lastsearch_page_'.$relativepathstring];
577 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_'.$relativepathstring])) {
578 $out = $_SESSION[
'lastsearch_mode_'.$relativepathstring];
580 } elseif (!isset($_GET[
'sortfield'])) {
583 if (!empty($_GET[
'action']) && $_GET[
'action'] ==
'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
586 if (is_object($object) && isset($object->fields[$paramname][
'default'])) {
587 $out = $object->fields[$paramname][
'default'];
590 if (!empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) {
591 if (!empty($_GET[
'action']) && (preg_match(
'/^create|^add_price|^make/', $_GET[
'action']) || preg_match(
'/^presend/', $_GET[
'action'])) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
593 if (!empty($user->default_values)) {
594 if (isset($user->default_values[$relativepathstring][
'createform'])) {
595 foreach ($user->default_values[$relativepathstring][
'createform'] as $defkey => $defval) {
597 if ($defkey !=
'_noquery_') {
598 $tmpqueryarraytohave = explode(
'&', $defkey);
601 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
602 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
615 if (isset($user->default_values[$relativepathstring][
'createform'][$defkey][$paramname])) {
616 $out = $user->default_values[$relativepathstring][
'createform'][$defkey][$paramname];
623 } elseif (!empty($paramname) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
625 if (!empty($user->default_values)) {
628 if ($paramname ==
'sortfield' || $paramname ==
'sortorder') {
630 if (isset($user->default_values[$relativepathstring][
'sortorder'])) {
632 foreach ($user->default_values[$relativepathstring][
'sortorder'] as $defkey => $defval) {
634 if ($defkey !=
'_noquery_') {
635 $tmpqueryarraytohave = explode(
'&', $defkey);
638 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
639 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
652 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
653 foreach ($user->default_values[$relativepathstring][
'sortorder'][$defkey] as $key => $val) {
657 if ($paramname ==
'sortfield') {
660 if ($paramname ==
'sortorder') {
668 } elseif (isset($user->default_values[$relativepathstring][
'filters'])) {
669 foreach ($user->default_values[$relativepathstring][
'filters'] as $defkey => $defval) {
670 if (!empty($_GET[
'disabledefaultvalues'])) {
674 if ($defkey !=
'_noquery_') {
675 $tmpqueryarraytohave = explode(
'&', $defkey);
678 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
679 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
693 if (isset($_POST[
'sall']) || isset($_POST[
'search_all']) || isset($_GET[
'sall']) || isset($_GET[
'search_all'])) {
695 if (empty($conf->global->MAIN_DISABLE_DEFAULT_FILTER_FOR_QUICK_SEARCH)) {
696 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
697 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
700 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
701 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
716 if (!is_array($out) && empty($_POST[$paramname]) && empty($noreplace)) {
720 while (preg_match(
'/__([A-Z0-9]+_?[A-Z0-9]+)__/i', $out, $reg) && ($loopnb < $maxloop)) {
724 if ($reg[1] ==
'DAY') {
726 $newout = $tmp[
'mday'];
727 } elseif ($reg[1] ==
'MONTH') {
729 $newout = $tmp[
'mon'];
730 } elseif ($reg[1] ==
'YEAR') {
732 $newout = $tmp[
'year'];
733 } elseif ($reg[1] ==
'PREVIOUS_DAY') {
736 $newout = $tmp2[
'day'];
737 } elseif ($reg[1] ==
'PREVIOUS_MONTH') {
740 $newout = $tmp2[
'month'];
741 } elseif ($reg[1] ==
'PREVIOUS_YEAR') {
743 $newout = ($tmp[
'year'] - 1);
744 } elseif ($reg[1] ==
'NEXT_DAY') {
747 $newout = $tmp2[
'day'];
748 } elseif ($reg[1] ==
'NEXT_MONTH') {
751 $newout = $tmp2[
'month'];
752 } elseif ($reg[1] ==
'NEXT_YEAR') {
754 $newout = ($tmp[
'year'] + 1);
755 } elseif ($reg[1] ==
'MYCOMPANY_COUNTRY_ID' || $reg[1] ==
'MYCOUNTRY_ID' || $reg[1] ==
'MYCOUNTRYID') {
756 $newout = $mysoc->country_id;
757 } elseif ($reg[1] ==
'USER_ID' || $reg[1] ==
'USERID') {
759 } elseif ($reg[1] ==
'USER_SUPERVISOR_ID' || $reg[1] ==
'SUPERVISOR_ID' || $reg[1] ==
'SUPERVISORID') {
760 $newout = $user->fk_user;
761 } elseif ($reg[1] ==
'ENTITY_ID' || $reg[1] ==
'ENTITYID') {
762 $newout = $conf->entity;
767 $out = preg_replace(
'/__'.preg_quote($reg[1],
'/').
'__/', $newout, $out);
772 if (preg_match(
'/^array/', $check)) {
773 if (!is_array($out) || empty($out)) {
776 $tmparray = explode(
':', $check);
777 if (!empty($tmparray[1])) {
778 $tmpcheck = $tmparray[1];
780 $tmpcheck =
'alphanohtml';
782 foreach ($out as $outkey => $outval) {
783 $out[$outkey] =
sanitizeVal($outval, $tmpcheck, $filter, $options);
789 if (strpos($paramname,
'search_') === 0) {
790 $out = preg_replace(
'/([<>])([-+]?\d)/',
'\1 \2', $out);
793 $out =
sanitizeVal($out, $check, $filter, $options);
798 if ($paramname ==
'backtopage' || $paramname ==
'backtolist' || $paramname ==
'backtourl') {
799 $out = str_replace(
'\\',
'/', $out);
800 $out = str_replace(array(
':',
';',
'@',
"\t",
' '),
'', $out);
802 $oldstringtoclean = $out;
803 $out = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $out);
804 $out = preg_replace(array(
'/^[^\?]*%/'),
'', $out);
805 $out = preg_replace(array(
'/^[a-z]*\/\s*\/+/i'),
'', $out);
806 }
while ($oldstringtoclean != $out);
811 if (empty($method) || $method == 3 || $method == 4) {
812 if (preg_match(
'/^search_/', $paramname) || in_array($paramname, array(
'sortorder',
'sortfield'))) {
819 if ($out !=
'' && isset($user)) {
820 $user->lastsearch_values_tmp[$relativepathstring][$paramname] = $out;
839 return (
int)
GETPOST($paramname,
'int', $method,
null,
null, 0);
853 function checkVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
855 return sanitizeVal($out, $check, $filter, $options);
867 function sanitizeVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
877 if (!is_numeric($out)) {
882 if (preg_match(
'/[^0-9,-]+/i', $out)) {
887 $out = filter_var($out, FILTER_SANITIZE_STRING);
890 $out = filter_var($out, FILTER_SANITIZE_EMAIL);
893 if (!is_array($out)) {
895 if (preg_match(
'/[^a-z]+/i', $out)) {
901 if (!is_array($out)) {
903 if (preg_match(
'/[^a-z0-9_\-\.]+/i', $out)) {
909 if (!is_array($out)) {
911 if (preg_match(
'/[^a-z0-9_\-\.,]+/i', $out)) {
921 if (!is_array($out)) {
924 $oldstringtoclean = $out;
931 $out = str_ireplace(array(
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'\',
'\',
'/',
'../',
'..\\'),
'', $out);
932 }
while ($oldstringtoclean != $out);
937 if (!is_array($out)) {
940 $oldstringtoclean = $out;
946 $out = str_ireplace(array(
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'\',
'\',
'/',
'../',
'..\\'),
'', $out);
947 }
while ($oldstringtoclean != $out);
951 case 'restricthtmlallowunvalid':
956 if (empty($filter)) {
957 return 'BadParameterForGETPOST - Param 3 of sanitizeVal()';
962 $out = filter_var($out, $filter, $options);
971 if (!function_exists(
'dol_getprefix')) {
981 function dol_getprefix($mode =
'')
984 if ($mode ==
'email') {
987 if (!empty($conf->global->MAIL_PREFIX_FOR_EMAIL_ID)) {
988 if ($conf->global->MAIL_PREFIX_FOR_EMAIL_ID !=
'SERVER_NAME') {
989 return $conf->global->MAIL_PREFIX_FOR_EMAIL_ID;
990 } elseif (isset($_SERVER[
"SERVER_NAME"])) {
991 return $_SERVER[
"SERVER_NAME"];
996 if (!empty($conf->file->instance_unique_id)) {
997 return sha1(
'dolibarr'.$conf->file->instance_unique_id);
1001 return sha1(DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1005 global $dolibarr_main_instance_unique_id, $dolibarr_main_cookie_cryptkey;
1006 $tmp_instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ?
'' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id;
1009 if (!empty($tmp_instance_unique_id)) {
1010 return sha1(
'dolibarr'.$tmp_instance_unique_id);
1014 if (isset($_SERVER[
"SERVER_NAME"]) && isset($_SERVER[
"DOCUMENT_ROOT"])) {
1015 return sha1($_SERVER[
"SERVER_NAME"].$_SERVER[
"DOCUMENT_ROOT"].DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1017 return sha1(DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1034 global $conf, $langs, $user, $mysoc;
1038 if (!file_exists($fullpath)) {
1039 dol_syslog(
'functions::dol_include_once Tried to load unexisting file: '.$relpath, LOG_WARNING);
1043 if (!empty($classname) && !class_exists($classname)) {
1044 return include $fullpath;
1046 return include_once $fullpath;
1065 $path = preg_replace(
'/^\//',
'', $path);
1068 $res = DOL_DOCUMENT_ROOT.
'/'.$path;
1069 if (is_array($conf->file->dol_document_root)) {
1070 foreach ($conf->file->dol_document_root as $key => $dirroot) {
1071 if ($key ==
'main') {
1074 if (file_exists($dirroot.
'/'.$path)) {
1075 $res = $dirroot.
'/'.$path;
1080 if ($returnemptyifnotfound) {
1082 if ($returnemptyifnotfound == 1 || !file_exists($res)) {
1094 $res = DOL_URL_ROOT.
'/'.$path;
1097 $res = DOL_MAIN_URL_ROOT.
'/'.$path;
1100 $res = DOL_URL_ROOT.
'/'.$path;
1103 foreach ($conf->file->dol_document_root as $key => $dirroot) {
1104 if ($key ==
'main') {
1106 global $dolibarr_main_url_root;
1109 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1110 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1113 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : $urlwithroot).
'/'.$path;
1117 preg_match(
'/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i', $path, $regs);
1118 if (!empty($regs[1])) {
1120 if (file_exists($dirroot.
'/'.$regs[1])) {
1122 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : DOL_URL_ROOT).$conf->file->dol_url_root[$key].
'/'.$path;
1125 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : DOL_MAIN_URL_ROOT).$conf->file->dol_url_root[$key].
'/'.$path;
1128 global $dolibarr_main_url_root;
1131 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1132 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1135 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : $urlwithroot).$conf->file->dol_url_root[$key].
'/'.$path;
1162 if (isset($object->db) && isset($object->db->db) && is_object($object->db->db) && get_class($object->db->db) ==
'PgSql\Connection') {
1163 $tmpsavdb = $object->db;
1167 $myclone = unserialize(serialize($object));
1169 if (!empty($tmpsavdb)) {
1170 $object->db = $tmpsavdb;
1172 } elseif ($native == 2) {
1174 $myclone =
new stdClass();
1175 $tmparray = get_object_vars($object);
1177 if (is_array($tmparray)) {
1178 foreach ($tmparray as $propertykey => $propertyval) {
1179 if (is_scalar($propertyval) || is_array($propertyval)) {
1180 $myclone->$propertykey = $propertyval;
1185 $myclone = clone $object;
1203 if (empty($conf->dol_optimize_smallscreen)) {
1206 if ($type ==
'width' && $size > 250) {
1231 $filesystem_forbidden_chars = array(
'<',
'>',
'/',
'\\',
'?',
'*',
'|',
'"',
':',
'°',
'$',
';',
'`');
1233 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
1234 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $tmp);
1235 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1236 $tmp = str_replace(
'..',
'', $tmp);
1256 $filesystem_forbidden_chars = array(
'<',
'>',
'?',
'*',
'|',
'"',
'°',
'$',
';',
'`');
1258 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
1259 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $tmp);
1260 $tmp = preg_replace(
'/\s+\-$/',
'', $tmp);
1261 $tmp = str_replace(
'..',
'', $tmp);
1276 $stringtoclean = preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $stringtoclean);
1278 $stringtoclean = preg_replace(
'/<!--[^>]*-->/',
'', $stringtoclean);
1280 $stringtoclean = str_replace(
'\\',
'/', $stringtoclean);
1284 $stringtoclean = str_replace(array(
':',
';',
'@'),
'', $stringtoclean);
1288 $oldstringtoclean = $stringtoclean;
1291 $stringtoclean = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $stringtoclean);
1292 }
while ($oldstringtoclean != $stringtoclean);
1296 $stringtoclean = preg_replace(array(
'/^[a-z]*\/\/+/i'),
'', $stringtoclean);
1299 return $stringtoclean;
1311 $oldstringtoclean = $stringtoclean;
1312 $stringtoclean = str_ireplace(array(
'"',
':',
'[',
']',
"\n",
"\r",
'\\',
'\/'),
'', $stringtoclean);
1313 }
while ($oldstringtoclean != $stringtoclean);
1315 return $stringtoclean;
1330 if (is_null($str)) {
1335 if (extension_loaded(
'intl') && !empty($conf->global->MAIN_UNACCENT_USE_TRANSLITERATOR)) {
1336 $transliterator = \Transliterator::createFromRules(
':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', \Transliterator::FORWARD);
1337 return $transliterator->transliterate($str);
1340 $string = rawurlencode($str);
1341 $replacements = array(
1342 '%C3%80' =>
'A',
'%C3%81' =>
'A',
'%C3%82' =>
'A',
'%C3%83' =>
'A',
'%C3%84' =>
'A',
'%C3%85' =>
'A',
1344 '%C3%88' =>
'E',
'%C3%89' =>
'E',
'%C3%8A' =>
'E',
'%C3%8B' =>
'E',
1345 '%C3%8C' =>
'I',
'%C3%8D' =>
'I',
'%C3%8E' =>
'I',
'%C3%8F' =>
'I',
1347 '%C3%92' =>
'O',
'%C3%93' =>
'O',
'%C3%94' =>
'O',
'%C3%95' =>
'O',
'%C3%96' =>
'O',
1349 '%C3%99' =>
'U',
'%C3%9A' =>
'U',
'%C3%9B' =>
'U',
'%C3%9C' =>
'U',
1350 '%C3%9D' =>
'Y',
'%C5%B8' =>
'y',
1351 '%C3%A0' =>
'a',
'%C3%A1' =>
'a',
'%C3%A2' =>
'a',
'%C3%A3' =>
'a',
'%C3%A4' =>
'a',
'%C3%A5' =>
'a',
1353 '%C3%A8' =>
'e',
'%C3%A9' =>
'e',
'%C3%AA' =>
'e',
'%C3%AB' =>
'e',
1354 '%C3%AC' =>
'i',
'%C3%AD' =>
'i',
'%C3%AE' =>
'i',
'%C3%AF' =>
'i',
1356 '%C3%B2' =>
'o',
'%C3%B3' =>
'o',
'%C3%B4' =>
'o',
'%C3%B5' =>
'o',
'%C3%B6' =>
'o',
1358 '%C3%B9' =>
'u',
'%C3%BA' =>
'u',
'%C3%BB' =>
'u',
'%C3%BC' =>
'u',
1359 '%C3%BD' =>
'y',
'%C3%BF' =>
'y'
1361 $string = strtr($string, $replacements);
1362 return rawurldecode($string);
1367 "\xC0\xC1\xC2\xC3\xC4\xC5\xC7
1368 \xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1
1369 \xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD
1370 \xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB
1371 \xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8
1372 \xF9\xFA\xFB\xFC\xFD\xFF",
1380 $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"));
1399 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
",",
";",
"=",
'°');
1400 $forbidden_chars_to_remove = array();
1403 if (is_array($badcharstoreplace)) {
1404 $forbidden_chars_to_replace = $badcharstoreplace;
1406 if (is_array($badcharstoremove)) {
1407 $forbidden_chars_to_remove = $badcharstoremove;
1410 return str_replace($forbidden_chars_to_replace, $newstr, str_replace($forbidden_chars_to_remove,
"", $str));
1429 if ($removetabcrlf) {
1430 return preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $str);
1432 return preg_replace(
'/[\x00-\x08\x11-\x12\x14-\x1F\x7F]/u',
'', $str);
1446 if (is_null($stringtoescape)) {
1451 $substitjs = array(
"'"=>
"\\'",
"\r"=>
'\\r');
1453 if (empty($noescapebackslashn)) {
1454 $substitjs[
"\n"] =
'\\n';
1455 $substitjs[
'\\'] =
'\\\\';
1458 $substitjs[
"'"] =
"\\'";
1459 $substitjs[
'"'] =
"\\'";
1460 } elseif ($mode == 1) {
1461 $substitjs[
"'"] =
"\\'";
1462 } elseif ($mode == 2) {
1463 $substitjs[
'"'] =
'\\"';
1464 } elseif ($mode == 3) {
1465 $substitjs[
"'"] =
"\\'";
1466 $substitjs[
'"'] =
"\\\"";
1468 return strtr($stringtoescape, $substitjs);
1479 return str_replace(
'"',
'\"', $stringtoescape);
1493 function dol_escape_htmltag($stringtoescape, $keepb = 0, $keepn = 0, $noescapetags =
'', $escapeonlyhtmltags = 0)
1495 if ($noescapetags ==
'common') {
1496 $noescapetags =
'html,body,a,b,em,hr,i,u,ul,li,br,div,img,font,p,span,strong,table,tr,td,th,tbody';
1500 if ($escapeonlyhtmltags) {
1501 $tmp = htmlspecialchars_decode((
string) $stringtoescape, ENT_COMPAT);
1503 $tmp = html_entity_decode((
string) $stringtoescape, ENT_COMPAT,
'UTF-8');
1506 $tmp = strtr($tmp, array(
"<b>"=>
'',
'</b>'=>
''));
1509 $tmp = strtr($tmp, array(
"\r"=>
'\\r',
"\n"=>
'\\n'));
1512 if ($escapeonlyhtmltags) {
1513 return htmlspecialchars($tmp, ENT_COMPAT,
'UTF-8');
1517 $tmparrayoftags = array();
1518 if ($noescapetags) {
1519 $tmparrayoftags = explode(
',', $noescapetags);
1521 if (count($tmparrayoftags)) {
1522 foreach ($tmparrayoftags as $tagtoreplace) {
1523 $tmp = str_ireplace(
'<'.$tagtoreplace.
'>',
'__BEGINTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
1524 $tmp = str_ireplace(
'</'.$tagtoreplace.
'>',
'__ENDTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
1525 $tmp = str_ireplace(
'<'.$tagtoreplace.
' />',
'__BEGINENDTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
1529 $result = htmlentities($tmp, ENT_COMPAT,
'UTF-8');
1531 if (count($tmparrayoftags)) {
1532 foreach ($tmparrayoftags as $tagtoreplace) {
1533 $result = str_ireplace(
'__BEGINTAGTOREPLACE'.$tagtoreplace.
'__',
'<'.$tagtoreplace.
'>', $result);
1534 $result = str_ireplace(
'__ENDTAGTOREPLACE'.$tagtoreplace.
'__',
'</'.$tagtoreplace.
'>', $result);
1535 $result = str_ireplace(
'__BEGINENDTAGTOREPLACE'.$tagtoreplace.
'__',
'<'.$tagtoreplace.
' />', $result);
1552 if (function_exists(
'mb_strtolower')) {
1553 return mb_strtolower($string, $encoding);
1555 return strtolower($string);
1568 if (function_exists(
'mb_strtoupper')) {
1569 return mb_strtoupper($string, $encoding);
1571 return strtoupper($string);
1584 if (function_exists(
'mb_substr')) {
1585 return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding).mb_substr($string, 1,
null, $encoding);
1587 return ucfirst($string);
1600 if (function_exists(
'mb_convert_case')) {
1601 return mb_convert_case($string, MB_CASE_TITLE, $encoding);
1603 return ucwords($string);
1628 function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename =
'', $restricttologhandler =
'', $logcontext =
null)
1630 global $conf, $user, $debugbar;
1633 if (empty($conf->syslog->enabled)) {
1638 if (defined(
'USEEXTERNALSERVER') && !defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
1639 global $website, $websitekey;
1640 if (is_object($website) && !empty($website->ref)) {
1641 $suffixinfilename .=
'_website_'.$website->ref;
1642 } elseif (!empty($websitekey)) {
1643 $suffixinfilename .=
'_website_'.$websitekey;
1648 if (defined(
'USESUFFIXINLOG')) {
1649 $suffixinfilename .= constant(
'USESUFFIXINLOG');
1653 foreach ($conf->loghandlers as $loghandlerinstance) {
1654 $loghandlerinstance->setIdent($ident);
1658 if (!empty($message)) {
1660 $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');
1661 if (!array_key_exists($level, $logLevels)) {
1662 throw new Exception(
'Incorrect log level');
1664 if ($level > $conf->global->SYSLOG_LEVEL) {
1668 if (empty($conf->global->MAIN_SHOW_PASSWORD_INTO_LOG)) {
1669 $message = preg_replace(
'/password=\'[^\']*\'/',
'password=\'hidden\'', $message);
1673 if ((!empty($_REQUEST[
'logtohtml']) && !empty($conf->global->MAIN_ENABLE_LOG_TO_HTML))
1674 || (!empty($user->rights->debugbar->read) && is_object($debugbar))) {
1675 $conf->logbuffer[] =
dol_print_date(time(),
"%Y-%m-%d %H:%M:%S").
" ".$logLevels[$level].
" ".$message;
1680 if (!empty($conf->global->MAIN_ENABLE_LOG_INLINE_HTML) && !empty($_GET[
"log"])) {
1681 print
"\n\n<!-- Log start\n";
1683 print
"Log end -->\n";
1687 'message' => $message,
1688 'script' => (isset($_SERVER[
'PHP_SELF']) ? basename($_SERVER[
'PHP_SELF'],
'.php') :
false),
1690 'user' => ((is_object($user) && $user->id) ? $user->login :
false),
1695 if (!empty($remoteip)) {
1696 $data[
'ip'] = $remoteip;
1698 if (!empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) && $_SERVER[
'HTTP_X_FORWARDED_FOR'] != $remoteip) {
1699 $data[
'ip'] = $_SERVER[
'HTTP_X_FORWARDED_FOR'].
' -> '.$data[
'ip'];
1700 } elseif (!empty($_SERVER[
'HTTP_CLIENT_IP']) && $_SERVER[
'HTTP_CLIENT_IP'] != $remoteip) {
1701 $data[
'ip'] = $_SERVER[
'HTTP_CLIENT_IP'].
' -> '.$data[
'ip'];
1703 } elseif (!empty($_SERVER[
'SERVER_ADDR'])) {
1705 $data[
'ip'] = $_SERVER[
'SERVER_ADDR'];
1706 } elseif (!empty($_SERVER[
'COMPUTERNAME'])) {
1708 $data[
'ip'] = $_SERVER[
'COMPUTERNAME'].(empty($_SERVER[
'USERNAME']) ?
'' :
'@'.$_SERVER[
'USERNAME']);
1709 } elseif (!empty($_SERVER[
'LOGNAME'])) {
1711 $data[
'ip'] =
'???@'.$_SERVER[
'LOGNAME'];
1715 foreach ($conf->loghandlers as $loghandlerinstance) {
1716 if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
1719 $loghandlerinstance->export($data, $suffixinfilename);
1725 foreach ($conf->loghandlers as $loghandlerinstance) {
1726 $loghandlerinstance->setIdent($ident);
1749 if (strpos($url,
'?') > 0) {
1750 $url .=
'&dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup='.urlencode($name);
1752 $url .=
'?dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup='.urlencode($name);
1757 $backtopagejsfieldsid =
''; $backtopagejsfieldslabel =
'';
1758 if ($backtopagejsfields) {
1759 $tmpbacktopagejsfields = explode(
':', $backtopagejsfields);
1760 if (empty($tmpbacktopagejsfields[1])) {
1761 $backtopagejsfields = $name.
":".$backtopagejsfields;
1762 $tmp2backtopagejsfields = explode(
',', $tmpbacktopagejsfields[0]);
1764 $tmp2backtopagejsfields = explode(
',', $tmpbacktopagejsfields[1]);
1766 $backtopagejsfieldsid = empty($tmp2backtopagejsfields[0]) ?
'' : $tmp2backtopagejsfields[0];
1767 $backtopagejsfieldslabel = empty($tmp2backtopagejsfields[1]) ?
'' : $tmp2backtopagejsfields[1];
1768 $url .=
'&backtopagejsfields='.urlencode($backtopagejsfields);
1772 $out .=
'<!-- a link for button to open url into a dialog popup with backtopagejsfields = '.$backtopagejsfields.
' -->';
1773 $out .=
'<a class="cursorpointer classlink button_'.$name.($morecss ?
' '.$morecss :
'').
'"'.$disabled.
' title="'.
dol_escape_htmltag($label).
'"';
1774 if (empty($conf->use_javascript_ajax)) {
1775 $out .=
' href="'.DOL_URL_ROOT.$url.
'" target="_blank"';
1777 $out .=
'>'.$buttonstring.
'</a>';
1779 if (!empty($conf->use_javascript_ajax)) {
1781 $out .=
'<!-- code to open popup and variables to retreive returned variables -->';
1782 $out .=
'<div id="idfordialog'.$name.
'" class="hidden">div for dialog</div>';
1783 $out .=
'<div id="varforreturndialogid'.$name.
'" class="hidden">div for returned id</div>';
1784 $out .=
'<div id="varforreturndialoglabel'.$name.
'" class="hidden">div for returned label</div>';
1785 $out .=
'<!-- Add js code to open dialog popup on dialog -->';
1786 $out .=
'<script type="text/javascript">
1787 jQuery(document).ready(function () {
1788 jQuery(".button_'.$name.
'").click(function () {
1789 console.log(\'Open popup with jQuery(...).dialog() on URL '.
dol_escape_js(DOL_URL_ROOT.$url).
'\');
1790 var $tmpdialog = $(\
'#idfordialog'.$name.
'\');
1791 $tmpdialog.html(\
'<iframe class="iframedialog" id="iframedialog'.$name.
'" style="border: 0px;" src="'.DOL_URL_ROOT.$url.
'" width="100%" height="98%"></iframe>\');
1795 height: (window.innerHeight - 150),
1798 open:
function (event, ui) {
1799 console.log(
"open popup name='.$name.', backtopagejsfields='.$backtopagejsfields.'");
1801 close:
function (event, ui) {
1802 returnedid = jQuery(
"#varforreturndialogid'.$name.'").text();
1803 returnedlabel = jQuery(
"#varforreturndialoglabel'.$name.'").text();
1804 console.log(
"popup has been closed. returnedid (js var defined into parent page)="+returnedid+
" returnedlabel="+returnedlabel);
1805 if (returnedid !=
"" && returnedid !=
"div for returned id") {
1806 jQuery(
"#'.(empty($backtopagejsfieldsid)?"none
":$backtopagejsfieldsid).'").val(returnedid);
1808 if (returnedlabel !=
"" && returnedlabel !=
"div for returned label") {
1809 jQuery(
"#'.(empty($backtopagejsfieldslabel)?"none
":$backtopagejsfieldslabel).'").val(returnedlabel);
1814 $tmpdialog.dialog(\
'open\');
1838 function dol_fiche_head($links = array(), $active =
'0', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'')
1840 print
dol_get_fiche_head($links, $active, $title, $notab, $picto, $pictoisfullpath, $morehtmlright, $morecss, $limittoshow, $moretabssuffix);
1858 function dol_get_fiche_head($links = array(), $active =
'', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'')
1860 global $conf, $langs, $hookmanager;
1864 if (!empty($conf->dol_optimize_smallscreen)) {
1868 $out =
"\n".
'<!-- dol_fiche_head - dol_get_fiche_head -->';
1870 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
1871 $out .=
'<div class="tabs'.($picto ?
'' :
' nopaddingleft').
'" data-role="controlgroup" data-type="horizontal">'.
"\n";
1875 if ($morehtmlright) {
1876 $out .=
'<div class="inline-block floatright tabsElem">'.$morehtmlright.
'</div>';
1880 if (!empty($title) && $showtitle && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1882 $out .=
'<a class="tabTitle">';
1884 $noprefix = $pictoisfullpath;
1885 if (strpos($picto,
'fontawesome_') !==
false) {
1888 $out .=
img_picto($title, ($noprefix ?
'' :
'object_').$picto,
'', $pictoisfullpath, 0, 0,
'',
'imgTabTitle').
' ';
1890 $out .=
'<span class="tabTitleText">'.dol_escape_htmltag(
dol_trunc($title, $limittitle)).
'</span>';
1898 if (is_array($links) && !empty($links)) {
1899 $keys = array_keys($links);
1901 $maxkey = max($keys);
1907 if (empty($limittoshow)) {
1908 $limittoshow = (empty($conf->global->MAIN_MAXTABS_IN_CARD) ? 99 : $conf->global->MAIN_MAXTABS_IN_CARD);
1910 if (!empty($conf->dol_optimize_smallscreen)) {
1918 for ($i = 0; $i <= $maxkey; $i++) {
1919 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
1921 if ($i >= $limittoshow) {
1927 for ($i = 0; $i <= $maxkey; $i++) {
1928 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
1934 if ($i < $limittoshow || $isactive) {
1936 $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])).
' -->';
1938 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
1939 if (!empty($links[$i][0])) {
1940 $out .=
'<a class="tabimage'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">'.$links[$i][1].
'</a>'.
"\n";
1942 $out .=
'<span class="tabspan">'.$links[$i][1].
'</span>'.
"\n";
1944 } elseif (!empty($links[$i][1])) {
1946 $out .=
'<div class="tab tab'.($isactive?
'active':
'unactive').
'" style="margin: 0 !important">';
1947 if (!empty($links[$i][0])) {
1948 $titletoshow = preg_replace(
'/<.*$/',
'', $links[$i][1]);
1949 $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).
'">';
1951 $out .= $links[$i][1];
1952 if (!empty($links[$i][0])) {
1953 $out .=
'</a>'.
"\n";
1955 $out .= empty($links[$i][4]) ?
'' : $links[$i][4];
1964 $outmore .=
'<div class="popuptabset wordwrap">';
1966 $outmore .=
'<div class="popuptab wordwrap" style="display:inherit;">';
1967 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
1968 if (!empty($links[$i][0])) {
1969 $outmore .=
'<a class="tabimage'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">'.$links[$i][1].
'</a>'.
"\n";
1971 $outmore .=
'<span class="tabspan">'.$links[$i][1].
'</span>'.
"\n";
1973 } elseif (!empty($links[$i][1])) {
1974 $outmore .=
'<a'.(!empty($links[$i][2]) ?
' id="'.$links[$i][2].
'"' :
'').
' class="wordwrap inline-block'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">';
1975 $outmore .= preg_replace(
'/([a-z])\/([a-z])/i',
'\\1 / \\2', $links[$i][1]);
1976 $outmore .=
'</a>'.
"\n";
1978 $outmore .=
'</div>';
1985 $outmore .=
'</div>';
1989 $left = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'right' :
'left');
1990 $right = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right');
1991 $widthofpopup = 200;
1993 $tabsname = $moretabssuffix;
1994 if (empty($tabsname)) {
1995 $tabsname = str_replace(
"@",
"", $picto);
1997 $out .=
'<div id="moretabs'.$tabsname.
'" class="inline-block tabsElem valignmiddle">';
1998 $out .=
'<div class="tab"><a href="#" class="tab moretab inline-block tabunactive"><span class="hideonsmartphone">'.$langs->trans(
"More").
'</span>... ('.$nbintab.
')</a></div>';
1999 $out .=
'<div id="moretabsList'.$tabsname.
'" style="width: '.$widthofpopup.
'px; position: absolute; '.$left.
': -999em; text-align: '.$left.
'; margin:0px; padding:2px; z-index:10;">';
2002 $out .=
'<div></div>';
2006 $out .=
"$('#moretabs".$tabsname.
"').mouseenter( function() {
2007 var x = this.offsetLeft, y = this.offsetTop;
2008 console.log('mouseenter ".$left.
" x='+x+' y='+y+' window.innerWidth='+window.innerWidth);
2009 if ((window.innerWidth - x) < ".($widthofpopup + 10).
") {
2010 $('#moretabsList".$tabsname.
"').css('".$right.
"','8px');
2012 $('#moretabsList".$tabsname.
"').css('".$left.
"','auto');
2015 $out .=
"$('#moretabs".$tabsname.
"').mouseleave( function() { console.log('mouseleave ".$left.
"'); $('#moretabsList".$tabsname.
"').css('".$left.
"','-999em');});";
2016 $out .=
"</script>";
2019 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
2023 if (!$notab || $notab == -1 || $notab == -2 || $notab == -3) {
2024 $out .=
"\n".
'<div class="tabBar'.($notab == -1 ?
'' : ($notab == -2 ?
' tabBarNoTop' : (($notab == -3 ?
' noborderbottom' :
'').
' tabBarWithBottom'))).
'">'.
"\n";
2027 $parameters = array(
'tabname' => $active,
'out' => $out);
2028 $reshook = $hookmanager->executeHooks(
'printTabsHead', $parameters);
2030 $out = $hookmanager->resPrint;
2056 if (!$notab || $notab == -1) {
2057 return "\n</div>\n";
2082 function dol_banner_tab($object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $onlybanner = 0, $morehtmlright =
'')
2084 global $conf,
$form, $user, $langs, $hookmanager, $action;
2088 $maxvisiblephotos = 1;
2090 $entity = (empty($object->entity) ? $conf->entity : $object->entity);
2091 $showbarcode = empty($conf->barcode->enabled) ? 0 : (empty($object->barcode) ? 0 : 1);
2092 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
2095 $modulepart =
'unknown';
2097 if ($object->element ==
'societe' || $object->element ==
'contact' || $object->element ==
'product' || $object->element ==
'ticket') {
2098 $modulepart = $object->element;
2099 } elseif ($object->element ==
'member') {
2100 $modulepart =
'memberphoto';
2101 } elseif ($object->element ==
'user') {
2102 $modulepart =
'userphoto';
2105 if (class_exists(
"Imagick")) {
2106 if ($object->element ==
'expensereport' || $object->element ==
'propal' || $object->element ==
'commande' || $object->element ==
'facture' || $object->element ==
'supplier_proposal') {
2107 $modulepart = $object->element;
2108 } elseif ($object->element ==
'fichinter') {
2109 $modulepart =
'ficheinter';
2110 } elseif ($object->element ==
'contrat') {
2111 $modulepart =
'contract';
2112 } elseif ($object->element ==
'order_supplier') {
2113 $modulepart =
'supplier_order';
2114 } elseif ($object->element ==
'invoice_supplier') {
2115 $modulepart =
'supplier_invoice';
2119 if ($object->element ==
'product') {
2121 $cssclass =
'photowithmargin photoref';
2122 $showimage = $object->is_photo_available($conf->product->multidir_output[$entity]);
2123 $maxvisiblephotos = (isset($conf->global->PRODUCT_MAX_VISIBLE_PHOTO) ? $conf->global->PRODUCT_MAX_VISIBLE_PHOTO : 5);
2124 if ($conf->browser->layout ==
'phone') {
2125 $maxvisiblephotos = 1;
2128 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$object->show_photos(
'product', $conf->product->multidir_output[$entity],
'small', $maxvisiblephotos, 0, 0, 0, $width, 0).
'</div>';
2130 if (!empty($conf->global->PRODUCT_NODISPLAYIFNOPHOTO)) {
2132 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
2134 $nophoto =
'/public/theme/common/nophoto.png';
2135 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><img class="photo'.$modulepart.($cssclass ?
' '.$cssclass :
'').
'" alt="No photo"'.($width ?
' style="width: '.$width.
'px"' :
'').
' src="'.DOL_URL_ROOT.$nophoto.
'"></div>';
2138 } elseif ($object->element ==
'ticket') {
2140 $cssclass =
'photoref';
2141 $showimage = $object->is_photo_available($conf->ticket->multidir_output[$entity].
'/'.$object->ref);
2142 $maxvisiblephotos = (isset($conf->global->TICKET_MAX_VISIBLE_PHOTO) ? $conf->global->TICKET_MAX_VISIBLE_PHOTO : 2);
2143 if ($conf->browser->layout ==
'phone') {
2144 $maxvisiblephotos = 1;
2148 $showphoto = $object->show_photos(
'ticket', $conf->ticket->multidir_output[$entity],
'small', $maxvisiblephotos, 0, 0, 0, $width, 0);
2149 if ($object->nbphoto > 0) {
2150 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$showphoto.
'</div>';
2156 if (!empty($conf->global->TICKET_NODISPLAYIFNOPHOTO)) {
2158 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
2160 $nophoto =
img_picto(
'No photo',
'object_ticket');
2161 $morehtmlleft .=
'<!-- No photo to show -->';
2162 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
2163 $morehtmlleft .= $nophoto;
2164 $morehtmlleft .=
'</div></div>';
2169 if ($modulepart !=
'unknown') {
2172 if (in_array($modulepart, array(
'propal',
'commande',
'facture',
'ficheinter',
'contract',
'supplier_order',
'supplier_proposal',
'supplier_invoice',
'expensereport')) && class_exists(
"Imagick")) {
2174 $dir_output = (empty($conf->$modulepart->multidir_output[$entity]) ? $conf->$modulepart->dir_output : $conf->$modulepart->multidir_output[$entity]).
"/";
2175 if (in_array($modulepart, array(
'invoice_supplier',
'supplier_invoice'))) {
2176 $subdir =
get_exdir($object->id, 2, 0, 1, $object, $modulepart);
2177 $subdir .= ((!empty($subdir) && !preg_match(
'/\/$/', $subdir)) ?
'/' :
'').$objectref;
2179 $subdir =
get_exdir($object->id, 0, 0, 1, $object, $modulepart);
2181 if (empty($subdir)) {
2182 $subdir =
'errorgettingsubdirofobject';
2185 $filepath = $dir_output.$subdir.
"/";
2187 $filepdf = $filepath.$objectref.
".pdf";
2188 $relativepath = $subdir.
'/'.$objectref.
'.pdf';
2191 $fileimage = $filepdf.
'_preview.png';
2192 $relativepathimage = $relativepath.
'_preview.png';
2194 $pdfexists = file_exists($filepdf);
2199 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
2200 if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) {
2201 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2210 if ($pdfexists && !$error) {
2211 $heightforphotref = 80;
2212 if (!empty($conf->dol_optimize_smallscreen)) {
2213 $heightforphotref = 60;
2216 if (file_exists($fileimage)) {
2217 $phototoshow =
'<div class="photoref">';
2218 $phototoshow .=
'<img height="'.$heightforphotref.
'" class="photo photowithborder" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart=apercu'.$modulepart.
'&file='.urlencode($relativepathimage).
'">';
2219 $phototoshow .=
'</div>';
2222 } elseif (!$phototoshow) {
2223 $phototoshow .=
$form->showphoto($modulepart, $object, 0, 0, 0,
'photowithmargin photoref',
'small', 1, 0, $maxvisiblephotos);
2227 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">';
2228 $morehtmlleft .= $phototoshow;
2229 $morehtmlleft .=
'</div>';
2233 if (empty($phototoshow)) {
2234 if ($object->element ==
'action') {
2236 $cssclass =
'photorefcenter';
2237 $nophoto =
img_picto(
'No photo',
'title_agenda');
2240 $cssclass =
'photorefcenter';
2241 $picto = $object->picto;
2242 $prefix =
'object_';
2243 if ($object->element ==
'project' && !$object->public) {
2246 if (strpos($picto,
'fontawesome_') !==
false) {
2249 $nophoto =
img_picto(
'No photo', $prefix.$picto);
2251 $morehtmlleft .=
'<!-- No photo to show -->';
2252 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
2253 $morehtmlleft .= $nophoto;
2254 $morehtmlleft .=
'</div></div>';
2260 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$form->showbarcode($object, 100,
'photoref valignmiddle').
'</div>';
2263 if ($object->element ==
'societe') {
2264 if (!empty($conf->use_javascript_ajax) && $user->hasRight(
'societe',
'creer') && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
2265 $morehtmlstatus .=
ajax_object_onoff($object,
'status',
'status',
'InActivity',
'ActivityCeased');
2267 $morehtmlstatus .= $object->getLibStatut(6);
2269 } elseif ($object->element ==
'product') {
2271 if (!empty($conf->use_javascript_ajax) && $user->rights->produit->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
2272 $morehtmlstatus .=
ajax_object_onoff($object,
'status',
'tosell',
'ProductStatusOnSell',
'ProductStatusNotOnSell');
2274 $morehtmlstatus .=
'<span class="statusrefsell">'.$object->getLibStatut(6, 0).
'</span>';
2276 $morehtmlstatus .=
' ';
2278 if (!empty($conf->use_javascript_ajax) && $user->rights->produit->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
2279 $morehtmlstatus .=
ajax_object_onoff($object,
'status_buy',
'tobuy',
'ProductStatusOnBuy',
'ProductStatusNotOnBuy');
2281 $morehtmlstatus .=
'<span class="statusrefbuy">'.$object->getLibStatut(6, 1).
'</span>';
2283 } elseif (in_array($object->element, array(
'facture',
'invoice',
'invoice_supplier',
'chargesociales',
'loan',
'tva',
'salary'))) {
2284 $tmptxt = $object->getLibStatut(6, $object->totalpaid);
2285 if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
2286 $tmptxt = $object->getLibStatut(5, $object->totalpaid);
2288 $morehtmlstatus .= $tmptxt;
2289 } elseif ($object->element ==
'contrat' || $object->element ==
'contract') {
2290 if ($object->statut == 0) {
2291 $morehtmlstatus .= $object->getLibStatut(5);
2293 $morehtmlstatus .= $object->getLibStatut(4);
2295 } elseif ($object->element ==
'facturerec') {
2296 if ($object->frequency == 0) {
2297 $morehtmlstatus .= $object->getLibStatut(2);
2299 $morehtmlstatus .= $object->getLibStatut(5);
2301 } elseif ($object->element ==
'project_task') {
2302 $object->fk_statut = 1;
2303 if ($object->progress > 0) {
2304 $object->fk_statut = 2;
2306 if ($object->progress >= 100) {
2307 $object->fk_statut = 3;
2309 $tmptxt = $object->getLibStatut(5);
2310 $morehtmlstatus .= $tmptxt;
2311 } elseif (method_exists($object,
'getLibStatut')) {
2312 $tmptxt = $object->getLibStatut(6);
2313 if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
2314 $tmptxt = $object->getLibStatut(5);
2316 $morehtmlstatus .= $tmptxt;
2320 if (
isModEnabled(
'accounting') && in_array($object->element, array(
'bank',
'paiementcharge',
'facture',
'invoice',
'invoice_supplier',
'expensereport',
'payment_various'))) {
2322 if (method_exists($object,
'getVentilExportCompta')) {
2323 $accounted = $object->getVentilExportCompta();
2324 $langs->load(
"accountancy");
2325 $morehtmlstatus .=
'</div><div class="statusref statusrefbis"><span class="opacitymedium">'.($accounted > 0 ? $langs->trans(
"Accounted") : $langs->trans(
"NotYetAccounted")).
'</span>';
2330 if (!empty($object->name_alias)) {
2331 $morehtmlref .=
'<div class="refidno opacitymedium">'.$object->name_alias.
'</div>';
2335 if (in_array($object->element, array(
'product',
'bank_account',
'project_task'))) {
2336 if (!empty($object->label)) {
2337 $morehtmlref .=
'<div class="refidno opacitymedium">'.$object->label.
'</div>';
2342 if (method_exists($object,
'getBannerAddress') && !in_array($object->element, array(
'product',
'bookmark',
'ecm_directories',
'ecm_files'))) {
2343 $moreaddress = $object->getBannerAddress(
'refaddress', $object);
2345 $morehtmlref .=
'<div class="refidno refaddress">';
2346 $morehtmlref .= $moreaddress;
2347 $morehtmlref .=
'</div>';
2350 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)) {
2351 $morehtmlref .=
'<div style="clear: both;"></div>';
2352 $morehtmlref .=
'<div class="refidno opacitymedium">';
2353 $morehtmlref .= $langs->trans(
"TechnicalID").
': '.$object->id;
2354 $morehtmlref .=
'</div>';
2357 $parameters=array(
'morehtmlref'=>$morehtmlref);
2358 $reshook = $hookmanager->executeHooks(
'formDolBanner', $parameters, $object, $action);
2361 } elseif (empty($reshook)) {
2362 $morehtmlref .= $hookmanager->resPrint;
2363 } elseif ($reshook > 0) {
2364 $morehtmlref = $hookmanager->resPrint;
2368 print
'<div class="'.($onlybanner ?
'arearefnobottom ' :
'arearef ').
'heightref valignmiddle centpercent">';
2369 print
$form->showrefnav($object, $paramid, $morehtml, $shownav, $fieldid, $fieldref, $morehtmlref, $moreparam, $nodbprefix, $morehtmlleft, $morehtmlstatus, $morehtmlright);
2371 print
'<div class="underrefbanner clearboth"></div>';
2387 if ($fieldrequired) {
2388 $ret .=
'<span class="fieldrequired">';
2390 $ret .=
'<label for="'.$fieldkey.
'">';
2391 $ret .= $langs->trans($langkey);
2393 if ($fieldrequired) {
2409 $ret =
' '.$bc[$var];
2411 $ret = preg_replace(
'/class=\"/',
'class="'.$moreclass.
' ', $ret);
2429 function dol_format_address($object, $withcountry = 0, $sep =
"\n", $outputlangs =
'', $mode = 0, $extralangcode =
'')
2431 global $conf, $langs, $hookmanager;
2434 $countriesusingstate = array(
'AU',
'CA',
'US',
'IN',
'GB',
'ES',
'UK',
'TR',
'CN');
2439 $ret .= ($extralangcode ? $object->array_languages[
'address'][$extralangcode] : (empty($object->address) ?
'' : $object->address));
2442 if (isset($object->country_code) && in_array($object->country_code, array(
'AU',
'CA',
'US',
'CN')) || !empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS)) {
2444 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2445 $ret .= (($ret && $town) ? $sep :
'').$town;
2447 if (!empty($object->state)) {
2448 $ret .= ($ret ? ($town ?
", " : $sep) :
'').$object->state;
2450 if (!empty($object->zip)) {
2451 $ret .= ($ret ? (($town || $object->state) ?
", " : $sep) :
'').$object->zip;
2453 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'GB',
'UK'))) {
2455 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2456 $ret .= ($ret ? $sep :
'').$town;
2457 if (!empty($object->state)) {
2458 $ret .= ($ret ?
", " :
'').$object->state;
2460 if (!empty($object->zip)) {
2461 $ret .= ($ret ? $sep :
'').$object->zip;
2463 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'ES',
'TR'))) {
2465 $ret .= ($ret ? $sep :
'').$object->zip;
2466 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2467 $ret .= ($town ? (($object->zip ?
' ' :
'').$town) :
'');
2468 if (!empty($object->state)) {
2469 $ret .=
"\n".$object->state;
2471 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'JP'))) {
2474 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2475 $ret .= ($ret ? $sep :
'').($object->state ? $object->state.
', ' :
'').$town.($object->zip ?
' ' :
'').$object->zip;
2476 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'IT'))) {
2478 $ret .= ($ret ? $sep :
'').$object->zip;
2479 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2480 $ret .= ($town ? (($object->zip ?
' ' :
'').$town) :
'');
2481 $ret .= (empty($object->state_code) ?
'' : (
' '.$object->state_code));
2484 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2485 $ret .= !empty($object->zip) ? (($ret ? $sep :
'').$object->zip) :
'';
2486 $ret .= ($town ? (($object->zip ?
' ' : ($ret ? $sep :
'')).$town) :
'');
2487 if (!empty($object->state) && in_array($object->country_code, $countriesusingstate)) {
2488 $ret .= ($ret ?
", " :
'').$object->state;
2491 if (!is_object($outputlangs)) {
2492 $outputlangs = $langs;
2495 $langs->load(
"dict");
2496 $ret .= (empty($object->country_code) ?
'' : ($ret ? $sep :
'').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv(
"Country".$object->country_code)));
2499 $parameters = array(
'withcountry' => $withcountry,
'sep' => $sep,
'outputlangs' => $outputlangs,
'mode' => $mode,
'extralangcode' => $extralangcode);
2500 $reshook = $hookmanager->executeHooks(
'formatAddress', $parameters, $object);
2504 $ret .= $hookmanager->resPrint;
2522 if ((abs($ts) <= 0x7FFFFFFF)) {
2523 return ($is_gmt) ? @gmstrftime($fmt, $ts) : @strftime($fmt, $ts);
2525 return 'Error date into a not supported range';
2550 function dol_print_date($time, $format =
'', $tzoutput =
'auto', $outputlangs =
'', $encodetooutput =
false)
2552 global $conf, $langs;
2559 if ($tzoutput ===
'auto') {
2560 $tzoutput = (empty($conf) ?
'tzserver' : (isset($conf->tzuserinputkey) ? $conf->tzuserinputkey :
'tzserver'));
2565 $offsettz = $offsetdst = 0;
2568 if (is_string($tzoutput)) {
2569 if ($tzoutput ==
'tzserver') {
2571 $offsettzstring = @date_default_timezone_get();
2574 } elseif ($tzoutput ==
'tzuser' || $tzoutput ==
'tzuserrel') {
2576 $offsettzstring = (empty($_SESSION[
'dol_tz_string']) ?
'UTC' : $_SESSION[
'dol_tz_string']);
2578 if (class_exists(
'DateTimeZone')) {
2579 $user_date_tz =
new DateTimeZone($offsettzstring);
2580 $user_dt =
new DateTime();
2581 $user_dt->setTimezone($user_date_tz);
2582 $user_dt->setTimestamp($tzoutput ==
'tzuser' ?
dol_now() : (
int) $time);
2583 $offsettz = $user_dt->getOffset();
2585 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
2586 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
2591 if (!is_object($outputlangs)) {
2592 $outputlangs = $langs;
2595 $format =
'daytextshort';
2600 $reduceformat = (!empty($conf->dol_optimize_smallscreen) && in_array($format, array(
'day',
'dayhour'))) ? 1 : 0;
2601 $format = preg_replace(
'/inputnoreduce/',
'', $format);
2602 $formatwithoutreduce = preg_replace(
'/reduceformat/',
'', $format);
2603 if ($formatwithoutreduce != $format) {
2604 $format = $formatwithoutreduce;
2610 if ($format ==
'day') {
2611 $format = ($outputlangs->trans(
"FormatDateShort") !=
"FormatDateShort" ? $outputlangs->trans(
"FormatDateShort") : $conf->format_date_short);
2612 } elseif ($format ==
'hour') {
2613 $format = ($outputlangs->trans(
"FormatHourShort") !=
"FormatHourShort" ? $outputlangs->trans(
"FormatHourShort") : $conf->format_hour_short);
2614 } elseif ($format ==
'hourduration') {
2615 $format = ($outputlangs->trans(
"FormatHourShortDuration") !=
"FormatHourShortDuration" ? $outputlangs->trans(
"FormatHourShortDuration") : $conf->format_hour_short_duration);
2616 } elseif ($format ==
'daytext') {
2617 $format = ($outputlangs->trans(
"FormatDateText") !=
"FormatDateText" ? $outputlangs->trans(
"FormatDateText") : $conf->format_date_text);
2618 } elseif ($format ==
'daytextshort') {
2619 $format = ($outputlangs->trans(
"FormatDateTextShort") !=
"FormatDateTextShort" ? $outputlangs->trans(
"FormatDateTextShort") : $conf->format_date_text_short);
2620 } elseif ($format ==
'dayhour') {
2621 $format = ($outputlangs->trans(
"FormatDateHourShort") !=
"FormatDateHourShort" ? $outputlangs->trans(
"FormatDateHourShort") : $conf->format_date_hour_short);
2622 } elseif ($format ==
'dayhoursec') {
2623 $format = ($outputlangs->trans(
"FormatDateHourSecShort") !=
"FormatDateHourSecShort" ? $outputlangs->trans(
"FormatDateHourSecShort") : $conf->format_date_hour_sec_short);
2624 } elseif ($format ==
'dayhourtext') {
2625 $format = ($outputlangs->trans(
"FormatDateHourText") !=
"FormatDateHourText" ? $outputlangs->trans(
"FormatDateHourText") : $conf->format_date_hour_text);
2626 } elseif ($format ==
'dayhourtextshort') {
2627 $format = ($outputlangs->trans(
"FormatDateHourTextShort") !=
"FormatDateHourTextShort" ? $outputlangs->trans(
"FormatDateHourTextShort") : $conf->format_date_hour_text_short);
2628 } elseif ($format ==
'dayhourlog') {
2630 $format =
'%Y%m%d%H%M%S';
2631 } elseif ($format ==
'dayhourlogsmall') {
2633 $format =
'%y%m%d%H%M';
2634 } elseif ($format ==
'dayhourldap') {
2635 $format =
'%Y%m%d%H%M%SZ';
2636 } elseif ($format ==
'dayhourxcard') {
2637 $format =
'%Y%m%dT%H%M%SZ';
2638 } elseif ($format ==
'dayxcard') {
2640 } elseif ($format ==
'dayrfc') {
2641 $format =
'%Y-%m-%d';
2642 } elseif ($format ==
'dayhourrfc') {
2643 $format =
'%Y-%m-%dT%H:%M:%SZ';
2644 } elseif ($format ==
'standard') {
2645 $format =
'%Y-%m-%d %H:%M:%S';
2648 if ($reduceformat) {
2649 $format = str_replace(
'%Y',
'%y', $format);
2650 $format = str_replace(
'yyyy',
'yy', $format);
2654 if (preg_match(
'/%b/i', $format)) {
2656 $format = str_replace(
'%b',
'__b__', $format);
2657 $format = str_replace(
'%B',
'__B__', $format);
2659 if (preg_match(
'/%a/i', $format)) {
2661 $format = str_replace(
'%a',
'__a__', $format);
2662 $format = str_replace(
'%A',
'__A__', $format);
2667 if (!empty($useadodb)) {
2668 include_once DOL_DOCUMENT_ROOT.
'/includes/adodbtime/adodb-time.inc.php';
2673 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)) {
2674 dol_print_error(
'',
"Functions.lib::dol_print_date function called with a bad value from page ".$_SERVER[
"PHP_SELF"]);
2676 } elseif (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $time, $reg)) {
2678 dol_syslog(
"Functions.lib::dol_print_date function called with a bad value from page ".$_SERVER[
"PHP_SELF"], LOG_WARNING);
2681 $syear = (!empty($reg[1]) ? $reg[1] :
'');
2682 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
2683 $sday = (!empty($reg[3]) ? $reg[3] :
'');
2684 $shour = (!empty($reg[4]) ? $reg[4] :
'');
2685 $smin = (!empty($reg[5]) ? $reg[5] :
'');
2686 $ssec = (!empty($reg[6]) ? $reg[6] :
'');
2688 $time =
dol_mktime($shour, $smin, $ssec, $smonth, $sday, $syear,
true);
2689 if (empty($useadodb)) {
2691 $tzo =
new DateTimeZone(
'UTC');
2693 $tzo =
new DateTimeZone(date_default_timezone_get());
2695 $dtts =
new DateTime();
2696 $dtts->setTimestamp($time);
2697 $dtts->setTimezone($tzo);
2698 $newformat = str_replace(
2699 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'%w',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2700 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'w',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2702 $ret = $dtts->format($newformat);
2704 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2705 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2708 $ret = adodb_strftime($format, $time + $offsettz + $offsetdst, $to_gmt);
2712 if ($time < 100000000000) {
2713 $timetouse = $time + $offsettz + $offsetdst;
2715 if (empty($useadodb)) {
2717 $tzo =
new DateTimeZone(
'UTC');
2719 $tzo =
new DateTimeZone(date_default_timezone_get());
2721 $dtts =
new DateTime();
2722 $dtts->setTimestamp($timetouse);
2723 $dtts->setTimezone($tzo);
2724 $newformat = str_replace(
2725 array(
'%Y',
'%y',
'%m',
'%d',
'%H',
'%I',
'%M',
'%S',
'%p',
'%w',
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2726 array(
'Y',
'y',
'm',
'd',
'H',
'h',
'i',
's',
'A',
'w',
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2728 $ret = $dtts->format($newformat);
2730 array(
'__£__',
'__$__',
'__{__',
'__}__',
'__[__',
'__]__'),
2731 array(
'T',
'Z',
'__a__',
'__A__',
'__b__',
'__B__'),
2734 $ret = adodb_strftime($format, $timetouse, $to_gmt);
2738 $ret =
'Bad value '.$time.
' for date';
2742 if (preg_match(
'/__b__/i', $format)) {
2743 $timetouse = $time + $offsettz + $offsetdst;
2745 if (empty($useadodb)) {
2747 $tzo =
new DateTimeZone(
'UTC');
2749 $tzo =
new DateTimeZone(date_default_timezone_get());
2751 $dtts =
new DateTime();
2752 $dtts->setTimestamp($timetouse);
2753 $dtts->setTimezone($tzo);
2754 $month = $dtts->format(
"m");
2757 $month = adodb_strftime(
'%m', $timetouse, $to_gmt);
2759 $month = sprintf(
"%02d", $month);
2760 if ($encodetooutput) {
2761 $monthtext = $outputlangs->transnoentities(
'Month'.$month);
2762 $monthtextshort = $outputlangs->transnoentities(
'MonthShort'.$month);
2764 $monthtext = $outputlangs->transnoentitiesnoconv(
'Month'.$month);
2765 $monthtextshort = $outputlangs->transnoentitiesnoconv(
'MonthShort'.$month);
2768 $ret = str_replace(
'__b__', $monthtextshort, $ret);
2769 $ret = str_replace(
'__B__', $monthtext, $ret);
2773 if (preg_match(
'/__a__/i', $format)) {
2775 $timetouse = $time + $offsettz + $offsetdst;
2777 if (empty($useadodb)) {
2779 $tzo =
new DateTimeZone(
'UTC');
2781 $tzo =
new DateTimeZone(date_default_timezone_get());
2783 $dtts =
new DateTime();
2784 $dtts->setTimestamp($timetouse);
2785 $dtts->setTimezone($tzo);
2786 $w = $dtts->format(
"w");
2788 $w = adodb_strftime(
'%w', $timetouse, $to_gmt);
2790 $dayweek = $outputlangs->transnoentitiesnoconv(
'Day'.$w);
2792 $ret = str_replace(
'__A__', $dayweek, $ret);
2793 $ret = str_replace(
'__a__',
dol_substr($dayweek, 0, 3), $ret);
2822 $datetimeobj =
new DateTime();
2823 $datetimeobj->setTimestamp($timestamp);
2824 if ($forcetimezone) {
2825 $datetimeobj->setTimezone(
new DateTimeZone($forcetimezone ==
'gmt' ?
'UTC' : $forcetimezone));
2828 'year'=>((
int) date_format($datetimeobj,
'Y')),
2829 'mon'=>((
int) date_format($datetimeobj,
'm')),
2830 'mday'=>((
int) date_format($datetimeobj,
'd')),
2831 'wday'=>((
int) date_format($datetimeobj,
'w')),
2832 'yday'=>((
int) date_format($datetimeobj,
'z')),
2833 'hours'=>((
int) date_format($datetimeobj,
'H')),
2834 'minutes'=>((
int) date_format($datetimeobj,
'i')),
2835 'seconds'=>((
int) date_format($datetimeobj,
's')),
2863 function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm =
'auto', $check = 1)
2868 if ($gm ===
'auto') {
2869 $gm = (empty($conf) ?
'tzserver' : $conf->tzuserinputkey);
2874 if ($hour == -1 || empty($hour)) {
2877 if ($minute == -1 || empty($minute)) {
2880 if ($second == -1 || empty($second)) {
2886 if (!$month || !$day) {
2895 if ($hour < 0 || $hour > 24) {
2898 if ($minute < 0 || $minute > 60) {
2901 if ($second < 0 || $second > 60) {
2906 if (empty($gm) || ($gm ===
'server' || $gm ===
'tzserver')) {
2907 $default_timezone = @date_default_timezone_get();
2908 $localtz =
new DateTimeZone($default_timezone);
2909 } elseif ($gm ===
'user' || $gm ===
'tzuser' || $gm ===
'tzuserrel') {
2911 $default_timezone = (empty($_SESSION[
"dol_tz_string"]) ? @date_default_timezone_get() : $_SESSION[
"dol_tz_string"]);
2913 $localtz =
new DateTimeZone($default_timezone);
2915 dol_syslog(
"Warning dol_tz_string contains an invalid value ".$_SESSION[
"dol_tz_string"], LOG_WARNING);
2916 $default_timezone = @date_default_timezone_get();
2918 } elseif (strrpos($gm,
"tz,") !==
false) {
2919 $timezone = str_replace(
"tz,",
"", $gm);
2921 $localtz =
new DateTimeZone($timezone);
2923 dol_syslog(
"Warning passed timezone contains an invalid value ".$timezone, LOG_WARNING);
2927 if (empty($localtz)) {
2928 $localtz =
new DateTimeZone(
'UTC');
2932 $dt =
new DateTime(
'now', $localtz);
2933 $dt->setDate((
int) $year, (
int) $month, (
int) $day);
2934 $dt->setTime((
int) $hour, (
int) $minute, (
int) $second);
2935 $date = $dt->getTimestamp();
2955 if ($mode ===
'auto') {
2959 if ($mode ==
'gmt') {
2961 } elseif ($mode ==
'tzserver') {
2962 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2964 $ret = (int) (
dol_now(
'gmt') + ($tzsecond * 3600));
2970 } elseif ($mode ==
'tzuser' || $mode ==
'tzuserrel') {
2973 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
2974 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
2975 $ret = (int) (
dol_now(
'gmt') + ($offsettz + $offsetdst));
2992 global $conf, $langs;
2995 if (!empty($conf->dol_optimize_smallscreen)) {
3000 if (empty($shortvalue) || $size < ($level * 10)) {
3002 $textunitshort = $langs->trans(
"b");
3003 $textunitlong = $langs->trans(
"Bytes");
3005 $ret = round($size / $level, 0);
3006 $textunitshort = $langs->trans(
"Kb");
3007 $textunitlong = $langs->trans(
"KiloBytes");
3010 if (empty($shortunit)) {
3011 $ret .=
' '.$textunitlong;
3013 $ret .=
' '.$textunitshort;
3036 $link =
'<a href="';
3037 if (!preg_match(
'/^http/i', $url)) {
3043 $link .=
' target="'.$target.
'"';
3046 if (!preg_match(
'/^http/i', $url)) {
3051 return '<div class="nospan float" style="margin-right: 10px">'.($withpicto ?
img_picto($langs->trans(
"Url"),
'globe').
' ' :
'').$link.
'</div>';
3066 function dol_print_email($email, $cid = 0, $socid = 0, $addlink = 0, $max = 64, $showinvalid = 1, $withpicto = 0)
3068 global $conf, $user, $langs, $hookmanager;
3072 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) {
3076 if (empty($email)) {
3080 if (!empty($addlink)) {
3081 $newemail =
'<a style="text-overflow: ellipsis;" href="';
3082 if (!preg_match(
'/^mailto:/i', $email)) {
3083 $newemail .=
'mailto:';
3085 $newemail .= $email;
3088 $newemail .=
'</a>';
3090 $langs->load(
"errors");
3091 $newemail .=
img_warning($langs->trans(
"ErrorBadEMail", $email));
3094 if (($cid || $socid) &&
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
3097 if (!empty($conf->global->AGENDA_ADDACTIONFOREMAIL)) {
3098 $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>';
3101 $newemail =
'<div>'.$newemail.
' '.$link.
'</div>';
3106 $langs->load(
"errors");
3107 $newemail .=
img_warning($langs->trans(
"ErrorBadEMail", $email));
3112 $rep = ($withpicto ?
img_picto($langs->trans(
"EMail").
' : '.$email, (is_numeric($withpicto) ?
'email' : $withpicto)).
' ' :
'').$newemail;
3115 $parameters = array(
'cid' => $cid,
'socid' => $socid,
'addlink' => $addlink,
'picto' => $withpicto);
3117 $reshook = $hookmanager->executeHooks(
'printEmail', $parameters, $email);
3121 $rep .= $hookmanager->resPrint;
3136 $socialnetworks = array();
3138 require_once DOL_DOCUMENT_ROOT.
'/core/lib/memory.lib.php';
3139 $cachekey =
'socialnetworks_' . $conf->entity;
3141 if (!is_null($dataretrieved)) {
3142 $socialnetworks = $dataretrieved;
3144 $sql =
"SELECT rowid, code, label, url, icon, active FROM ".MAIN_DB_PREFIX.
"c_socialnetworks";
3145 $sql .=
" WHERE entity=".$conf->entity;
3146 $resql = $db->query($sql);
3148 while ($obj = $db->fetch_object(
$resql)) {
3149 $socialnetworks[$obj->code] = array(
3150 'rowid' => $obj->rowid,
3151 'label' => $obj->label,
3153 'icon' => $obj->icon,
3154 'active' => $obj->active,
3161 return $socialnetworks;
3176 global $conf, $user, $langs;
3180 if (empty($value)) {
3184 if (!empty($type)) {
3185 $htmllink =
'<div class="divsocialnetwork inline-block valignmiddle">';
3187 $htmllink .=
'<span class="fa paddingright '.($dictsocialnetworks[$type][
'icon'] ? $dictsocialnetworks[$type][
'icon'] :
'fa-link').
'"></span>';
3188 if ($type ==
'skype') {
3190 $htmllink .=
' ';
3191 $htmllink .=
'<a href="skype:';
3193 $htmllink .=
'?call" alt="'.$langs->trans(
"Call").
' '.$value.
'" title="'.
dol_escape_htmltag($langs->trans(
"Call").
' '.$value).
'">';
3194 $htmllink .=
'<img src="'.DOL_URL_ROOT.
'/theme/common/skype_callbutton.png" border="0">';
3195 $htmllink .=
'</a><a href="skype:';
3197 $htmllink .=
'?chat" alt="'.$langs->trans(
"Chat").
' '.$value.
'" title="'.
dol_escape_htmltag($langs->trans(
"Chat").
' '.$value).
'">';
3198 $htmllink .=
'<img class="paddingleft" src="'.DOL_URL_ROOT.
'/theme/common/skype_chatbutton.png" border="0">';
3199 $htmllink .=
'</a>';
3200 if (($cid || $socid) &&
isModEnabled(
'agenda') && $user->rights->agenda->myactions->create) {
3201 $addlink =
'AC_SKYPE';
3203 if (!empty($conf->global->AGENDA_ADDACTIONFORSKYPE)) {
3204 $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>';
3206 $htmllink .= ($link ?
' '.$link :
'');
3209 if (!empty($dictsocialnetworks[$type][
'url'])) {
3210 $tmpvirginurl = preg_replace(
'/\/?{socialid}/',
'', $dictsocialnetworks[$type][
'url']);
3211 if ($tmpvirginurl) {
3212 $value = preg_replace(
'/^www\.'.preg_quote($tmpvirginurl,
'/').
'\/?/',
'', $value);
3213 $value = preg_replace(
'/^'.preg_quote($tmpvirginurl,
'/').
'\/?/',
'', $value);
3215 $tmpvirginurl3 = preg_replace(
'/^https:\/\//i',
'https://www.', $tmpvirginurl);
3216 if ($tmpvirginurl3) {
3217 $value = preg_replace(
'/^www\.'.preg_quote($tmpvirginurl3,
'/').
'\/?/',
'', $value);
3218 $value = preg_replace(
'/^'.preg_quote($tmpvirginurl3,
'/').
'\/?/',
'', $value);
3221 $tmpvirginurl2 = preg_replace(
'/^https?:\/\//i',
'', $tmpvirginurl);
3222 if ($tmpvirginurl2) {
3223 $value = preg_replace(
'/^www\.'.preg_quote($tmpvirginurl2,
'/').
'\/?/',
'', $value);
3224 $value = preg_replace(
'/^'.preg_quote($tmpvirginurl2,
'/').
'\/?/',
'', $value);
3227 $link = str_replace(
'{socialid}', $value, $dictsocialnetworks[$type][
'url']);
3228 if (preg_match(
'/^https?:\/\//i', $link)) {
3229 $htmllink .=
' <a href="'.dol_sanitizeUrl($link, 0).
'" target="_blank" rel="noopener noreferrer">'.
dol_escape_htmltag($value).
'</a>';
3231 $htmllink .=
' <a href="'.dol_sanitizeUrl($link, 1).
'" target="_blank" rel="noopener noreferrer">'.
dol_escape_htmltag($value).
'</a>';
3237 $htmllink .=
'</div>';
3239 $langs->load(
"errors");
3240 $htmllink .=
img_warning($langs->trans(
"ErrorBadSocialNetworkValue", $value));
3255 function dol_print_profids($profID, $profIDtype, $countrycode =
'', $addcpButton = 1, $separ =
' ')
3259 if (empty($profID) || empty($profIDtype)) {
3262 if (empty($countrycode)) $countrycode = $mysoc->country_code;
3263 $newProfID = $profID;
3264 $id = substr($profIDtype, -1);
3266 if (strtoupper($countrycode) ==
'FR') {
3268 if ($id == 1 &&
dol_strlen($newProfID) == 9) $newProfID = substr($newProfID, 0, 3).$separ.substr($newProfID, 3, 3).$separ.substr($newProfID, 6, 3);
3269 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);
3270 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);
3273 else $ret = $newProfID;
3291 function dol_print_phone($phone, $countrycode =
'', $cid = 0, $socid = 0, $addlink =
'', $separ =
" ", $withpicto =
'', $titlealt =
'', $adddivfloat = 0)
3293 global $conf, $user, $langs, $mysoc, $hookmanager;
3296 $phone = is_null($phone) ?
'' : preg_replace(
"/[\s.-]/",
"", trim($phone));
3297 if (empty($phone)) {
3300 if (!empty($conf->global->MAIN_PHONE_SEPAR)) {
3301 $separ = $conf->global->MAIN_PHONE_SEPAR;
3303 if (empty($countrycode) && is_object($mysoc)) {
3304 $countrycode = $mysoc->country_code;
3308 if ($conf->dol_optimize_smallscreen) {
3313 if (strtoupper($countrycode) ==
"FR") {
3316 $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);
3318 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 2).$separ.substr($newphone, 5, 2);
3320 $newphone = substr($newphone, 0, 2).$separ.substr($newphone, 2, 3).$separ.substr($newphone, 5, 2).$separ.substr($newphone, 7, 2);
3322 $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);
3324 $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);
3326 $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);
3328 } elseif (strtoupper($countrycode) ==
"CA") {
3330 $newphone = ($separ !=
'' ?
'(' :
'').substr($newphone, 0, 3).($separ !=
'' ?
')' :
'').$separ.substr($newphone, 3, 3).($separ !=
'' ?
'-' :
'').substr($newphone, 6, 4);
3332 } elseif (strtoupper($countrycode) ==
"PT") {
3334 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3336 } elseif (strtoupper($countrycode) ==
"SR") {
3338 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3);
3340 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 4);
3342 } elseif (strtoupper($countrycode) ==
"DE") {
3344 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 4).$separ.substr($newphone, 11, 3);
3346 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 4).$separ.substr($newphone, 10, 3);
3348 } elseif (strtoupper($countrycode) ==
"ES") {
3350 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3352 } elseif (strtoupper($countrycode) ==
"BF") {
3354 $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);
3356 } elseif (strtoupper($countrycode) ==
"RO") {
3358 $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);
3360 } elseif (strtoupper($countrycode) ==
"TR") {
3362 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 4);
3364 } elseif (strtoupper($countrycode) ==
"US") {
3366 $newphone = substr($newphone, 0, 2).$separ.substr($newphone, 2, 3).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 4);
3368 } elseif (strtoupper($countrycode) ==
"MX") {
3370 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 2);
3372 $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);
3374 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 4);
3376 } elseif (strtoupper($countrycode) ==
"ML") {
3378 $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);
3380 } elseif (strtoupper($countrycode) ==
"TH") {
3382 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 3);
3384 $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);
3386 } elseif (strtoupper($countrycode) ==
"MU") {
3389 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 2).$separ.substr($newphone, 9, 2);
3391 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 4).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 2);
3393 } elseif (strtoupper($countrycode) ==
"ZA") {
3395 $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);
3397 } elseif (strtoupper($countrycode) ==
"SY") {
3399 $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);
3401 $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);
3403 } elseif (strtoupper($countrycode) ==
"AE") {
3405 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 2);
3407 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3409 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 4);
3411 } elseif (strtoupper($countrycode) ==
"DZ") {
3413 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3415 } elseif (strtoupper($countrycode) ==
"BE") {
3417 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 3);
3419 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3421 } elseif (strtoupper($countrycode) ==
"PF") {
3423 $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);
3425 } elseif (strtoupper($countrycode) ==
"CO") {
3427 $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);
3429 } elseif (strtoupper($countrycode) ==
"JO") {
3431 $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);
3433 } elseif (strtoupper($countrycode) ==
"JM") {
3435 $newphone = substr($newphone, 0, 5).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 4);
3437 } elseif (strtoupper($countrycode) ==
"MG") {
3439 $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);
3441 } elseif (strtoupper($countrycode) ==
"GB") {
3443 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3445 } elseif (strtoupper($countrycode) ==
"CH") {
3447 $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);
3449 $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);
3451 } elseif (strtoupper($countrycode) ==
"TN") {
3453 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3455 } elseif (strtoupper($countrycode) ==
"GF") {
3457 $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);
3459 } elseif (strtoupper($countrycode) ==
"GP") {
3461 $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);
3463 } elseif (strtoupper($countrycode) ==
"MQ") {
3465 $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);
3467 } elseif (strtoupper($countrycode) ==
"IT") {
3469 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3471 $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);
3473 } elseif (strtoupper($countrycode) ==
"AU") {
3477 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 1).$separ.substr($newphone, 4, 4).$separ.substr($newphone, 8, 4);
3479 } elseif (strtoupper($countrycode) ==
"LU") {
3482 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 2);
3484 $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);
3486 $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);
3488 $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);
3491 if (!empty($addlink)) {
3492 if ($conf->browser->layout ==
'phone' || (
isModEnabled(
'clicktodial') && !empty($conf->global->CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS))) {
3493 $newphoneform = $newphone;
3494 $newphone =
'<a href="tel:'.$phone.
'"';
3495 $newphone .=
'>'.$newphoneform.
'</a>';
3496 } elseif (
isModEnabled(
'clicktodial') && $addlink ==
'AC_TEL') {
3497 if (empty($user->clicktodial_loaded)) {
3498 $user->fetch_clicktodial();
3502 $urlmask =
'ErrorClickToDialModuleNotConfigured';
3503 if (!empty($conf->global->CLICKTODIAL_URL)) {
3504 $urlmask = $conf->global->CLICKTODIAL_URL;
3506 if (!empty($user->clicktodial_url)) {
3507 $urlmask = $user->clicktodial_url;
3510 $clicktodial_poste = (!empty($user->clicktodial_poste) ?urlencode($user->clicktodial_poste) :
'');
3511 $clicktodial_login = (!empty($user->clicktodial_login) ?urlencode($user->clicktodial_login) :
'');
3512 $clicktodial_password = (!empty($user->clicktodial_password) ?urlencode($user->clicktodial_password) :
'');
3514 $url = sprintf($urlmask, urlencode($phone), $clicktodial_poste, $clicktodial_login, $clicktodial_password);
3516 $substitarray = array(
'__PHONEFROM__'=>$clicktodial_poste,
3517 '__PHONETO__'=>urlencode($phone),
3518 '__LOGIN__'=>$clicktodial_login,
3519 '__PASS__'=>$clicktodial_password);
3521 $newphonesav = $newphone;
3522 if (empty($conf->global->CLICKTODIAL_DO_NOT_USE_AJAX_CALL)) {
3524 $newphone =
'<a href="'.$url.
'" class="cssforclicktodial"';
3525 $newphone .=
'>'.$newphonesav.
'</a>';
3528 $newphone =
'<a href="'.$url.
'"';
3529 if (!empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) {
3530 $newphone .=
' target="_blank" rel="noopener noreferrer"';
3532 $newphone .=
'>'.$newphonesav.
'</a>';
3537 if (
isModEnabled(
'agenda') && $user->hasRight(
"agenda",
"myactions",
"create")) {
3540 if ($addlink ==
'AC_FAX') {
3543 if (!empty($conf->global->AGENDA_ADDACTIONFORPHONE)) {
3544 $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>';
3547 $newphone =
'<div>'.$newphone.
' '.$link.
'</div>';
3552 if (empty($titlealt)) {
3553 $titlealt = ($withpicto ==
'fax' ? $langs->trans(
"Fax") : $langs->trans(
"Phone"));
3558 $parameters = array(
'countrycode' => $countrycode,
'cid' => $cid,
'socid' => $socid,
'titlealt' => $titlealt,
'picto' => $withpicto);
3559 $reshook = $hookmanager->executeHooks(
'printPhone', $parameters, $phone);
3560 $rep .= $hookmanager->resPrint;
3562 if (empty($reshook)) {
3565 if ($withpicto ==
'fax') {
3566 $picto =
'phoning_fax';
3567 } elseif ($withpicto ==
'phone') {
3569 } elseif ($withpicto ==
'mobile') {
3570 $picto =
'phoning_mobile';
3575 if ($adddivfloat == 1) {
3576 $rep .=
'<div class="nospan float" style="margin-right: 10px">';
3577 } elseif (empty($adddivfloat)) {
3578 $rep .=
'<span style="margin-right: 10px;">';
3580 $rep .= ($withpicto ?
img_picto($titlealt,
'object_'.$picto.
'.png').
' ' :
'').$newphone;
3581 if ($adddivfloat == 1) {
3583 } elseif (empty($adddivfloat)) {
3600 global $conf, $langs;
3611 if (file_exists(DOL_DOCUMENT_ROOT.
'/theme/common/flags/'.$countrycode.
'.png')) {
3612 $ret .=
' '.img_picto($countrycode.
' '.$langs->trans(
"AccordingToGeoIPDatabase"), DOL_URL_ROOT.
'/theme/common/flags/'.$countrycode.
'.png',
'', 1);
3614 $ret .=
' ('.$countrycode.
')';
3634 if (empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) || preg_match(
'/[^0-9\.\:,\[\]]/', $_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
3635 if (empty($_SERVER[
'HTTP_CLIENT_IP']) || preg_match(
'/[^0-9\.\:,\[\]]/', $_SERVER[
'HTTP_CLIENT_IP'])) {
3636 if (empty($_SERVER[
"HTTP_CF_CONNECTING_IP"])) {
3637 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
3639 $ip = $_SERVER[
"HTTP_CF_CONNECTING_IP"];
3642 $ip = $_SERVER[
'HTTP_CLIENT_IP'];
3645 $ip = $_SERVER[
'HTTP_X_FORWARDED_FOR'];
3661 if (isset($_SERVER[
'HTTPS']) && $_SERVER[
'HTTPS'] ==
'on') {
3663 } 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') {
3681 if (!empty($conf->geoipmaxmind->enabled)) {
3685 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeoip.class.php';
3686 $geoip =
new DolGeoIP(
'country', $datafile);
3688 $countrycode = $geoip->getCountryCodeFromIP($ip);
3691 return $countrycode;
3703 global $conf, $langs, $user;
3707 if (!empty($conf->geoipmaxmind->enabled)) {
3712 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeoip.class.php';
3713 $geoip =
new DolGeoIP(
'country', $datafile);
3714 $countrycode = $geoip->getCountryCodeFromIP($ip);
3715 $ret = $countrycode;
3734 global $conf, $user, $langs, $hookmanager;
3740 $parameters = array(
'element' => $element,
'id' => $id);
3741 $reshook = $hookmanager->executeHooks(
'printAddress', $parameters, $address);
3742 $out .= $hookmanager->resPrint;
3744 if (empty($reshook)) {
3745 if (empty($charfornl)) {
3746 $out .= nl2br($address);
3748 $out .= preg_replace(
'/[\r\n]+/', $charfornl, $address);
3752 $showgmap = $showomap = 0;
3753 if (($element ==
'thirdparty' || $element ==
'societe') && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS)) {
3756 if ($element ==
'contact' && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS)) {
3759 if ($element ==
'member' && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS)) {
3762 if (($element ==
'thirdparty' || $element ==
'societe') && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS)) {
3765 if ($element ==
'contact' && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS)) {
3768 if ($element ==
'member' && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS)) {
3772 $url =
dol_buildpath(
'/google/gmaps.php?mode='.$element.
'&id='.$id, 1);
3773 $out .=
' <a href="'.$url.
'" target="_gmaps"><img id="'.$htmlid.
'" class="valigntextbottom" src="'.DOL_URL_ROOT.
'/theme/common/gmap.png"></a>';
3776 $url =
dol_buildpath(
'/openstreetmap/maps.php?mode='.$element.
'&id='.$id, 1);
3777 $out .=
' <a href="'.$url.
'" target="_gmaps"><img id="'.$htmlid.
'_openstreetmap" class="valigntextbottom" src="'.DOL_URL_ROOT.
'/theme/common/gmap.png"></a>';
3798 function isValidEmail($address, $acceptsupervisorkey = 0, $acceptuserkey = 0)
3800 if ($acceptsupervisorkey && $address ==
'__SUPERVISOREMAIL__') {
3803 if ($acceptuserkey && $address ==
'__USER_EMAIL__') {
3806 if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
3823 if (function_exists(
'idn_to_ascii') && function_exists(
'checkdnsrr')) {
3824 if (!checkdnsrr(idn_to_ascii($domain),
'MX')) {
3827 if (function_exists(
'getmxrr')) {
3830 getmxrr(idn_to_ascii($domain), $mxhosts, $weight);
3831 if (count($mxhosts) > 1) {
3834 if (count($mxhosts) == 1 && !empty($mxhosts[0])) {
3871 $tmparray = explode(
' ', $s);
3872 foreach ($tmparray as $tmps) {
3889 if (is_null($string)) {
3893 if (function_exists(
'mb_strlen')) {
3894 return mb_strlen($string, $stringencoding);
3896 return strlen($string);
3910 function dol_substr($string, $start, $length, $stringencoding =
'', $trunconbytes = 0)
3914 if (empty($stringencoding)) {
3915 $stringencoding = $langs->charset_output;
3919 if (empty($trunconbytes)) {
3920 if (function_exists(
'mb_substr')) {
3921 $ret = mb_substr($string, $start, $length, $stringencoding);
3923 $ret = substr($string, $start, $length);
3926 if (function_exists(
'mb_strcut')) {
3927 $ret = mb_strcut($string, $start, $length, $stringencoding);
3929 $ret = substr($string, $start, $length);
3949 function dol_trunc($string, $size = 40, $trunc =
'right', $stringencoding =
'UTF-8', $nodot = 0, $display = 0)
3953 if (empty($size) || !empty($conf->global->MAIN_DISABLE_TRUNC)) {
3957 if (empty($stringencoding)) {
3958 $stringencoding =
'UTF-8';
3961 if ($conf->dol_optimize_smallscreen == 1 && $display == 1) {
3962 $size = round($size / 3);
3966 if ($trunc ==
'right') {
3968 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
3970 return dol_substr($newstring, 0, $size, $stringencoding).($nodot ?
'' :
'…');
3975 } elseif ($trunc ==
'middle') {
3977 if (
dol_strlen($newstring, $stringencoding) > 2 &&
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
3978 $size1 = round($size / 2);
3979 $size2 = round($size / 2);
3980 return dol_substr($newstring, 0, $size1, $stringencoding).
'…'.
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
3984 } elseif ($trunc ==
'left') {
3986 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
3988 return '…'.dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
3992 } elseif ($trunc ==
'wrap') {
3994 if (
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
4000 return 'BadParam3CallingDolTrunc';
4024 function img_picto($titlealt, $picto, $moreatt =
'', $pictoisfullpath =
false, $srconly = 0, $notitle = 0, $alt =
'', $morecss =
'', $marginleftonlyshort = 2)
4026 global $conf, $langs;
4029 $url = DOL_URL_ROOT;
4030 $theme = isset($conf->theme) ? $conf->theme :
null;
4031 $path =
'theme/'.$theme;
4033 if ($pictoisfullpath) {
4035 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
4038 $fullpathpicto = $picto;
4040 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
4041 $morecss .= ($morecss ?
' ' :
'').$reg[1];
4042 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
4045 $pictowithouttext = preg_replace(
'/(\.png|\.gif|\.svg)$/',
'', $picto);
4046 $pictowithouttext = str_replace(
'object_',
'', $pictowithouttext);
4048 if (strpos($pictowithouttext,
'fontawesome_') !==
false || preg_match(
'/^fa-/', $pictowithouttext)) {
4050 $pictowithouttext = str_replace(
'fontawesome_',
'', $pictowithouttext);
4051 $pictowithouttext = str_replace(
'fa-',
'', $pictowithouttext);
4053 $pictowithouttextarray = explode(
'_', $pictowithouttext);
4054 $marginleftonlyshort = 0;
4056 if (!empty($pictowithouttextarray[1])) {
4058 $fakey =
'fa-'.$pictowithouttextarray[0];
4059 $fa = empty($pictowithouttextarray[1]) ?
'fa' : $pictowithouttextarray[1];
4060 $facolor = empty($pictowithouttextarray[2]) ?
'' : $pictowithouttextarray[2];
4061 $fasize = empty($pictowithouttextarray[3]) ?
'' : $pictowithouttextarray[3];
4063 $fakey =
'fa-'.$pictowithouttext;
4073 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
4074 $morecss .= ($morecss ?
' ' :
'').$reg[1];
4075 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
4077 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
4078 $morestyle = $reg[1];
4079 $moreatt = str_replace(
'style="'.$reg[1].
'"',
'', $moreatt);
4081 $moreatt = trim($moreatt);
4083 $enabledisablehtml =
'<span class="'.$fa.
' '.$fakey.($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
4084 $enabledisablehtml .= ($morecss ?
' '.$morecss :
'').
'" style="'.($fasize ? (
'font-size: '.$fasize.
';') :
'').($facolor ? (
' color: '.$facolor.
';') :
'').($morestyle ?
' '.$morestyle :
'').
'"'.(($notitle || empty($titlealt)) ?
'' :
' title="'.
dol_escape_htmltag($titlealt).
'"').($moreatt ?
' '.$moreatt :
'').
'>';
4088 $enabledisablehtml .=
'</span>';
4090 return $enabledisablehtml;
4093 if (empty($srconly) && in_array($pictowithouttext, array(
4094 '1downarrow',
'1uparrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected',
4095 'accountancy',
'accounting_account',
'account',
'accountline',
'action',
'add',
'address',
'angle-double-down',
'angle-double-up',
'asset',
4096 'bank_account',
'barcode',
'bank',
'bell',
'bill',
'billa',
'billr',
'billd',
'bookmark',
'bom',
'briefcase-medical',
'bug',
'building',
4097 'card',
'calendarlist',
'calendar',
'calendarmonth',
'calendarweek',
'calendarday',
'calendarperuser',
'calendarpertype',
4098 'cash-register',
'category',
'chart',
'check',
'clock',
'close_title',
'cog',
'collab',
'company',
'contact',
'country',
'contract',
'conversation',
'cron',
'cubes',
4099 'currency',
'multicurrency',
4100 'delete',
'dolly',
'dollyrevert',
'donation',
'download',
'dynamicprice',
4101 'edit',
'ellipsis-h',
'email',
'entity',
'envelope',
'eraser',
'establishment',
'expensereport',
'external-link-alt',
'external-link-square-alt',
'eye',
4102 'filter',
'file-code',
'file-export',
'file-import',
'file-upload',
'autofill',
'folder',
'folder-open',
'folder-plus',
4103 'gears',
'generate',
'globe',
'globe-americas',
'graph',
'grip',
'grip_title',
'group',
4105 'images',
'incoterm',
'info',
'intervention',
'inventory',
'intracommreport',
'jobprofile',
4106 'knowledgemanagement',
4107 'label',
'language',
'line',
'link',
'list',
'list-alt',
'listlight',
'loan',
'lock',
'lot',
'long-arrow-alt-right',
4108 'margin',
'map-marker-alt',
'member',
'meeting',
'money-bill-alt',
'movement',
'mrp',
'note',
'next',
4109 'off',
'on',
'order',
4110 'paiment',
'paragraph',
'play',
'pdf',
'phone',
'phoning',
'phoning_mobile',
'phoning_fax',
'playdisabled',
'previous',
'poll',
'pos',
'printer',
'product',
'propal',
'proposal',
'puce',
4111 'stock',
'resize',
'service',
'stats',
'trip',
4112 'security',
'setup',
'share-alt',
'sign-out',
'split',
'stripe',
'stripe-s',
'switch_off',
'switch_on',
'switch_on_red',
'tools',
'unlink',
'uparrow',
'user',
'user-tie',
'vcard',
'wrench',
4113 'github',
'google',
'jabber',
'microsoft',
'skype',
'twitter',
'facebook',
'linkedin',
'instagram',
'snapchat',
'youtube',
'google-plus-g',
'whatsapp',
4114 'chevron-left',
'chevron-right',
'chevron-down',
'chevron-top',
'commercial',
'companies',
4115 'generic',
'home',
'hrm',
'members',
'products',
'invoicing',
4116 'partnership',
'payment',
'payment_vat',
'pencil-ruler',
'pictoconfirm',
'preview',
'project',
'projectpub',
'projecttask',
'question',
'refresh',
'region',
4117 'salary',
'shipment',
'state',
'supplier_invoice',
'supplier_invoicea',
'supplier_invoicer',
'supplier_invoiced',
4118 'technic',
'ticket',
4120 'recent',
'reception',
'recruitmentcandidature',
'recruitmentjobposition',
'replacement',
'resource',
'recurring',
'rss',
4121 'shapes',
'skill',
'square',
'stop-circle',
'supplier',
'supplier_proposal',
'supplier_order',
'supplier_invoice',
4122 'timespent',
'title_setup',
'title_accountancy',
'title_bank',
'title_hrm',
'title_agenda',
4123 'uncheck',
'url',
'user-cog',
'user-injured',
'user-md',
'vat',
'website',
'workstation',
'webhook',
'world',
'private',
4124 'conferenceorbooth',
'eventorganization',
4125 'stamp',
'signature'
4127 $fakey = $pictowithouttext;
4131 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'))) {
4134 if (in_array($pictowithouttext, array(
'black-tie',
'github',
'google',
'microsoft',
'skype',
'twitter',
'facebook',
'linkedin',
'instagram',
'snapchat',
'stripe',
'stripe-s',
'youtube',
'google-plus-g',
'whatsapp'))) {
4138 $arrayconvpictotofa = array(
4139 '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',
4140 'bank_account'=>
'university',
4141 'bill'=>
'file-invoice-dollar',
'billa'=>
'file-excel',
'billr'=>
'file-invoice-dollar',
'billd'=>
'file-medical',
4142 'supplier_invoice'=>
'file-invoice-dollar',
'supplier_invoicea'=>
'file-excel',
'supplier_invoicer'=>
'file-invoice-dollar',
'supplier_invoiced'=>
'file-medical',
4144 'card'=>
'address-card',
'chart'=>
'chart-line',
'company'=>
'building',
'contact'=>
'address-book',
'contract'=>
'suitcase',
'collab'=>
'people-arrows',
'conversation'=>
'comments',
'country'=>
'globe-americas',
'cron'=>
'business-time',
4145 'donation'=>
'file-alt',
'dynamicprice'=>
'hand-holding-usd',
4146 'setup'=>
'cog',
'companies'=>
'building',
'products'=>
'cube',
'commercial'=>
'suitcase',
'invoicing'=>
'coins',
4147 'accounting'=>
'search-dollar',
'category'=>
'tag',
'dollyrevert'=>
'dolly',
4148 'generate'=>
'plus-square',
'hrm'=>
'user-tie',
'incoterm'=>
'truck-loading',
4149 'margin'=>
'calculator',
'members'=>
'user-friends',
'ticket'=>
'ticket-alt',
'globe'=>
'external-link-alt',
'lot'=>
'barcode',
4150 'email'=>
'at',
'establishment'=>
'building',
'edit'=>
'pencil-alt',
'entity'=>
'globe',
4151 'graph'=>
'chart-line',
'grip_title'=>
'arrows-alt',
'grip'=>
'arrows-alt',
'help'=>
'question-circle',
4152 'generic'=>
'file',
'holiday'=>
'umbrella-beach',
4153 'info'=>
'info-circle',
'inventory'=>
'boxes',
'intracommreport'=>
'globe-europe',
'jobprofile'=>
'cogs',
4154 'knowledgemanagement'=>
'ticket-alt',
'label'=>
'layer-group',
'line'=>
'bars',
'loan'=>
'money-bill-alt',
4155 'member'=>
'user-alt',
'meeting'=>
'chalkboard-teacher',
'mrp'=>
'cubes',
'next'=>
'arrow-alt-circle-right',
4156 'trip'=>
'wallet',
'expensereport'=>
'wallet',
'group'=>
'users',
'movement'=>
'people-carry',
4157 'sign-out'=>
'sign-out-alt',
4158 'switch_off'=>
'toggle-off',
'switch_on'=>
'toggle-on',
'switch_on_red'=>
'toggle-on',
'check'=>
'check',
'bookmark'=>
'star',
4159 'bank'=>
'university',
'close_title'=>
'times',
'delete'=>
'trash',
'filter'=>
'filter',
4160 'list-alt'=>
'list-alt',
'calendarlist'=>
'bars',
'calendar'=>
'calendar-alt',
'calendarmonth'=>
'calendar-alt',
'calendarweek'=>
'calendar-week',
'calendarday'=>
'calendar-day',
'calendarperuser'=>
'table',
4161 'intervention'=>
'ambulance',
'invoice'=>
'file-invoice-dollar',
'currency'=>
'dollar-sign',
'multicurrency'=>
'dollar-sign',
'order'=>
'file-invoice',
4162 'error'=>
'exclamation-triangle',
'warning'=>
'exclamation-triangle',
4164 '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',
4165 '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',
4166 'recent' =>
'check-square',
'reception'=>
'dolly',
'recruitmentjobposition'=>
'id-card-alt',
'recruitmentcandidature'=>
'id-badge',
4167 'resize'=>
'crop',
'supplier_order'=>
'dol-order_supplier',
'supplier_proposal'=>
'file-signature',
4168 'refresh'=>
'redo',
'region'=>
'map-marked',
'replacement'=>
'exchange-alt',
'resource'=>
'laptop-house',
'recurring'=>
'history',
4169 'service'=>
'concierge-bell',
4170 'skill'=>
'shapes',
'state'=>
'map-marked-alt',
'security'=>
'key',
'salary'=>
'wallet',
'shipment'=>
'dolly',
'stock'=>
'box-open',
'stats' =>
'chart-bar',
'split'=>
'code-branch',
'stripe'=>
'stripe-s',
4171 'supplier'=>
'building',
'technic'=>
'cogs',
4172 'timespent'=>
'clock',
'title_setup'=>
'tools',
'title_accountancy'=>
'money-check-alt',
'title_bank'=>
'university',
'title_hrm'=>
'umbrella-beach',
4173 'title_agenda'=>
'calendar-alt',
4174 'uncheck'=>
'times',
'uparrow'=>
'share',
'url'=>
'external-link-alt',
'vat'=>
'money-check-alt',
'vcard'=>
'address-card',
4175 'jabber'=>
'comment-o',
4176 'website'=>
'globe-americas',
'workstation'=>
'pallet',
'webhook'=>
'bullseye',
'world'=>
'globe',
'private'=>
'user-lock',
4177 'conferenceorbooth'=>
'chalkboard-teacher',
'eventorganization'=>
'project-diagram'
4179 if ($pictowithouttext ==
'off') {
4180 $fakey =
'fa-square';
4182 } elseif ($pictowithouttext ==
'on') {
4183 $fakey =
'fa-check-square';
4185 } elseif ($pictowithouttext ==
'listlight') {
4186 $fakey =
'fa-download';
4187 $marginleftonlyshort = 1;
4188 } elseif ($pictowithouttext ==
'printer') {
4189 $fakey =
'fa-print';
4191 } elseif ($pictowithouttext ==
'note') {
4192 $fakey =
'fa-sticky-note';
4193 $marginleftonlyshort = 1;
4194 } elseif (in_array($pictowithouttext, array(
'1uparrow',
'1downarrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected'))) {
4195 $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');
4196 $fakey =
'fa-'.$convertarray[$pictowithouttext];
4197 if (preg_match(
'/selected/', $pictowithouttext)) {
4200 $marginleftonlyshort = 1;
4201 } elseif (!empty($arrayconvpictotofa[$pictowithouttext])) {
4202 $fakey =
'fa-'.$arrayconvpictotofa[$pictowithouttext];
4204 $fakey =
'fa-'.$pictowithouttext;
4207 if (in_array($pictowithouttext, array(
'dollyrevert',
'member',
'members',
'contract',
'group',
'resource',
'shipment'))) {
4208 $morecss .=
' em092';
4210 if (in_array($pictowithouttext, array(
'conferenceorbooth',
'collab',
'eventorganization',
'holiday',
'info',
'project',
'workstation'))) {
4211 $morecss .=
' em088';
4213 if (in_array($pictowithouttext, array(
'asset',
'intervention',
'payment',
'loan',
'partnership',
'stock',
'technic'))) {
4214 $morecss .=
' em080';
4218 $arrayconvpictotomarginleftonly = array(
4219 'bank',
'check',
'delete',
'generic',
'grip',
'grip_title',
'jabber',
4220 'grip_title',
'grip',
'listlight',
'note',
'on',
'off',
'playdisabled',
'printer',
'resize',
'sign-out',
'stats',
'switch_on',
'switch_on_red',
'switch_off',
4221 'uparrow',
'1uparrow',
'1downarrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected'
4223 if (!isset($arrayconvpictotomarginleftonly[$pictowithouttext])) {
4224 $marginleftonlyshort = 0;
4228 $arrayconvpictotomorcess = array(
4229 'action'=>
'infobox-action',
'account'=>
'infobox-bank_account',
'accounting_account'=>
'infobox-bank_account',
'accountline'=>
'infobox-bank_account',
'accountancy'=>
'infobox-bank_account',
'asset'=>
'infobox-bank_account',
4230 'bank_account'=>
'infobox-bank_account',
4231 'bill'=>
'infobox-commande',
'billa'=>
'infobox-commande',
'billr'=>
'infobox-commande',
'billd'=>
'infobox-commande',
4232 'margin'=>
'infobox-bank_account',
'conferenceorbooth'=>
'infobox-project',
4233 'cash-register'=>
'infobox-bank_account',
'contract'=>
'infobox-contrat',
'check'=>
'font-status4',
'collab'=>
'infobox-action',
'conversation'=>
'infobox-contrat',
4234 'donation'=>
'infobox-commande',
'dolly'=>
'infobox-commande',
'dollyrevert'=>
'flip infobox-order_supplier',
4235 'ecm'=>
'infobox-action',
'eventorganization'=>
'infobox-project',
4236 'hrm'=>
'infobox-adherent',
'group'=>
'infobox-adherent',
'intervention'=>
'infobox-contrat',
4237 'incoterm'=>
'infobox-supplier_proposal',
4238 'currency'=>
'infobox-bank_account',
'multicurrency'=>
'infobox-bank_account',
4239 'members'=>
'infobox-adherent',
'member'=>
'infobox-adherent',
'money-bill-alt'=>
'infobox-bank_account',
4240 'order'=>
'infobox-commande',
4241 'user'=>
'infobox-adherent',
'users'=>
'infobox-adherent',
4242 'error'=>
'pictoerror',
'warning'=>
'pictowarning',
'switch_on'=>
'font-status4',
'switch_on_red'=>
'font-status8',
4243 'holiday'=>
'infobox-holiday',
'info'=>
'opacityhigh',
'invoice'=>
'infobox-commande',
4244 'knowledgemanagement'=>
'infobox-contrat rotate90',
'loan'=>
'infobox-bank_account',
4245 'payment'=>
'infobox-bank_account',
'payment_vat'=>
'infobox-bank_account',
'poll'=>
'infobox-adherent',
'pos'=>
'infobox-bank_account',
'project'=>
'infobox-project',
'projecttask'=>
'infobox-project',
4246 'propal'=>
'infobox-propal',
'proposal'=>
'infobox-propal',
'private'=>
'infobox-project',
4247 'reception'=>
'flip',
'recruitmentjobposition'=>
'infobox-adherent',
'recruitmentcandidature'=>
'infobox-adherent',
4248 'resource'=>
'infobox-action',
4249 'salary'=>
'infobox-bank_account',
'shipment'=>
'infobox-commande',
'supplier_invoice'=>
'infobox-order_supplier',
'supplier_invoicea'=>
'infobox-order_supplier',
'supplier_invoiced'=>
'infobox-order_supplier',
4250 'supplier'=>
'infobox-order_supplier',
'supplier_order'=>
'infobox-order_supplier',
'supplier_proposal'=>
'infobox-supplier_proposal',
4251 'ticket'=>
'infobox-contrat',
'title_accountancy'=>
'infobox-bank_account',
'title_hrm'=>
'infobox-holiday',
'expensereport'=>
'infobox-expensereport',
'trip'=>
'infobox-expensereport',
'title_agenda'=>
'infobox-action',
4252 'vat'=>
'infobox-bank_account',
4254 'list-alt'=>
'imgforviewmode',
'calendar'=>
'imgforviewmode',
'calendarweek'=>
'imgforviewmode',
'calendarmonth'=>
'imgforviewmode',
'calendarday'=>
'imgforviewmode',
'calendarperuser'=>
'imgforviewmode'
4256 if (!empty($arrayconvpictotomorcess[$pictowithouttext])) {
4257 $morecss .= ($morecss ?
' ' :
'').$arrayconvpictotomorcess[$pictowithouttext];
4261 $arrayconvpictotocolor = array(
4262 'address'=>
'#6c6aa8',
'building'=>
'#6c6aa8',
'bom'=>
'#a69944',
4263 'cog'=>
'#999',
'companies'=>
'#6c6aa8',
'company'=>
'#6c6aa8',
'contact'=>
'#6c6aa8',
'cron'=>
'#555',
4264 'dynamicprice'=>
'#a69944',
4265 'edit'=>
'#444',
'note'=>
'#999',
'error'=>
'',
'help'=>
'#bbb',
'listlight'=>
'#999',
'language'=>
'#555',
4267 'lock'=>
'#ddd',
'lot'=>
'#a69944',
4268 'map-marker-alt'=>
'#aaa',
'mrp'=>
'#a69944',
'product'=>
'#a69944',
'service'=>
'#a69944',
'inventory'=>
'#a69944',
'stock'=>
'#a69944',
'movement'=>
'#a69944',
4269 'other'=>
'#ddd',
'world'=>
'#986c6a',
4270 'partnership'=>
'#6c6aa8',
'playdisabled'=>
'#ccc',
'printer'=>
'#444',
'projectpub'=>
'#986c6a',
'reception'=>
'#a69944',
'resize'=>
'#444',
'rss'=>
'#cba',
4272 'security'=>
'#999',
'square'=>
'#888',
'stop-circle'=>
'#888',
'stats'=>
'#444',
'switch_off'=>
'#999',
'technic'=>
'#999',
'timespent'=>
'#555',
4273 'uncheck'=>
'#800',
'uparrow'=>
'#555',
'user-cog'=>
'#999',
'country'=>
'#aaa',
'globe-americas'=>
'#aaa',
'region'=>
'#aaa',
'state'=>
'#aaa',
4274 'website'=>
'#304',
'workstation'=>
'#a69944'
4276 if (isset($arrayconvpictotocolor[$pictowithouttext])) {
4277 $facolor = $arrayconvpictotocolor[$pictowithouttext];
4284 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
4285 $morecss .= ($morecss ?
' ' :
'').$reg[1];
4286 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
4288 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
4289 $morestyle = $reg[1];
4290 $moreatt = str_replace(
'style="'.$reg[1].
'"',
'', $moreatt);
4292 $moreatt = trim($moreatt);
4294 $enabledisablehtml =
'<span class="'.$fa.
' '.$fakey.($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
4295 $enabledisablehtml .= ($morecss ?
' '.$morecss :
'').
'" style="'.($fasize ? (
'font-size: '.$fasize.
';') :
'').($facolor ? (
' color: '.$facolor.
';') :
'').($morestyle ?
' '.$morestyle :
'').
'"'.(($notitle || empty($titlealt)) ?
'' :
' title="'.
dol_escape_htmltag($titlealt).
'"').($moreatt ?
' '.$moreatt :
'').
'>';
4299 $enabledisablehtml .=
'</span>';
4301 return $enabledisablehtml;
4304 if (!empty($conf->global->MAIN_OVERWRITE_THEME_PATH)) {
4305 $path = $conf->global->MAIN_OVERWRITE_THEME_PATH.
'/theme/'.$theme;
4306 } elseif (!empty($conf->global->MAIN_OVERWRITE_THEME_RES)) {
4307 $path = $conf->global->MAIN_OVERWRITE_THEME_RES.
'/theme/'.$conf->global->MAIN_OVERWRITE_THEME_RES;
4308 } elseif (!empty($conf->modules_parts[
'theme']) && array_key_exists($theme, $conf->modules_parts[
'theme'])) {
4309 $path = $theme.
'/theme/'.$theme;
4314 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $picto, $regs)) {
4320 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
4325 foreach ($conf->file->dol_document_root as $type => $dirroot) {
4326 if ($type ==
'main') {
4330 if (file_exists($dirroot.
'/'.$path.
'/img/'.$picto)) {
4331 $url = DOL_URL_ROOT.$conf->file->dol_url_root[$type];
4337 $fullpathpicto = $url.
'/'.$path.
'/img/'.$picto;
4341 return $fullpathpicto;
4344 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 :
'').
'"').
'>';
4360 function img_object($titlealt, $picto, $moreatt =
'', $pictoisfullpath =
false, $srconly = 0, $notitle = 0)
4362 if (strpos($picto,
'^') === 0) {
4363 return img_picto($titlealt, str_replace(
'^',
'', $picto), $moreatt, $pictoisfullpath, $srconly, $notitle);
4365 return img_picto($titlealt,
'object_'.$picto, $moreatt, $pictoisfullpath, $srconly, $notitle);
4380 function img_weather($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $morecss =
'')
4384 if (is_numeric($picto)) {
4387 return '<i class="fa fa-weather-level'.$picto.
'"></i>';
4388 } elseif (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
4392 $path = DOL_URL_ROOT.
'/theme/'.$conf->theme.
'/img/weather/'.$picto;
4394 return img_picto($titlealt, $path, $moreatt, 1, 0, 0,
'', $morecss);
4408 function img_picto_common($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $notitle = 0)
4412 if (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
4416 if ($pictoisfullpath) {
4419 $path = DOL_URL_ROOT.
'/theme/common/'.$picto;
4421 if (!empty($conf->global->MAIN_MODULE_CAN_OVERWRITE_COMMONICONS)) {
4422 $themepath = DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/img/'.$picto;
4424 if (file_exists($themepath)) {
4430 return img_picto($titlealt, $path, $moreatt, 1, 0, $notitle);
4449 if (empty($titlealt) || $titlealt ==
'default') {
4450 if ($numaction ==
'-1' || $numaction ==
'ST_NO') {
4452 $titlealt = $langs->transnoentitiesnoconv(
'ChangeDoNotContact');
4453 } elseif ($numaction ==
'0' || $numaction ==
'ST_NEVER') {
4455 $titlealt = $langs->transnoentitiesnoconv(
'ChangeNeverContacted');
4456 } elseif ($numaction ==
'1' || $numaction ==
'ST_TODO') {
4458 $titlealt = $langs->transnoentitiesnoconv(
'ChangeToContact');
4459 } elseif ($numaction ==
'2' || $numaction ==
'ST_PEND') {
4461 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactInProcess');
4462 } elseif ($numaction ==
'3' || $numaction ==
'ST_DONE') {
4464 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactDone');
4466 $titlealt = $langs->transnoentitiesnoconv(
'ChangeStatus '.$numaction);
4470 if (!is_numeric($numaction)) {
4474 return img_picto($titlealt, !empty($picto) ? $picto :
'stcomm'.$numaction.
'.png');
4484 function img_pdf($titlealt =
'default', $size = 3)
4488 if ($titlealt ==
'default') {
4489 $titlealt = $langs->trans(
'Show');
4492 return img_picto($titlealt,
'pdf'.$size.
'.png');
4506 if ($titlealt ==
'default') {
4507 $titlealt = $langs->trans(
'Add');
4510 return img_picto($titlealt,
'edit_add.png', $other);
4523 if ($titlealt ==
'default') {
4524 $titlealt = $langs->trans(
'Remove');
4527 return img_picto($titlealt,
'edit_remove.png', $other);
4538 function img_edit($titlealt =
'default', $float = 0, $other =
'')
4542 if ($titlealt ==
'default') {
4543 $titlealt = $langs->trans(
'Modify');
4546 return img_picto($titlealt,
'edit.png', ($float ?
'style="float: '.($langs->tab_translate[
"DIRECTION"] ==
'rtl' ?
'left' :
'right').
'"' :
"").($other ?
' '.$other :
''));
4557 function img_view($titlealt =
'default', $float = 0, $other =
'class="valignmiddle"')
4561 if ($titlealt ==
'default') {
4562 $titlealt = $langs->trans(
'View');
4565 $moreatt = ($float ?
'style="float: right" ' :
'').$other;
4567 return img_picto($titlealt,
'eye', $moreatt);
4578 function img_delete($titlealt =
'default', $other =
'class="pictodelete"', $morecss =
'')
4582 if ($titlealt ==
'default') {
4583 $titlealt = $langs->trans(
'Delete');
4586 return img_picto($titlealt,
'delete.png', $other,
false, 0, 0,
'', $morecss);
4599 if ($titlealt ==
"default") {
4600 $titlealt = $langs->trans(
"Print");
4602 return img_picto($titlealt,
'printer.png', $other);
4612 function img_split($titlealt =
'default', $other =
'class="pictosplit"')
4616 if ($titlealt ==
'default') {
4617 $titlealt = $langs->trans(
'Split');
4620 return img_picto($titlealt,
'split.png', $other);
4630 function img_help($usehelpcursor = 1, $usealttitle = 1)
4635 if (is_string($usealttitle)) {
4638 $usealttitle = $langs->trans(
'Info');
4642 return img_picto($usealttitle,
'info.png',
'style="vertical-align: middle;'.($usehelpcursor == 1 ?
' cursor: help' : ($usehelpcursor == 2 ?
' cursor: pointer' :
'')).
'"');
4655 if ($titlealt ==
'default') {
4656 $titlealt = $langs->trans(
'Informations');
4659 return img_picto($titlealt,
'info.png',
'style="vertical-align: middle;"');
4670 function img_warning($titlealt =
'default', $moreatt =
'', $morecss =
'pictowarning')
4674 if ($titlealt ==
'default') {
4675 $titlealt = $langs->trans(
'Warning');
4679 return img_picto($titlealt,
'warning.png',
'class="'.$morecss.
'"'.($moreatt ? ($moreatt ==
'1' ?
' style="float: right"' :
' '.$moreatt) :
''));
4692 if ($titlealt ==
'default') {
4693 $titlealt = $langs->trans(
'Error');
4696 return img_picto($titlealt,
'error.png');
4706 function img_next($titlealt =
'default', $moreatt =
'')
4710 if ($titlealt ==
'default') {
4711 $titlealt = $langs->trans(
'Next');
4715 return '<span class="fa fa-chevron-right paddingright paddingleft" title="'.dol_escape_htmltag($titlealt).
'"></span>';
4729 if ($titlealt ==
'default') {
4730 $titlealt = $langs->trans(
'Previous');
4734 return '<span class="fa fa-chevron-left paddingright paddingleft" title="'.dol_escape_htmltag($titlealt).
'"></span>';
4745 function img_down($titlealt =
'default', $selected = 0, $moreclass =
'')
4749 if ($titlealt ==
'default') {
4750 $titlealt = $langs->trans(
'Down');
4753 return img_picto($titlealt, ($selected ?
'1downarrow_selected.png' :
'1downarrow.png'),
'class="imgdown'.($moreclass ?
" ".$moreclass :
"").
'"');
4764 function img_up($titlealt =
'default', $selected = 0, $moreclass =
'')
4768 if ($titlealt ==
'default') {
4769 $titlealt = $langs->trans(
'Up');
4772 return img_picto($titlealt, ($selected ?
'1uparrow_selected.png' :
'1uparrow.png'),
'class="imgup'.($moreclass ?
" ".$moreclass :
"").
'"');
4783 function img_left($titlealt =
'default', $selected = 0, $moreatt =
'')
4787 if ($titlealt ==
'default') {
4788 $titlealt = $langs->trans(
'Left');
4791 return img_picto($titlealt, ($selected ?
'1leftarrow_selected.png' :
'1leftarrow.png'), $moreatt);
4802 function img_right($titlealt =
'default', $selected = 0, $moreatt =
'')
4806 if ($titlealt ==
'default') {
4807 $titlealt = $langs->trans(
'Right');
4810 return img_picto($titlealt, ($selected ?
'1rightarrow_selected.png' :
'1rightarrow.png'), $moreatt);
4824 if ($titlealt ==
'default') {
4825 $titlealt = $langs->trans(
'Active');
4829 return img_picto($titlealt,
'tick.png');
4844 if (is_null($morecss)) {
4848 if ($brand ==
'visa' || $brand ==
'Visa') {
4850 } elseif ($brand ==
'mastercard' || $brand ==
'MasterCard') {
4851 $brand =
'cc-mastercard';
4852 } elseif ($brand ==
'amex' || $brand ==
'American Express') {
4854 } elseif ($brand ==
'discover' || $brand ==
'Discover') {
4855 $brand =
'cc-discover';
4856 } elseif ($brand ==
'jcb' || $brand ==
'JCB') {
4858 } elseif ($brand ==
'diners' || $brand ==
'Diners club') {
4859 $brand =
'cc-diners-club';
4860 } elseif (!in_array($brand, array(
'cc-visa',
'cc-mastercard',
'cc-amex',
'cc-discover',
'cc-jcb',
'cc-diners-club'))) {
4861 $brand =
'credit-card';
4864 return '<span class="fa fa-'.$brand.
' fa-fw'.($morecss ?
' '.$morecss :
'').
'"></span>';
4875 function img_mime($file, $titlealt =
'', $morecss =
'')
4877 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
4883 if (empty($titlealt)) {
4884 $titlealt =
'Mime type: '.$mimetype;
4888 return '<i class="fa fa-'.$mimefa.
' paddingright'.($morecss ?
' '.$morecss :
'').
'"'.($titlealt ?
' title="'.$titlealt.
'"' :
'').
'></i>';
4901 global $conf, $langs;
4903 if ($titlealt ==
'default') {
4904 $titlealt = $langs->trans(
'Search');
4907 $img =
img_picto($titlealt,
'search.png', $other,
false, 1);
4909 $input =
'<input type="image" class="liste_titre" name="button_search" src="'.$img.
'" ';
4910 $input .=
'value="'.dol_escape_htmltag($titlealt).
'" title="'.
dol_escape_htmltag($titlealt).
'" >';
4924 global $conf, $langs;
4926 if ($titlealt ==
'default') {
4927 $titlealt = $langs->trans(
'Search');
4930 $img =
img_picto($titlealt,
'searchclear.png', $other,
false, 1);
4932 $input =
'<input type="image" class="liste_titre" name="button_removefilter" src="'.$img.
'" ';
4933 $input .=
'value="'.dol_escape_htmltag($titlealt).
'" title="'.
dol_escape_htmltag($titlealt).
'" >';
4949 function info_admin($text, $infoonimgalt = 0, $nodiv = 0, $admin =
'1', $morecss =
'hideonsmartphone', $textfordropdown =
'')
4951 global $conf, $langs;
4953 if ($infoonimgalt) {
4954 $result =
img_picto($text,
'info',
'class="'.($morecss ?
' '.$morecss :
'').
'"');
4956 if (empty($conf->use_javascript_ajax)) {
4957 $textfordropdown =
'';
4960 $class = (empty($admin) ?
'undefined' : ($admin ==
'1' ?
'info' : $admin));
4961 $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>');
4963 if ($textfordropdown) {
4964 $tmpresult =
'<span class="'.$class.
'text opacitymedium cursorpointer">'.$langs->trans($textfordropdown).
' '.
img_picto($langs->trans($textfordropdown),
'1downarrow').
'</span>';
4965 $tmpresult .=
'<script type="text/javascript">
4966 jQuery(document).ready(function() {
4967 jQuery(".'.$class.
'text").click(function() {
4968 console.log("toggle text");
4969 jQuery(".'.$class.
'").toggle();
4974 $result = $tmpresult.$result;
4995 global $conf, $langs, $argv;
4996 global $dolibarr_main_prod;
5003 require_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
5005 $langs->load(
"main");
5009 $langs->loadLangs(array(
'main',
'errors'));
5011 if ($_SERVER[
'DOCUMENT_ROOT']) {
5012 $out .= $langs->trans(
"DolibarrHasDetectedError").
".<br>\n";
5014 $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";
5016 $out .= $langs->trans(
"InformationToHelpDiagnose").
":<br>\n";
5018 $out .=
"<b>".$langs->trans(
"Date").
":</b> ".
dol_print_date(time(),
'dayhourlog').
"<br>\n";
5019 $out .=
"<b>".$langs->trans(
"Dolibarr").
":</b> ".DOL_VERSION.
" - https://www.dolibarr.org<br>\n";
5020 if (isset($conf->global->MAIN_FEATURES_LEVEL)) {
5021 $out .=
"<b>".$langs->trans(
"LevelOfFeature").
":</b> ".
getDolGlobalInt(
'MAIN_FEATURES_LEVEL').
"<br>\n";
5023 if (function_exists(
"phpversion")) {
5024 $out .=
"<b>".$langs->trans(
"PHP").
":</b> ".phpversion().
"<br>\n";
5026 $out .=
"<b>".$langs->trans(
"Server").
":</b> ".(isset($_SERVER[
"SERVER_SOFTWARE"]) ?
dol_htmlentities($_SERVER[
"SERVER_SOFTWARE"], ENT_COMPAT) :
'').
"<br>\n";
5027 if (function_exists(
"php_uname")) {
5028 $out .=
"<b>".$langs->trans(
"OS").
":</b> ".php_uname().
"<br>\n";
5030 $out .=
"<b>".$langs->trans(
"UserAgent").
":</b> ".(isset($_SERVER[
"HTTP_USER_AGENT"]) ?
dol_htmlentities($_SERVER[
"HTTP_USER_AGENT"], ENT_COMPAT) :
'').
"<br>\n";
5032 $out .=
"<b>".$langs->trans(
"RequestedUrl").
":</b> ".
dol_htmlentities($_SERVER[
"REQUEST_URI"], ENT_COMPAT).
"<br>\n";
5033 $out .=
"<b>".$langs->trans(
"Referer").
":</b> ".(isset($_SERVER[
"HTTP_REFERER"]) ?
dol_htmlentities($_SERVER[
"HTTP_REFERER"], ENT_COMPAT) :
'').
"<br>\n";
5034 $out .=
"<b>".$langs->trans(
"MenuManager").
":</b> ".(isset($conf->standard_menu) ?
dol_htmlentities($conf->standard_menu, ENT_COMPAT) :
'').
"<br>\n";
5036 $syslog .=
"url=".dol_escape_htmltag($_SERVER[
"REQUEST_URI"]);
5037 $syslog .=
", query_string=".dol_escape_htmltag($_SERVER[
"QUERY_STRING"]);
5040 $out .=
'> '.$langs->transnoentities(
"ErrorInternalErrorDetected").
":\n".$argv[0].
"\n";
5041 $syslog .=
"pid=".dol_getmypid();
5044 if (!empty($conf->modules)) {
5045 $out .=
"<b>".$langs->trans(
"Modules").
":</b> ".join(
', ', $conf->modules).
"<br>\n";
5048 if (is_object($db)) {
5049 if ($_SERVER[
'DOCUMENT_ROOT']) {
5050 $out .=
"<b>".$langs->trans(
"DatabaseTypeManager").
":</b> ".$db->type.
"<br>\n";
5051 $out .=
"<b>".$langs->trans(
"RequestLastAccessInError").
":</b> ".($db->lastqueryerror() ?
dol_escape_htmltag($db->lastqueryerror()) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
5052 $out .=
"<b>".$langs->trans(
"ReturnCodeLastAccessInError").
":</b> ".($db->lasterrno() ?
dol_escape_htmltag($db->lasterrno()) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
5053 $out .=
"<b>".$langs->trans(
"InformationLastAccessInError").
":</b> ".($db->lasterror() ?
dol_escape_htmltag($db->lasterror()) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
5058 $out .=
'> '.$langs->transnoentities(
"DatabaseTypeManager").
":\n".$db->type.
"\n";
5059 $out .=
'> '.$langs->transnoentities(
"RequestLastAccessInError").
":\n".($db->lastqueryerror() ? $db->lastqueryerror() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
5060 $out .=
'> '.$langs->transnoentities(
"ReturnCodeLastAccessInError").
":\n".($db->lasterrno() ? $db->lasterrno() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
5061 $out .=
'> '.$langs->transnoentities(
"InformationLastAccessInError").
":\n".($db->lasterror() ? $db->lasterror() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
5063 $syslog .=
", sql=".$db->lastquery();
5064 $syslog .=
", db_error=".$db->lasterror();
5067 if ($error || $errors) {
5068 $langs->load(
"errors");
5071 if (is_array($error) && is_array($errors)) {
5072 $errors = array_merge($error, $errors);
5073 } elseif (is_array($error)) {
5075 } elseif (is_array($errors)) {
5076 $errors = array_merge(array($error), $errors);
5078 $errors = array_merge(array($error), array($errors));
5081 foreach ($errors as $msg) {
5085 if ($_SERVER[
'DOCUMENT_ROOT']) {
5089 $out .=
'> '.$langs->transnoentities(
"Message").
":\n".$msg.
"\n";
5091 $syslog .=
", msg=".$msg;
5094 if (empty($dolibarr_main_prod) && $_SERVER[
'DOCUMENT_ROOT'] && function_exists(
'xdebug_print_function_stack') && function_exists(
'xdebug_call_file')) {
5095 xdebug_print_function_stack();
5096 $out .=
'<b>XDebug informations:</b>'.
"<br>\n";
5097 $out .=
'File: '.xdebug_call_file().
"<br>\n";
5098 $out .=
'Line: '.xdebug_call_line().
"<br>\n";
5099 $out .=
'Function: '.xdebug_call_function().
"<br>\n";
5104 if (!headers_sent()) {
5105 if (function_exists(
'top_httphead')) {
5108 http_response_code(500);
5111 if (empty($dolibarr_main_prod)) {
5114 if (empty($langs->defaultlang)) {
5115 $langs->setDefaultLang();
5117 $langs->loadLangs(array(
"main",
"errors"));
5119 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";
5120 print $langs->trans(
"DolibarrHasDetectedError").
'. ';
5121 print $langs->trans(
"YouCanSetOptionDolibarrMainProdToZero");
5122 define(
"MAIN_CORE_ERROR", 1);
5138 function dol_print_error_email($prefixcode, $errormessage =
'', $errormessages = array(), $morecss =
'error', $email =
'')
5140 global $langs, $conf;
5142 if (empty($email)) {
5143 $email = $conf->global->MAIN_INFO_SOCIETE_MAIL;
5146 $langs->load(
"errors");
5149 print
'<br><div class="center login_main_message"><div class="'.$morecss.
'">';
5150 print $langs->trans(
"ErrorContactEMail", $email, $prefixcode.dol_print_date($now,
'%Y%m%d%H%M%S'));
5151 if ($errormessage) {
5152 print
'<br><br>'.$errormessage;
5154 if (is_array($errormessages) && count($errormessages)) {
5155 foreach ($errormessages as $mesgtoshow) {
5156 print
'<br><br>'.$mesgtoshow;
5159 print
'</div></div>';
5178 function print_liste_field_titre($name, $file =
"", $field =
"", $begin =
"", $moreparam =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $tooltip =
"", $forcenowrapcolumntitle = 0)
5180 print
getTitleFieldOfList($name, 0, $file, $field, $begin, $moreparam, $moreattrib, $sortfield, $sortorder, $prefix, 0, $tooltip, $forcenowrapcolumntitle);
5201 function getTitleFieldOfList($name, $thead = 0, $file =
"", $field =
"", $begin =
"", $moreparam =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $disablesortlink = 0, $tooltip =
'', $forcenowrapcolumntitle = 0)
5203 global $conf, $langs,
$form;
5206 if ($moreattrib ==
'class="right"') {
5207 $prefix .=
'right ';
5210 $sortorder = strtoupper($sortorder);
5219 $tmpsortfield = explode(
',', $sortfield);
5220 $sortfield1 = trim($tmpsortfield[0]);
5221 $tmpfield = explode(
',', $field);
5222 $field1 = trim($tmpfield[0]);
5224 if (empty($conf->global->MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE) && empty($forcenowrapcolumntitle)) {
5225 $prefix =
'wrapcolumntitle '.$prefix;
5231 $liste_titre =
'liste_titre';
5232 if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace(
"/^[^\.]+\./",
"", $field1))) {
5233 $liste_titre =
'liste_titre_sel';
5236 $tagstart =
'<'.$tag.
' class="'.$prefix.$liste_titre.
'" '.$moreattrib;
5238 $tagstart .= ($name && empty($conf->global->MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE) && empty($forcenowrapcolumntitle) && !
dol_textishtml($name)) ?
' title="'.
dol_escape_htmltag($langs->trans($name)).
'"' :
'';
5241 if (empty($thead) && $field && empty($disablesortlink)) {
5242 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
5243 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
5244 $options = preg_replace(
'/&+/i',
'&', $options);
5245 if (!preg_match(
'/^&/', $options)) {
5246 $options =
'&'.$options;
5249 $sortordertouseinlink =
'';
5250 if ($field1 != $sortfield1) {
5251 if (preg_match(
'/^DESC/i', $sortorder)) {
5252 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
5254 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
5257 if (preg_match(
'/^ASC/i', $sortorder)) {
5258 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
5260 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
5263 $sortordertouseinlink = preg_replace(
'/,$/',
'', $sortordertouseinlink);
5264 $out .=
'<a class="reposition" href="'.$file.
'?sortfield='.$field.
'&sortorder='.$sortordertouseinlink.
'&begin='.$begin.$options.
'"';
5270 if (preg_match(
'/:\w+$/', $tooltip)) {
5271 $tmptooltip = explode(
':', $tooltip);
5273 $tmptooltip = array($tooltip);
5275 $out .=
$form->textwithpicto($langs->trans($name), $langs->trans($tmptooltip[0]), 1,
'help',
'', 0, 3, (empty($tmptooltip[1]) ?
'' :
'extra_'.str_replace(
'.',
'_', $field).
'_'.$tmptooltip[1]));
5277 $out .= $langs->trans($name);
5280 if (empty($thead) && $field && empty($disablesortlink)) {
5284 if (empty($thead) && $field) {
5285 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
5286 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
5287 $options = preg_replace(
'/&+/i',
'&', $options);
5288 if (!preg_match(
'/^&/', $options)) {
5289 $options =
'&'.$options;
5292 if (!$sortorder || $field1 != $sortfield1) {
5296 if (preg_match(
'/^DESC/', $sortorder)) {
5299 $sortimg .=
'<span class="nowrap">'.img_up(
"Z-A", 0,
'paddingright').
'</span>';
5301 if (preg_match(
'/^ASC/', $sortorder)) {
5304 $sortimg .=
'<span class="nowrap">'.img_down(
"A-Z", 0,
'paddingright').
'</span>';
5309 $tagend =
'</'.$tag.
'>';
5311 $out = $tagstart.$sortimg.$out.$tagend;
5326 dol_syslog(__FUNCTION__.
" is deprecated", LOG_WARNING);
5328 print
'<div class="titre">'.$title.
'</div>';
5360 function load_fiche_titre($titre, $morehtmlright =
'', $picto =
'generic', $pictoisfullpath = 0, $id =
'', $morecssontable =
'', $morehtmlcenter =
'')
5366 if ($picto ==
'setup') {
5371 $return .=
'<table '.($id ?
'id="'.$id.
'" ' :
'').
'class="centpercent notopnoleftnoright table-fiche-title'.($morecssontable ?
' '.$morecssontable :
'').
'">';
5372 $return .=
'<tr class="titre">';
5374 $return .=
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">'.img_picto(
'', $picto,
'class="valignmiddle widthpictotitle pictotitle"', $pictoisfullpath).
'</td>';
5376 $return .=
'<td class="nobordernopadding valignmiddle col-title">';
5377 $return .=
'<div class="titre inline-block">'.$titre.
'</div>';
5380 $return .=
'<td class="nobordernopadding center valignmiddle col-center">'.$morehtmlcenter.
'</td>';
5383 $return .=
'<td class="nobordernopadding titre_right wordbreakimp right valignmiddle col-right">'.$morehtmlright.
'</td>';
5385 $return .=
'</tr></table>'.
"\n";
5413 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 =
'')
5415 global $conf, $langs;
5418 $savtotalnboflines = $totalnboflines;
5419 $totalnboflines = abs((
int) $totalnboflines);
5421 if ($picto ==
'setup') {
5422 $picto =
'title_setup.png';
5424 if (($conf->browser->name ==
'ie') && $picto ==
'generic') {
5425 $picto =
'title.gif';
5428 $limit = $conf->liste_limit;
5430 if ($savlimit != 0 && (($num > $limit) || ($num == -1) || ($limit == 0))) {
5438 print
"<!-- Begin title -->\n";
5439 print
'<table class="centpercent notopnoleftnoright table-fiche-title'.($morecss ?
' '.$morecss :
'').
'"><tr>';
5443 if ($picto && $titre) {
5444 print
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">'.img_picto(
'', $picto,
'class="valignmiddle pictotitle widthpictotitle"', $pictoisfullpath).
'</td>';
5446 print
'<td class="nobordernopadding valignmiddle col-title">';
5447 print
'<div class="titre inline-block">'.$titre;
5448 if (!empty($titre) && $savtotalnboflines >= 0 && (string) $savtotalnboflines !=
'') {
5449 print
'<span class="opacitymedium colorblack paddingleft">('.$totalnboflines.
')</span>';
5451 print
'</div></td>';
5454 if ($morehtmlcenter) {
5455 print
'<td class="nobordernopadding center valignmiddle col-center">'.$morehtmlcenter.
'</td>';
5459 print
'<td class="nobordernopadding valignmiddle right col-right">';
5460 print
'<input type="hidden" name="pageplusoneold" value="'.((int) $page + 1).
'">';
5462 $options .=
"&sortfield=".urlencode($sortfield);
5465 $options .=
"&sortorder=".urlencode($sortorder);
5469 if ($savlimit != 0 && ($page > 0 || $num > $limit)) {
5470 if ($totalnboflines) {
5472 $maxnbofpage = (empty($conf->dol_optimize_smallscreen) ? 4 : 0);
5475 $nbpages = ceil($totalnboflines / $limit);
5479 $cpt = ($page - $maxnbofpage);
5485 if (empty($pagenavastextinput)) {
5486 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page=0'.$options.
'">1</a></li>';
5488 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
5489 } elseif ($cpt == 2) {
5490 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page=1'.$options.
'">2</a></li>';
5496 if ($pagenavastextinput) {
5497 if ($cpt == $page) {
5498 $pagelist .=
'<li class="pagination"><input type="text" class="width25 center pageplusone" name="pageplusone" value="'.($page + 1).
'"></li>';
5502 if ($cpt == $page) {
5503 $pagelist .=
'<li class="pagination"><span class="active">'.($page + 1).
'</span></li>';
5505 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page='.$cpt.$options.
'">'.($cpt + 1).
'</a></li>';
5509 }
while ($cpt < $nbpages && $cpt <= ($page + $maxnbofpage));
5511 if (empty($pagenavastextinput)) {
5512 if ($cpt < $nbpages) {
5513 if ($cpt < $nbpages - 2) {
5514 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
5515 } elseif ($cpt == $nbpages - 2) {
5516 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page='.($nbpages - 2).$options.
'">'.($nbpages - 1).
'</a></li>';
5518 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page='.($nbpages - 1).$options.
'">'.$nbpages.
'</a></li>';
5522 $pagelist .=
'<li class="pagination paginationlastpage"><a href="'.$file.
'?page='.($nbpages - 1).$options.
'">'.$nbpages.
'</a></li>';
5525 $pagelist .=
'<li class="pagination"><span class="active">'.($page + 1).
"</li>";
5529 if ($savlimit || $morehtmlright || $morehtmlrightbeforearrow) {
5530 print_fleche_navigation($page, $file, $options, $nextpage, $pagelist, $morehtmlright, $savlimit, $totalnboflines, $hideselectlimit, $morehtmlrightbeforearrow);
5534 if ($pagenavastextinput) {
5540 print
'</tr></table>'.
"\n";
5541 print
"<!-- End title -->\n\n";
5559 function print_fleche_navigation($page, $file, $options =
'', $nextpage = 0, $betweenarrows =
'', $afterarrows =
'', $limit = -1, $totalnboflines = 0, $hideselectlimit = 0, $beforearrows =
'')
5561 global $conf, $langs;
5563 print
'<div class="pagination"><ul>';
5564 if ($beforearrows) {
5565 print
'<li class="paginationbeforearrows">';
5566 print $beforearrows;
5569 if ((
int) $limit > 0 && empty($hideselectlimit)) {
5570 $pagesizechoices =
'10:10,15:15,20:20,30:30,40:40,50:50,100:100,250:250,500:500,1000:1000';
5571 $pagesizechoices .=
',5000:5000,10000:10000,20000:20000';
5574 if (!empty($conf->global->MAIN_PAGESIZE_CHOICES)) {
5575 $pagesizechoices = $conf->global->MAIN_PAGESIZE_CHOICES;
5578 print
'<li class="pagination">';
5579 print
'<select class="flat selectlimit" name="limit" title="'.dol_escape_htmltag($langs->trans(
"MaxNbOfRecordPerPage")).
'">';
5580 $tmpchoice = explode(
',', $pagesizechoices);
5581 $tmpkey = $limit.
':'.$limit;
5582 if (!in_array($tmpkey, $tmpchoice)) {
5583 $tmpchoice[] = $tmpkey;
5585 $tmpkey = $conf->liste_limit.
':'.$conf->liste_limit;
5586 if (!in_array($tmpkey, $tmpchoice)) {
5587 $tmpchoice[] = $tmpkey;
5589 asort($tmpchoice, SORT_NUMERIC);
5590 foreach ($tmpchoice as $val) {
5592 $tmp = explode(
':', $val);
5595 if ($key !=
'' && $val !=
'') {
5596 if ((
int) $key == (
int) $limit) {
5597 $selected =
' selected="selected"';
5599 print
'<option name="'.$key.
'"'.$selected.
'>'.
dol_escape_htmltag($val).
'</option>'.
"\n";
5603 if ($conf->use_javascript_ajax) {
5604 print
'<!-- JS CODE TO ENABLE select limit to launch submit of page -->
5606 jQuery(document).ready(function () {
5607 jQuery(".selectlimit").change(function() {
5608 console.log("Change limit. Send submit");
5609 $(this).parents(\'form:first\').submit();
5618 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>';
5620 if ($betweenarrows) {
5621 print
'<!--<div class="betweenarrows nowraponall inline-block">-->';
5622 print $betweenarrows;
5623 print
'<!--</div>-->';
5625 if ($nextpage > 0) {
5626 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>';
5629 print
'<li class="paginationafterarrows">';
5633 print
'</ul></div>'.
"\n";
5648 function vatrate($rate, $addpercent =
false, $info_bits = 0, $usestarfornpr = 0, $html = 0)
5652 if (preg_match(
'/%/', $rate)) {
5653 $rate = str_replace(
'%',
'', $rate);
5657 if (preg_match(
'/\((.*)\)/', $rate, $reg)) {
5658 $morelabel =
' ('.$reg[1].
')';
5659 $rate = preg_replace(
'/\s*'.preg_quote($morelabel,
'/').
'/',
'', $rate);
5660 $morelabel =
' '.($html ?
'<span class="opacitymedium">' :
'').
'('.$reg[1].
')'.($html ?
'</span>' :
'');
5662 if (preg_match(
'/\*/', $rate)) {
5663 $rate = str_replace(
'*',
'', $rate);
5668 if (!preg_match(
'/\//', $rate)) {
5669 $ret =
price($rate, 0,
'', 0, 0).($addpercent ?
'%' :
'');
5672 $ret = $rate.($addpercent ?
'%' :
'');
5674 if (($info_bits & 1) && $usestarfornpr >= 0) {
5697 function price($amount,
$form = 0, $outlangs =
'', $trunc = 1, $rounding = -1, $forcerounding = -1, $currency_code =
'')
5699 global $langs, $conf;
5702 if (empty($amount)) {
5705 $amount = (is_numeric($amount) ? $amount : 0);
5706 if ($rounding < 0) {
5707 $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
5709 $nbdecimal = $rounding;
5711 if ($outlangs ===
'none') {
5721 if (!is_object($outlangs)) {
5725 if ($outlangs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
5726 $dec = $outlangs->transnoentitiesnoconv(
"SeparatorDecimal");
5728 if ($outlangs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
5729 $thousand = $outlangs->transnoentitiesnoconv(
"SeparatorThousand");
5731 if ($thousand ==
'None') {
5733 } elseif ($thousand ==
'Space') {
5740 $amount = str_replace(
',',
'.', $amount);
5742 $datas = explode(
'.', $amount);
5743 $decpart = isset($datas[1]) ? $datas[1] :
'';
5744 $decpart = preg_replace(
'/0+$/i',
'', $decpart);
5753 if ($trunc && $nbdecimal > $conf->global->MAIN_MAX_DECIMALS_SHOWN) {
5754 $nbdecimal = $conf->global->MAIN_MAX_DECIMALS_SHOWN;
5755 if (preg_match(
'/\.\.\./i', $conf->global->MAIN_MAX_DECIMALS_SHOWN)) {
5762 if ((
string) $forcerounding !=
'-1') {
5763 if ($forcerounding ===
'MU') {
5764 $nbdecimal = $conf->global->MAIN_MAX_DECIMALS_UNIT;
5765 } elseif ($forcerounding ===
'MT') {
5766 $nbdecimal = $conf->global->MAIN_MAX_DECIMALS_TOT;
5767 } elseif ($forcerounding >= 0) {
5768 $nbdecimal = $forcerounding;
5773 $output = number_format($amount, $nbdecimal, $dec, $thousand);
5775 $output = preg_replace(
'/\s/',
' ', $output);
5776 $output = preg_replace(
'/\'/',
''', $output);
5779 $cursymbolbefore = $cursymbolafter =
'';
5780 if ($currency_code && is_object($outlangs)) {
5781 if ($currency_code ==
'auto') {
5782 $currency_code = $conf->currency;
5785 $listofcurrenciesbefore = array(
'AUD',
'CAD',
'CNY',
'COP',
'CLP',
'GBP',
'HKD',
'MXN',
'PEN',
'USD',
'CRC');
5786 $listoflanguagesbefore = array(
'nl_NL');
5787 if (in_array($currency_code, $listofcurrenciesbefore) || in_array($outlangs->defaultlang, $listoflanguagesbefore)) {
5788 $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
5790 $tmpcur = $outlangs->getCurrencySymbol($currency_code);
5791 $cursymbolafter .= ($tmpcur == $currency_code ?
' '.$tmpcur : $tmpcur);
5794 $output = $cursymbolbefore.$output.$end.($cursymbolafter ?
' ' :
'').$cursymbolafter;
5825 global $langs, $conf;
5828 if (is_null($amount)) {
5837 if (is_null($langs)) {
5841 if ($langs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
5842 $dec = $langs->transnoentitiesnoconv(
"SeparatorDecimal");
5844 if ($langs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
5845 $thousand = $langs->transnoentitiesnoconv(
"SeparatorThousand");
5848 if ($thousand ==
'None') {
5850 } elseif ($thousand ==
'Space') {
5858 if (!is_numeric($amount)) {
5859 $amount = preg_replace(
'/[a-zA-Z\/\\\*\(\)<>\_]/',
'', $amount);
5862 if ($option == 2 && $thousand ==
'.' && preg_match(
'/\.(\d\d\d)$/', (
string) $amount)) {
5863 $amount = str_replace($thousand,
'', $amount);
5869 if (is_numeric($amount)) {
5871 $temps = sprintf(
"%0.10F", $amount - intval($amount));
5872 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
5874 $amount = number_format($amount, $nbofdec, $dec, $thousand);
5879 if ($thousand !=
',' && $thousand !=
'.') {
5880 $amount = str_replace(
',',
'.', $amount);
5883 $amount = str_replace(
' ',
'', $amount);
5884 $amount = str_replace($thousand,
'', $amount);
5885 $amount = str_replace($dec,
'.', $amount);
5887 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
5893 $nbofdectoround =
'';
5894 if ($rounding ==
'MU') {
5895 $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_UNIT;
5896 } elseif ($rounding ==
'MT') {
5897 $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_TOT;
5898 } elseif ($rounding ==
'MS') {
5899 $nbofdectoround = isset($conf->global->MAIN_MAX_DECIMALS_STOCK) ? $conf->global->MAIN_MAX_DECIMALS_STOCK : 5;
5900 } elseif ($rounding ==
'CU') {
5901 $nbofdectoround = max($conf->global->MAIN_MAX_DECIMALS_UNIT, 8);
5902 } elseif ($rounding ==
'CT') {
5903 $nbofdectoround = max($conf->global->MAIN_MAX_DECIMALS_TOT, 8);
5904 } elseif (is_numeric($rounding)) {
5905 $nbofdectoround = (int) $rounding;
5910 $amount = round(is_string($amount) ? (
float) $amount : $amount, $nbofdectoround);
5912 return 'ErrorBadParameterProvidedToFunction';
5918 if (is_numeric($amount)) {
5920 $temps = sprintf(
"%0.10F", $amount - intval($amount));
5921 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
5923 $amount = number_format($amount, min($nbofdec, $nbofdectoround), $dec, $thousand);
5929 if ($thousand !=
',' && $thousand !=
'.') {
5930 $amount = str_replace(
',',
'.', $amount);
5933 $amount = str_replace(
' ',
'', $amount);
5934 $amount = str_replace($thousand,
'', $amount);
5935 $amount = str_replace($dec,
'.', $amount);
5937 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
5955 function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round = -1, $forceunitoutput =
'no', $use_short_label = 0)
5957 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
5959 if (($forceunitoutput ==
'no' && $dimension < 1 / 10000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -6)) {
5960 $dimension = $dimension * 1000000;
5962 } elseif (($forceunitoutput ==
'no' && $dimension < 1 / 10 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -3)) {
5963 $dimension = $dimension * 1000;
5965 } elseif (($forceunitoutput ==
'no' && $dimension > 100000000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 6)) {
5966 $dimension = $dimension / 1000000;
5968 } elseif (($forceunitoutput ==
'no' && $dimension > 100000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 3)) {
5969 $dimension = $dimension / 1000;
5985 $ret =
price($dimension, 0, $outputlangs, 0, 0, $round);
5986 $ret .=
' '.measuringUnitString(0, $type, $unit, $use_short_label, $outputlangs);
6004 function get_localtax($vatrate, $local, $thirdparty_buyer =
"", $thirdparty_seller =
"", $vatnpr = 0)
6006 global $db, $conf, $mysoc;
6008 if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) {
6009 $thirdparty_seller = $mysoc;
6012 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);
6014 $vatratecleaned = $vatrate;
6016 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
6017 $vatratecleaned = trim($reg[1]);
6018 $vatratecode = $reg[2];
6027 if ($mysoc->country_code ==
'ES') {
6029 if (!$mysoc->localtax1_assuj || (
string) $vatratecleaned ==
"0") {
6032 if ($thirdparty_seller->id == $mysoc->id) {
6033 if (!$thirdparty_buyer->localtax1_assuj) {
6037 if (!$thirdparty_seller->localtax1_assuj) {
6045 if (!$mysoc->localtax2_assuj) {
6048 if ($thirdparty_seller->id == $mysoc->id) {
6049 if (!$thirdparty_buyer->localtax2_assuj) {
6053 if (!$thirdparty_seller->localtax2_assuj) {
6059 if ($local == 1 && !$thirdparty_seller->localtax1_assuj) {
6062 if ($local == 2 && !$thirdparty_seller->localtax2_assuj) {
6068 if (in_array($mysoc->country_code, array(
'ES'))) {
6069 $conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY = 1;
6073 if (!empty($conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY)) {
6075 if ($thirdparty_seller != $mysoc) {
6077 return $thirdparty_seller->localtax1_value;
6081 return $conf->global->MAIN_INFO_VALUE_LOCALTAX1;
6086 if ($thirdparty_seller != $mysoc) {
6089 return $thirdparty_seller->localtax2_value;
6092 if (in_array($mysoc->country_code, array(
'ES'))) {
6093 return $thirdparty_buyer->localtax2_value;
6095 return $conf->global->MAIN_INFO_VALUE_LOCALTAX2;
6102 $sql =
"SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
6103 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
6104 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($thirdparty_seller->country_code).
"'";
6105 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
6106 if (!empty($vatratecode)) {
6107 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
6109 $sql .=
" AND t.recuperableonly = '".$db->escape($vatnpr).
"'";
6112 $resql = $db->query($sql);
6115 $obj = $db->fetch_object(
$resql);
6118 return $obj->localtax1;
6119 } elseif ($local == 2) {
6120 return $obj->localtax2;
6141 $valors = explode(
":", $tax);
6143 if (count($valors) > 1) {
6160 $sql =
" SELECT t.localtax".$local.
" as localtax";
6161 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t INNER JOIN ".MAIN_DB_PREFIX.
"c_country as c ON c.rowid = t.fk_pays";
6162 $sql .=
" WHERE c.code = '".$db->escape($mysoc->country_code).
"' AND t.active = 1 AND t.taux = (";
6163 $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";
6164 $sql .=
" WHERE c.code = '".$db->escape($mysoc->country_code).
"' AND tt.active = 1)";
6165 $sql .=
" AND t.localtax".$local.
"_type <> '0'";
6166 $sql .=
" ORDER BY t.rowid DESC";
6168 $resql = $db->query($sql);
6170 $obj = $db->fetch_object(
$resql);
6171 return $obj->localtax;
6191 function getTaxesFromId($vatrate, $buyer =
null, $seller =
null, $firstparamisid = 1)
6195 dol_syslog(
"getTaxesFromId vat id or rate = ".$vatrate);
6198 $sql =
"SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy,";
6199 $sql .=
" t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type";
6200 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t";
6201 if ($firstparamisid) {
6202 $sql .=
" WHERE t.rowid = ".(int) $vatrate;
6204 $vatratecleaned = $vatrate;
6207 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
6208 $vatratecleaned = $reg[1];
6209 $vatratecode = $reg[2];
6212 $sql .=
", ".MAIN_DB_PREFIX.
"c_country as c";
6215 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($seller->country_code).
"'";
6216 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
6218 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
6222 $resql = $db->query($sql);
6224 $obj = $db->fetch_object(
$resql);
6227 'rowid'=>$obj->rowid,
6230 'localtax1'=>$obj->localtax1,
6231 'localtax1_type'=>$obj->localtax1_type,
6232 'localtax2'=>$obj->localtax2,
6233 'localtax2_type'=>$obj->localtax2_type,
6235 'accountancy_code_sell'=>$obj->accountancy_code_sell,
6236 'accountancy_code_buy'=>$obj->accountancy_code_buy
6268 dol_syslog(
"getLocalTaxesFromRate vatrate=".$vatrate.
" local=".$local);
6271 $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";
6272 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t";
6273 if ($firstparamisid) {
6274 $sql .=
" WHERE t.rowid = ".(int) $vatrate;
6276 $vatratecleaned = $vatrate;
6279 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
6280 $vatratecleaned = $reg[1];
6281 $vatratecode = $reg[2];
6284 $sql .=
", ".MAIN_DB_PREFIX.
"c_country as c";
6285 if (!empty($mysoc) && $mysoc->country_code ==
'ES') {
6286 $countrycodetouse = ((empty($buyer) || empty($buyer->country_code)) ? $mysoc->country_code : $buyer->country_code);
6287 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($countrycodetouse).
"'";
6289 $countrycodetouse = ((empty($seller) || empty($seller->country_code)) ? $mysoc->country_code : $seller->country_code);
6290 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($countrycodetouse).
"'";
6292 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
6294 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
6298 $resql = $db->query($sql);
6300 $obj = $db->fetch_object(
$resql);
6303 $vateratestring = $obj->rate.($obj->code ?
' ('.$obj->code.
')' :
'');
6306 return array($obj->localtax1_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
6307 } elseif ($local == 2) {
6308 return array($obj->localtax2_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
6310 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);
6330 global $db, $conf, $mysoc;
6332 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
6340 $product->fetch($idprod);
6342 if ($mysoc->country_code == $thirdpartytouse->country_code) {
6344 if ($idprodfournprice > 0) {
6345 $result = $product->get_buyprice($idprodfournprice, 0, 0, 0);
6347 $ret = $product->vatrate_supplier;
6348 if ($product->default_vat_code_supplier) {
6349 $ret .=
' ('.$product->default_vat_code_supplier.
')';
6355 $ret = $product->tva_tx;
6356 if ($product->default_vat_code) {
6357 $ret .=
' ('.$product->default_vat_code.
')';
6368 if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS)) {
6370 $sql =
"SELECT t.taux as vat_rate, t.code as default_vat_code";
6371 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
6372 $sql .=
" WHERE t.active = 1 AND t.fk_pays = c.rowid AND c.code = '".$db->escape($thirdpartytouse->country_code).
"'";
6373 $sql .=
" ORDER BY t.use_default DESC, t.taux DESC, t.code ASC, t.recuperableonly ASC";
6374 $sql .= $db->plimit(1);
6376 $resql = $db->query($sql);
6378 $obj = $db->fetch_object(
$resql);
6380 $ret = $obj->vat_rate;
6381 if ($obj->default_vat_code) {
6382 $ret .=
' ('.$obj->default_vat_code.
')';
6394 if ($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS !=
'none') {
6395 $defaulttx = $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;
6406 dol_syslog(
"get_product_vat_for_country: ret=".$ret);
6423 if (!class_exists(
'Product')) {
6424 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
6433 $result = $product->fetch($idprod);
6435 if ($mysoc->country_code == $thirdpartytouse->country_code) {
6449 $sql =
"SELECT taux as vat_rate, localtax1, localtax2";
6450 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
6451 $sql .=
" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$db->escape($thirdpartytouse->country_code).
"'";
6452 $sql .=
" ORDER BY t.taux DESC, t.recuperableonly ASC";
6453 $sql .= $db->plimit(1);
6455 $resql = $db->query($sql);
6457 $obj = $db->fetch_object(
$resql);
6460 $ret = $obj->localtax1;
6461 } elseif ($local == 2) {
6462 $ret = $obj->localtax2;
6470 dol_syslog(
"get_product_localtax_for_country: ret=".$ret);
6494 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
6497 $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;
6499 $seller_country_code = $thirdparty_seller->country_code;
6500 $seller_in_cee =
isInEEC($thirdparty_seller);
6502 $buyer_country_code = $thirdparty_buyer->country_code;
6503 $buyer_in_cee =
isInEEC($thirdparty_buyer);
6505 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 :
''));
6509 if (!empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC)) {
6510 if ($seller_in_cee && $buyer_in_cee) {
6511 $isacompany = $thirdparty_buyer->
isACompany();
6512 if ($isacompany &&
getDolGlobalString(
'MAIN_USE_VAT_COMPANIES_IN_EEC_WITH_INVALID_VAT_ID_ARE_INDIVIDUAL')) {
6513 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
6527 if (!$seller_use_vat) {
6535 if (($seller_country_code == $buyer_country_code)
6536 || (in_array($seller_country_code, array(
'FR',
'MC')) && in_array($buyer_country_code, array(
'FR',
'MC')))) {
6546 if (($seller_in_cee && $buyer_in_cee)) {
6547 $isacompany = $thirdparty_buyer->
isACompany();
6548 if ($isacompany &&
getDolGlobalString(
'MAIN_USE_VAT_COMPANIES_IN_EEC_WITH_INVALID_VAT_ID_ARE_INDIVIDUAL')) {
6549 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
6566 if (!empty($conf->global->MAIN_USE_VAT_OF_PRODUCT_FOR_INDIVIDUAL_CUSTOMER_OUT_OF_EEC) && empty($buyer_in_cee)) {
6567 $isacompany = $thirdparty_buyer->
isACompany();
6595 if ($idprodfournprice > 0) {
6596 if (!class_exists(
'ProductFournisseur')) {
6597 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
6600 $prodprice->fetch_product_fournisseur_price($idprodfournprice);
6601 return $prodprice->fourn_tva_npr;
6602 } elseif ($idprod > 0) {
6603 if (!class_exists(
'Product')) {
6604 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
6607 $prod->fetch($idprod);
6608 return $prod->tva_npr;
6631 if (!is_object($thirdparty_seller)) {
6634 if (!is_object($thirdparty_buyer)) {
6639 if ($mysoc->country_code ==
'ES') {
6640 if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) {
6645 if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) {
6648 if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj ==
'localtax1off') {
6652 } elseif ($local == 2) {
6654 if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) {
6657 if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj ==
'localtax2off') {
6662 if ($thirdparty_seller->country_code == $thirdparty_buyer->country_code) {
6677 function yn($yesno, $case = 1, $color = 0)
6681 $result =
'unknown';
6683 if ($yesno == 1 || strtolower($yesno) ==
'yes' || strtolower($yesno) ==
'true') {
6684 $result = $langs->trans(
'yes');
6685 if ($case == 1 || $case == 3) {
6686 $result = $langs->trans(
"Yes");
6689 $result =
'<input type="checkbox" value="1" checked disabled>';
6692 $result =
'<input type="checkbox" value="1" checked disabled> '.$result;
6696 } elseif ($yesno == 0 || strtolower($yesno) ==
'no' || strtolower($yesno) ==
'false') {
6697 $result = $langs->trans(
"no");
6698 if ($case == 1 || $case == 3) {
6699 $result = $langs->trans(
"No");
6702 $result =
'<input type="checkbox" value="0" disabled>';
6705 $result =
'<input type="checkbox" value="0" disabled> '.$result;
6711 $classname =
'error';
6715 return '<span class="'.$classname.
'">'.$result.
'</span>';
6735 function get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart =
'')
6739 if (empty($modulepart) && !empty($object->module)) {
6740 $modulepart = $object->module;
6745 $arrayforoldpath = array(
'cheque',
'category',
'holiday',
'supplier_invoice',
'invoice_supplier',
'mailing',
'supplier_payment');
6747 $arrayforoldpath[] =
'product';
6749 if (!empty($level) && in_array($modulepart, $arrayforoldpath)) {
6751 if (empty($alpha)) {
6752 $num = preg_replace(
'/([^0-9])/i',
'', $num);
6754 $num = preg_replace(
'/^.*\-/i',
'', $num);
6756 $num = substr(
"000".$num, -$level);
6758 $path = substr($num, 0, 1);
6761 $path = substr($num, 1, 1).
'/'.substr($num, 0, 1);
6764 $path = substr($num, 2, 1).
'/'.substr($num, 1, 1).
'/'.substr($num, 0, 1);
6774 if (empty($withoutslash) && !empty($path)) {
6793 dol_syslog(
"functions.lib::dol_mkdir: dir=".$dir, LOG_INFO);
6796 if (@is_dir($dir_osencoded)) {
6804 if (!empty($dataroot)) {
6806 $dir = str_replace($dataroot.
'/',
'', $dir);
6807 $ccdir = $dataroot.
'/';
6810 $cdir = explode(
"/", $dir);
6811 $num = count($cdir);
6812 for ($i = 0; $i < $num; $i++) {
6814 $ccdir .=
'/'.$cdir[$i];
6816 $ccdir .= $cdir[$i];
6818 if (preg_match(
"/^.:$/", $ccdir, $regs)) {
6826 if (!@is_dir($ccdir_osencoded)) {
6827 dol_syslog(
"functions.lib::dol_mkdir: Directory '".$ccdir.
"' does not exists or is outside open_basedir PHP setting.", LOG_DEBUG);
6830 $dirmaskdec = octdec((
string) $newmask);
6831 if (empty($newmask)) {
6832 $dirmaskdec = empty($conf->global->MAIN_UMASK) ? octdec(
'0755') : octdec($conf->global->MAIN_UMASK);
6834 $dirmaskdec |= octdec(
'0111');
6835 if (!@mkdir($ccdir_osencoded, $dirmaskdec)) {
6837 dol_syslog(
"functions.lib::dol_mkdir: Fails to create directory '".$ccdir.
"' or directory already exists.", LOG_WARNING);
6840 dol_syslog(
"functions.lib::dol_mkdir: Directory '".$ccdir.
"' created", LOG_DEBUG);
6849 return ($nberr ? -$nberr : $nbcreated);
6860 return '<span class="fieldrequired">*</span>';
6880 function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto =
'UTF-8', $strip_tags = 0, $removedoublespaces = 1)
6882 if (is_null($stringtoclean)) {
6886 if ($removelinefeed == 2) {
6887 $stringtoclean = preg_replace(
'/<br[^>]*>(\n|\r)+/ims',
'<br>', $stringtoclean);
6889 $temp = preg_replace(
'/<br[^>]*>/i',
"\n", $stringtoclean);
6894 $temp = str_replace(
'< ',
'__ltspace__', $temp);
6897 $temp = strip_tags($temp);
6900 $pattern =
"/<[^<>]+>/";
6907 $tempbis = str_replace(
'<>',
'', $temp);
6908 $tempbis = preg_replace($pattern,
'', $tempbis);
6910 }
while ($tempbis != $temp);
6915 $temp = preg_replace(
'/<+([a-z]+)/i',
'\1', $temp);
6921 if ($removelinefeed == 1) {
6922 $temp = str_replace(array(
"\r\n",
"\r",
"\n"),
" ", $temp);
6926 if ($removedoublespaces) {
6927 while (strpos($temp,
" ")) {
6928 $temp = str_replace(
" ",
" ", $temp);
6932 $temp = str_replace(
'__ltspace__',
'< ', $temp);
6951 function dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles = 1, $removeclassattribute = 1, $cleanalsojavascript = 0, $allowiframe = 0, $allowed_tags = array())
6953 if (empty($allowed_tags)) {
6954 $allowed_tags = array(
6955 "html",
"head",
"meta",
"body",
"article",
"a",
"abbr",
"b",
"blockquote",
"br",
"cite",
"div",
"dl",
"dd",
"dt",
"em",
"font",
"img",
"ins",
"hr",
"i",
"li",
"link",
6956 "ol",
"p",
"q",
"s",
"section",
"span",
"strike",
"strong",
"title",
"table",
"tr",
"th",
"td",
"u",
"ul",
"sup",
"sub",
"blockquote",
"pre",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6"
6959 $allowed_tags[] =
"comment";
6961 $allowed_tags[] =
"iframe";
6964 $allowed_tags_string = join(
"><", $allowed_tags);
6965 $allowed_tags_string =
'<'.$allowed_tags_string.
'>';
6967 $stringtoclean = str_replace(
'<!DOCTYPE html>',
'__!DOCTYPE_HTML__', $stringtoclean);
6972 $stringtoclean = preg_replace(
'/<!--([^>]*)-->/',
'<comment>\1</comment>', $stringtoclean);
6974 $stringtoclean = preg_replace(
'/:/i',
':', $stringtoclean);
6975 $stringtoclean = preg_replace(
'/:|�+58|:/i',
'', $stringtoclean);
6977 $temp = strip_tags($stringtoclean, $allowed_tags_string);
6979 if ($cleanalsosomestyles) {
6980 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)\s*!\s*important/i',
'', $temp);
6982 if ($removeclassattribute) {
6983 $temp = preg_replace(
'/(<[^>]+)\s+class=((["\']).*?\\3|\\w*)/i',
'\\1', $temp);