44 include_once DOL_DOCUMENT_ROOT.
'/core/lib/json.lib.php';
47 if (!function_exists(
'utf8_encode')) {
54 function utf8_encode($elements)
56 return mb_convert_encoding($elements,
'UTF-8',
'ISO-8859-1');
60 if (!function_exists(
'utf8_decode')) {
67 function utf8_decode($elements)
69 return mb_convert_encoding($elements,
'ISO-8859-1',
'UTF-8');
84 return (
string) (empty($conf->global->$key) ? $default : $conf->global->$key);
97 return (
int) (empty($conf->global->$key) ? $default : $conf->global->$key);
108 return !empty($conf->$module->enabled);
124 require_once DOL_DOCUMENT_ROOT.
"/core/db/".$type.
'.class.php';
126 $class =
'DoliDB'.ucfirst($type);
127 $dolidb =
new $class($type, $host, $user, $pass, $name, $port);
148 function getEntity($element, $shared = 1, $currentobject =
null)
150 global $conf, $mc, $hookmanager, $object, $action, $db;
152 if (! is_object($hookmanager)) {
159 $element =
'contract';
161 case 'order_supplier':
162 $element =
'supplier_order';
164 case 'invoice_supplier':
165 $element =
'supplier_invoice';
169 if (is_object($mc)) {
170 $out = $mc->getEntity($element, $shared, $currentobject);
173 $addzero = array(
'user',
'usergroup',
'c_email_templates',
'email_template',
'default_values');
174 if (in_array($element, $addzero)) {
177 $out .= ((int) $conf->entity);
182 'element' => $element,
185 'currentobject' => $currentobject,
188 $reshook = $hookmanager->executeHooks(
'hookGetEntity', $parameters, $currentobject, $action);
190 if (is_numeric($reshook)) {
191 if ($reshook == 0 && !empty($hookmanager->resPrint)) {
192 $out .=
','.$hookmanager->resPrint;
193 } elseif ($reshook == 1) {
194 $out = $hookmanager->resPrint;
211 if (is_object($mc) && method_exists($mc,
'setEntity')) {
212 return $mc->setEntity($currentobject);
214 return ((is_object($currentobject) && $currentobject->id > 0 && $currentobject->entity > 0) ? $currentobject->entity : $conf->entity);
226 return preg_match(
'/(_pass|password|_pw|_key|securekey|serverkey|secret\d?|p12key|exportkey|_PW_[a-z]+|token)$/i', $keyname);
238 for ($r =
""; $n >= 0; $n = intval($n / 26) - 1)
239 $r = chr($n % 26 + 0x41) . $r;
262 include_once DOL_DOCUMENT_ROOT.
'/includes/mobiledetect/mobiledetectlib/Mobile_Detect.php';
269 $user_agent = substr($user_agent, 0, 512);
271 $detectmobile =
new Mobile_Detect(
null, $user_agent);
272 $tablet = $detectmobile->isTablet();
274 if ($detectmobile->isMobile()) {
278 if ($detectmobile->is(
'AndroidOS')) {
279 $os = $phone =
'android';
280 } elseif ($detectmobile->is(
'BlackBerryOS')) {
281 $os = $phone =
'blackberry';
282 } elseif ($detectmobile->is(
'iOS')) {
285 } elseif ($detectmobile->is(
'PalmOS')) {
286 $os = $phone =
'palm';
287 } elseif ($detectmobile->is(
'SymbianOS')) {
289 } elseif ($detectmobile->is(
'webOS')) {
291 } elseif ($detectmobile->is(
'MaemoOS')) {
293 } elseif ($detectmobile->is(
'WindowsMobileOS') || $detectmobile->is(
'WindowsPhoneOS')) {
299 if (preg_match(
'/linux/i', $user_agent)) {
301 } elseif (preg_match(
'/macintosh/i', $user_agent)) {
303 } elseif (preg_match(
'/windows/i', $user_agent)) {
309 if (preg_match(
'/firefox(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
312 } elseif (preg_match(
'/edge(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
315 } elseif (preg_match(
'/chrome(\/|\s)([\d\.]+)/i', $user_agent, $reg)) {
318 } elseif (preg_match(
'/chrome/i', $user_agent, $reg)) {
321 } elseif (preg_match(
'/iceweasel/i', $user_agent)) {
323 } elseif (preg_match(
'/epiphany/i', $user_agent)) {
325 } elseif (preg_match(
'/safari(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
328 } elseif (preg_match(
'/opera(\/|\s)([\d\.]*)/i', $user_agent, $reg)) {
332 } elseif (preg_match(
'/(MSIE\s([0-9]+\.[0-9]))|.*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
334 $version = end($reg);
335 } elseif (preg_match(
'/(Windows NT\s([0-9]+\.[0-9])).*(Trident\/[0-9]+.[0-9];.*rv:([0-9]+\.[0-9]+))/i', $user_agent, $reg)) {
338 $version = end($reg);
339 } elseif (preg_match(
'/l(i|y)n(x|ks)(\(|\/|\s)*([\d\.]+)/i', $user_agent, $reg)) {
354 'browsername' => $name,
355 'browserversion' => $version,
370 global $conf, $user, $langs, $db;
371 $disconnectdone =
false;
373 if (is_object($db) && !empty($db->connected)) {
374 $depth = $db->transaction_opened;
375 $disconnectdone = $db->close();
377 dol_syslog(
"--- End access to ".$_SERVER[
"PHP_SELF"].(($disconnectdone && $depth) ?
' (Warn: db disconnection forced, transaction depth was '.$depth.
')' :
''), (($disconnectdone && $depth) ? LOG_WARNING : LOG_INFO));
390 $relativepathstring = $_SERVER[
"PHP_SELF"];
392 if (constant(
'DOL_URL_ROOT')) {
393 $relativepathstring = preg_replace(
'/^'.preg_quote(constant(
'DOL_URL_ROOT'),
'/').
'/',
'', $relativepathstring);
395 $relativepathstring = preg_replace(
'/^\//',
'', $relativepathstring);
396 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
402 if (!empty($_GET[
'restore_lastsearch_values'])) {
403 if (!empty($_SESSION[
'lastsearch_values_'.$relativepathstring])) {
404 $tmp = json_decode($_SESSION[
'lastsearch_values_'.$relativepathstring],
true);
405 if (is_array($tmp)) {
406 foreach ($tmp as $key => $val) {
407 if ($key == $paramname) {
415 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_'.$relativepathstring])) {
417 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_'.$relativepathstring])) {
419 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_'.$relativepathstring])) {
421 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_'.$relativepathstring])) {
425 $isset = (isset($_POST[$paramname]) || isset($_GET[$paramname]));
442 if (empty($method)) {
443 $val = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
444 } elseif ($method == 1) {
445 $val = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
446 } elseif ($method == 2) {
447 $val = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
448 } elseif ($method == 3) {
449 $val = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
451 $val =
'BadFirstParameterForGETPOST';
454 return is_array($val);
484 function GETPOST($paramname, $check =
'alphanohtml', $method = 0, $filter =
null, $options =
null, $noreplace = 0)
486 global $mysoc, $user, $conf;
488 if (empty($paramname)) {
489 return 'BadFirstParameterForGETPOST';
492 dol_syslog(
"Deprecated use of GETPOST, called with 1st param = ".$paramname.
" and 2nd param is '', when calling page ".$_SERVER[
"PHP_SELF"], LOG_WARNING);
497 if (empty($method)) {
498 $out = isset($_GET[$paramname]) ? $_GET[$paramname] : (isset($_POST[$paramname]) ? $_POST[$paramname] :
'');
499 } elseif ($method == 1) {
500 $out = isset($_GET[$paramname]) ? $_GET[$paramname] :
'';
501 } elseif ($method == 2) {
502 $out = isset($_POST[$paramname]) ? $_POST[$paramname] :
'';
503 } elseif ($method == 3) {
504 $out = isset($_POST[$paramname]) ? $_POST[$paramname] : (isset($_GET[$paramname]) ? $_GET[$paramname] :
'');
506 return 'BadThirdParameterForGETPOST';
509 if (empty($method) || $method == 3 || $method == 4) {
510 $relativepathstring = $_SERVER[
"PHP_SELF"];
512 if (constant(
'DOL_URL_ROOT')) {
513 $relativepathstring = preg_replace(
'/^'.preg_quote(constant(
'DOL_URL_ROOT'),
'/').
'/',
'', $relativepathstring);
515 $relativepathstring = preg_replace(
'/^\//',
'', $relativepathstring);
516 $relativepathstring = preg_replace(
'/^custom\//',
'', $relativepathstring);
522 if (!empty($_GET[
'restore_lastsearch_values'])) {
523 if (!empty($_SESSION[
'lastsearch_values_'.$relativepathstring])) {
524 $tmp = json_decode($_SESSION[
'lastsearch_values_'.$relativepathstring],
true);
525 if (is_array($tmp)) {
526 foreach ($tmp as $key => $val) {
527 if ($key == $paramname) {
535 if ($paramname ==
'contextpage' && !empty($_SESSION[
'lastsearch_contextpage_'.$relativepathstring])) {
536 $out = $_SESSION[
'lastsearch_contextpage_'.$relativepathstring];
537 } elseif ($paramname ==
'limit' && !empty($_SESSION[
'lastsearch_limit_'.$relativepathstring])) {
538 $out = $_SESSION[
'lastsearch_limit_'.$relativepathstring];
539 } elseif ($paramname ==
'page' && !empty($_SESSION[
'lastsearch_page_'.$relativepathstring])) {
540 $out = $_SESSION[
'lastsearch_page_'.$relativepathstring];
541 } elseif ($paramname ==
'mode' && !empty($_SESSION[
'lastsearch_mode_'.$relativepathstring])) {
542 $out = $_SESSION[
'lastsearch_mode_'.$relativepathstring];
544 } elseif (!isset($_GET[
'sortfield'])) {
547 if (!empty($_GET[
'action']) && $_GET[
'action'] ==
'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
550 if (is_object($object) && isset($object->fields[$paramname][
'default'])) {
551 $out = $object->fields[$paramname][
'default'];
554 if (!empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) {
555 if (!empty($_GET[
'action']) && (preg_match(
'/^create/', $_GET[
'action']) || preg_match(
'/^presend/', $_GET[
'action'])) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
557 if (!empty($user->default_values)) {
558 if (isset($user->default_values[$relativepathstring][
'createform'])) {
559 foreach ($user->default_values[$relativepathstring][
'createform'] as $defkey => $defval) {
561 if ($defkey !=
'_noquery_') {
562 $tmpqueryarraytohave = explode(
'&', $defkey);
565 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
566 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
579 if (isset($user->default_values[$relativepathstring][
'createform'][$defkey][$paramname])) {
580 $out = $user->default_values[$relativepathstring][
'createform'][$defkey][$paramname];
587 } elseif (!empty($paramname) && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
589 if (!empty($user->default_values)) {
592 if ($paramname ==
'sortfield' || $paramname ==
'sortorder') {
594 if (isset($user->default_values[$relativepathstring][
'sortorder'])) {
596 foreach ($user->default_values[$relativepathstring][
'sortorder'] as $defkey => $defval) {
598 if ($defkey !=
'_noquery_') {
599 $tmpqueryarraytohave = explode(
'&', $defkey);
602 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
603 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
616 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
617 foreach ($user->default_values[$relativepathstring][
'sortorder'][$defkey] as $key => $val) {
621 if ($paramname ==
'sortfield') {
624 if ($paramname ==
'sortorder') {
632 } elseif (isset($user->default_values[$relativepathstring][
'filters'])) {
633 foreach ($user->default_values[$relativepathstring][
'filters'] as $defkey => $defval) {
634 if (!empty($_GET[
'disabledefaultvalues'])) {
638 if ($defkey !=
'_noquery_') {
639 $tmpqueryarraytohave = explode(
'&', $defkey);
642 foreach ($tmpqueryarraytohave as $tmpquerytohave) {
643 if (!in_array($tmpquerytohave, $tmpqueryarraywehave)) {
657 if (isset($_POST[
'sall']) || isset($_POST[
'search_all']) || isset($_GET[
'sall']) || isset($_GET[
'search_all'])) {
659 if (empty($conf->global->MAIN_DISABLE_DEFAULT_FILTER_FOR_QUICK_SEARCH)) {
660 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
661 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
664 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
";",
"=");
665 $out =
dol_string_nospecial($user->default_values[$relativepathstring][
'filters'][$defkey][$paramname],
'', $forbidden_chars_to_replace);
680 if (!is_array($out) && empty($_POST[$paramname]) && empty($noreplace)) {
684 while (preg_match(
'/__([A-Z0-9]+_?[A-Z0-9]+)__/i', $out, $reg) && ($loopnb < $maxloop)) {
688 if ($reg[1] ==
'DAY') {
690 $newout = $tmp[
'mday'];
691 } elseif ($reg[1] ==
'MONTH') {
693 $newout = $tmp[
'mon'];
694 } elseif ($reg[1] ==
'YEAR') {
696 $newout = $tmp[
'year'];
697 } elseif ($reg[1] ==
'PREVIOUS_DAY') {
700 $newout = $tmp2[
'day'];
701 } elseif ($reg[1] ==
'PREVIOUS_MONTH') {
704 $newout = $tmp2[
'month'];
705 } elseif ($reg[1] ==
'PREVIOUS_YEAR') {
707 $newout = ($tmp[
'year'] - 1);
708 } elseif ($reg[1] ==
'NEXT_DAY') {
711 $newout = $tmp2[
'day'];
712 } elseif ($reg[1] ==
'NEXT_MONTH') {
715 $newout = $tmp2[
'month'];
716 } elseif ($reg[1] ==
'NEXT_YEAR') {
718 $newout = ($tmp[
'year'] + 1);
719 } elseif ($reg[1] ==
'MYCOMPANY_COUNTRY_ID' || $reg[1] ==
'MYCOUNTRY_ID' || $reg[1] ==
'MYCOUNTRYID') {
720 $newout = $mysoc->country_id;
721 } elseif ($reg[1] ==
'USER_ID' || $reg[1] ==
'USERID') {
723 } elseif ($reg[1] ==
'USER_SUPERVISOR_ID' || $reg[1] ==
'SUPERVISOR_ID' || $reg[1] ==
'SUPERVISORID') {
724 $newout = $user->fk_user;
725 } elseif ($reg[1] ==
'ENTITY_ID' || $reg[1] ==
'ENTITYID') {
726 $newout = $conf->entity;
731 $out = preg_replace(
'/__'.preg_quote($reg[1],
'/').
'__/', $newout, $out);
736 if (preg_match(
'/^array/', $check)) {
737 if (!is_array($out) || empty($out)) {
740 $tmparray = explode(
':', $check);
741 if (!empty($tmparray[1])) {
742 $tmpcheck = $tmparray[1];
744 $tmpcheck =
'alphanohtml';
746 foreach ($out as $outkey => $outval) {
747 $out[$outkey] =
sanitizeVal($outval, $tmpcheck, $filter, $options);
751 $out =
sanitizeVal($out, $check, $filter, $options);
756 if ($paramname ==
'backtopage' || $paramname ==
'backtolist' || $paramname ==
'backtourl') {
757 $out = str_replace(
'\\',
'/', $out);
758 $out = str_replace(array(
':',
';',
'@',
"\t",
' '),
'', $out);
760 $oldstringtoclean = $out;
761 $out = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $out);
762 $out = preg_replace(array(
'/^[^\?]*%/'),
'', $out);
763 $out = preg_replace(array(
'/^[a-z]*\/\s*\/+/i'),
'', $out);
764 }
while ($oldstringtoclean != $out);
769 if (empty($method) || $method == 3 || $method == 4) {
770 if (preg_match(
'/^search_/', $paramname) || in_array($paramname, array(
'sortorder',
'sortfield'))) {
777 if ($out !=
'' && isset($user)) {
778 $user->lastsearch_values_tmp[$relativepathstring][$paramname] = $out;
797 return (
int)
GETPOST($paramname,
'int', $method,
null,
null, 0);
811 function checkVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
813 return sanitizeVal($out, $check, $filter, $options);
825 function sanitizeVal($out =
'', $check =
'alphanohtml', $filter =
null, $options =
null)
835 if (!is_numeric($out)) {
840 if (preg_match(
'/[^0-9,-]+/i', $out)) {
845 $out = filter_var($out, FILTER_SANITIZE_STRING);
848 $out = filter_var($out, FILTER_SANITIZE_EMAIL);
851 if (!is_array($out)) {
853 if (preg_match(
'/[^a-z]+/i', $out)) {
859 if (!is_array($out)) {
861 if (preg_match(
'/[^a-z0-9_\-\.]+/i', $out)) {
867 if (!is_array($out)) {
869 if (preg_match(
'/[^a-z0-9_\-\.,]+/i', $out)) {
879 if (!is_array($out)) {
882 $oldstringtoclean = $out;
889 $out = str_ireplace(array(
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'\',
'\',
'/',
'../',
'..\\'),
'', $out);
890 }
while ($oldstringtoclean != $out);
895 if (!is_array($out)) {
898 $oldstringtoclean = $out;
904 $out = str_ireplace(array(
'&',
'&',
'&',
'"',
'"',
'"',
'"',
'"',
'/',
'/',
'\',
'\',
'/',
'../',
'..\\'),
'', $out);
905 }
while ($oldstringtoclean != $out);
909 case 'restricthtmlallowunvalid':
911 $oldstringtoclean = $out;
913 if (!empty($out) && !empty($conf->global->MAIN_RESTRICTHTML_ONLY_VALID_HTML) && $check !=
'restricthtmlallowunvalid') {
915 $dom =
new DOMDocument;
919 $out =
'<div class="tricktoremove">'.$out.
'</div>';
921 $dom->loadHTML($out, LIBXML_ERR_NONE|LIBXML_HTML_NOIMPLIED|LIBXML_HTML_NODEFDTD|LIBXML_NONET|LIBXML_NOWARNING|LIBXML_NOXMLDECL);
922 $out = trim($dom->saveHTML());
925 $out = preg_replace(
'/^<div class="tricktoremove">/',
'', $out);
926 $out = preg_replace(
'/<\/div>$/',
'', $out);
929 return 'InvalidHTMLString';
935 $out = preg_replace(
'/'/i',
''', $out);
941 $out = preg_replace_callback(
'/&#(x?[0-9][0-9a-f]+;?)/i',
function ($m) {
946 $out = preg_replace(
'/&#x?[0-9]+/i',
'', $out);
951 if (!empty($conf->global->MAIN_RESTRICTHTML_REMOVE_ALSO_BAD_ATTRIBUTES)) {
957 $out = preg_replace(
'/'/i',
"'", $out);
958 }
while ($oldstringtoclean != $out);
961 if (empty($filter)) {
962 return 'BadFourthParameterForGETPOST';
964 $out = filter_var($out, $filter, $options);
972 if (!function_exists(
'dol_getprefix')) {
982 function dol_getprefix($mode =
'')
985 if ($mode ==
'email') {
988 if (!empty($conf->global->MAIL_PREFIX_FOR_EMAIL_ID)) {
989 if ($conf->global->MAIL_PREFIX_FOR_EMAIL_ID !=
'SERVER_NAME') {
990 return $conf->global->MAIL_PREFIX_FOR_EMAIL_ID;
991 } elseif (isset($_SERVER[
"SERVER_NAME"])) {
992 return $_SERVER[
"SERVER_NAME"];
997 if (!empty($conf->file->instance_unique_id)) {
998 return sha1(
'dolibarr'.$conf->file->instance_unique_id);
1002 return sha1(DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1006 global $dolibarr_main_instance_unique_id, $dolibarr_main_cookie_cryptkey;
1007 $tmp_instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ?
'' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id;
1010 if (!empty($tmp_instance_unique_id)) {
1011 return sha1(
'dolibarr'.$tmp_instance_unique_id);
1015 if (isset($_SERVER[
"SERVER_NAME"]) && isset($_SERVER[
"DOCUMENT_ROOT"])) {
1016 return sha1($_SERVER[
"SERVER_NAME"].$_SERVER[
"DOCUMENT_ROOT"].DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1018 return sha1(DOL_DOCUMENT_ROOT.DOL_URL_ROOT);
1035 global $conf, $langs, $user, $mysoc;
1039 if (!file_exists($fullpath)) {
1040 dol_syslog(
'functions::dol_include_once Tried to load unexisting file: '.$relpath, LOG_WARNING);
1044 if (!empty($classname) && !class_exists($classname)) {
1045 return include $fullpath;
1047 return include_once $fullpath;
1066 $path = preg_replace(
'/^\//',
'', $path);
1069 $res = DOL_DOCUMENT_ROOT.
'/'.$path;
1070 if (is_array($conf->file->dol_document_root)) {
1071 foreach ($conf->file->dol_document_root as $key => $dirroot) {
1072 if ($key ==
'main') {
1075 if (file_exists($dirroot.
'/'.$path)) {
1076 $res = $dirroot.
'/'.$path;
1081 if ($returnemptyifnotfound) {
1083 if ($returnemptyifnotfound == 1 || !file_exists($res)) {
1095 $res = DOL_URL_ROOT.
'/'.$path;
1098 $res = DOL_MAIN_URL_ROOT.
'/'.$path;
1101 $res = DOL_URL_ROOT.
'/'.$path;
1104 foreach ($conf->file->dol_document_root as $key => $dirroot) {
1105 if ($key ==
'main') {
1107 global $dolibarr_main_url_root;
1110 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1111 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1114 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : $urlwithroot).
'/'.$path;
1118 preg_match(
'/^([^\?]+(\.css\.php|\.css|\.js\.php|\.js|\.png|\.jpg|\.php)?)/i', $path, $regs);
1119 if (!empty($regs[1])) {
1121 if (file_exists($dirroot.
'/'.$regs[1])) {
1123 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : DOL_URL_ROOT).$conf->file->dol_url_root[$key].
'/'.$path;
1126 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : DOL_MAIN_URL_ROOT).$conf->file->dol_url_root[$key].
'/'.$path;
1129 global $dolibarr_main_url_root;
1132 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1133 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1136 $res = (preg_match(
'/^http/i', $conf->file->dol_url_root[$key]) ?
'' : $urlwithroot).$conf->file->dol_url_root[$key].
'/'.$path;
1163 if (isset($object->db) && isset($object->db->db) && is_object($object->db->db) && get_class($object->db->db) ==
'PgSql\Connection') {
1164 $tmpsavdb = $object->db;
1168 $myclone = unserialize(serialize($object));
1170 if (!empty($tmpsavdb)) {
1171 $object->db = $tmpsavdb;
1173 } elseif ($native == 2) {
1175 $myclone =
new stdClass();
1176 $tmparray = get_object_vars($object);
1178 if (is_array($tmparray)) {
1179 foreach ($tmparray as $propertykey => $propertyval) {
1180 if (is_scalar($propertyval) || is_array($propertyval)) {
1181 $myclone->$propertykey = $propertyval;
1186 $myclone = clone $object;
1204 if (empty($conf->dol_optimize_smallscreen)) {
1207 if ($type ==
'width' && $size > 250) {
1232 $filesystem_forbidden_chars = array(
'<',
'>',
'/',
'\\',
'?',
'*',
'|',
'"',
':',
'°',
'$',
';');
1234 $tmp = preg_replace(
'/\-\-+/',
'_', $tmp);
1235 $tmp = preg_replace(
'/\s+\-([^\s])/',
' _$1', $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 = str_replace(
'..',
'', $tmp);
1275 $stringtoclean = preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $stringtoclean);
1277 $stringtoclean = preg_replace(
'/<!--[^>]*-->/',
'', $stringtoclean);
1279 $stringtoclean = str_replace(
'\\',
'/', $stringtoclean);
1283 $stringtoclean = str_replace(array(
':',
';',
'@'),
'', $stringtoclean);
1287 $oldstringtoclean = $stringtoclean;
1290 $stringtoclean = str_ireplace(array(
'javascript',
'vbscript',
'&colon',
'&#'),
'', $stringtoclean);
1291 }
while ($oldstringtoclean != $stringtoclean);
1295 $stringtoclean = preg_replace(array(
'/^[a-z]*\/\/+/i'),
'', $stringtoclean);
1298 return $stringtoclean;
1314 if (extension_loaded(
'intl') && !empty($conf->global->MAIN_UNACCENT_USE_TRANSLITERATOR)) {
1315 $transliterator = \Transliterator::createFromRules(
':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', \Transliterator::FORWARD);
1316 return $transliterator->transliterate($str);
1319 $string = rawurlencode($str);
1320 $replacements = array(
1321 '%C3%80' =>
'A',
'%C3%81' =>
'A',
'%C3%82' =>
'A',
'%C3%83' =>
'A',
'%C3%84' =>
'A',
'%C3%85' =>
'A',
1323 '%C3%88' =>
'E',
'%C3%89' =>
'E',
'%C3%8A' =>
'E',
'%C3%8B' =>
'E',
1324 '%C3%8C' =>
'I',
'%C3%8D' =>
'I',
'%C3%8E' =>
'I',
'%C3%8F' =>
'I',
1326 '%C3%92' =>
'O',
'%C3%93' =>
'O',
'%C3%94' =>
'O',
'%C3%95' =>
'O',
'%C3%96' =>
'O',
1328 '%C3%99' =>
'U',
'%C3%9A' =>
'U',
'%C3%9B' =>
'U',
'%C3%9C' =>
'U',
1329 '%C3%9D' =>
'Y',
'%C5%B8' =>
'y',
1330 '%C3%A0' =>
'a',
'%C3%A1' =>
'a',
'%C3%A2' =>
'a',
'%C3%A3' =>
'a',
'%C3%A4' =>
'a',
'%C3%A5' =>
'a',
1332 '%C3%A8' =>
'e',
'%C3%A9' =>
'e',
'%C3%AA' =>
'e',
'%C3%AB' =>
'e',
1333 '%C3%AC' =>
'i',
'%C3%AD' =>
'i',
'%C3%AE' =>
'i',
'%C3%AF' =>
'i',
1335 '%C3%B2' =>
'o',
'%C3%B3' =>
'o',
'%C3%B4' =>
'o',
'%C3%B5' =>
'o',
'%C3%B6' =>
'o',
1337 '%C3%B9' =>
'u',
'%C3%BA' =>
'u',
'%C3%BB' =>
'u',
'%C3%BC' =>
'u',
1338 '%C3%BD' =>
'y',
'%C3%BF' =>
'y'
1340 $string = strtr($string, $replacements);
1341 return rawurldecode($string);
1346 "\xC0\xC1\xC2\xC3\xC4\xC5\xC7
1347 \xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1
1348 \xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD
1349 \xE0\xE1\xE2\xE3\xE4\xE5\xE7\xE8\xE9\xEA\xEB
1350 \xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8
1351 \xF9\xFA\xFB\xFC\xFD\xFF",
1359 $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"));
1378 $forbidden_chars_to_replace = array(
" ",
"'",
"/",
"\\",
":",
"*",
"?",
"\"",
"<",
">",
"|",
"[",
"]",
",",
";",
"=",
'°');
1379 $forbidden_chars_to_remove = array();
1382 if (is_array($badcharstoreplace)) {
1383 $forbidden_chars_to_replace = $badcharstoreplace;
1385 if (is_array($badcharstoremove)) {
1386 $forbidden_chars_to_remove = $badcharstoremove;
1389 return str_replace($forbidden_chars_to_replace, $newstr, str_replace($forbidden_chars_to_remove,
"", $str));
1408 if ($removetabcrlf) {
1409 return preg_replace(
'/[\x00-\x1F\x7F]/u',
'', $str);
1411 return preg_replace(
'/[\x00-\x08\x11-\x12\x14-\x1F\x7F]/u',
'', $str);
1426 $substitjs = array(
"'"=>
"\\'",
"\r"=>
'\\r');
1428 if (empty($noescapebackslashn)) {
1429 $substitjs[
"\n"] =
'\\n';
1430 $substitjs[
'\\'] =
'\\\\';
1433 $substitjs[
"'"] =
"\\'";
1434 $substitjs[
'"'] =
"\\'";
1435 } elseif ($mode == 1) {
1436 $substitjs[
"'"] =
"\\'";
1437 } elseif ($mode == 2) {
1438 $substitjs[
'"'] =
'\\"';
1439 } elseif ($mode == 3) {
1440 $substitjs[
"'"] =
"\\'";
1441 $substitjs[
'"'] =
"\\\"";
1443 return strtr($stringtoescape, $substitjs);
1454 return str_replace(
'"',
'\"', $stringtoescape);
1468 function dol_escape_htmltag($stringtoescape, $keepb = 0, $keepn = 0, $noescapetags =
'', $escapeonlyhtmltags = 0)
1470 if ($noescapetags ==
'common') {
1471 $noescapetags =
'html,body,a,b,em,hr,i,u,ul,li,br,div,img,font,p,span,strong,table,tr,td,th,tbody';
1475 if ($escapeonlyhtmltags) {
1476 $tmp = htmlspecialchars_decode((
string) $stringtoescape, ENT_COMPAT);
1478 $tmp = html_entity_decode((
string) $stringtoescape, ENT_COMPAT,
'UTF-8');
1481 $tmp = strtr($tmp, array(
"<b>"=>
'',
'</b>'=>
''));
1484 $tmp = strtr($tmp, array(
"\r"=>
'\\r',
"\n"=>
'\\n'));
1487 if ($escapeonlyhtmltags) {
1488 return htmlspecialchars($tmp, ENT_COMPAT,
'UTF-8');
1492 $tmparrayoftags = array();
1493 if ($noescapetags) {
1494 $tmparrayoftags = explode(
',', $noescapetags);
1496 if (count($tmparrayoftags)) {
1497 foreach ($tmparrayoftags as $tagtoreplace) {
1498 $tmp = str_ireplace(
'<'.$tagtoreplace.
'>',
'__BEGINTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
1499 $tmp = str_ireplace(
'</'.$tagtoreplace.
'>',
'__ENDTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
1500 $tmp = str_ireplace(
'<'.$tagtoreplace.
' />',
'__BEGINENDTAGTOREPLACE'.$tagtoreplace.
'__', $tmp);
1504 $result = htmlentities($tmp, ENT_COMPAT,
'UTF-8');
1506 if (count($tmparrayoftags)) {
1507 foreach ($tmparrayoftags as $tagtoreplace) {
1508 $result = str_ireplace(
'__BEGINTAGTOREPLACE'.$tagtoreplace.
'__',
'<'.$tagtoreplace.
'>', $result);
1509 $result = str_ireplace(
'__ENDTAGTOREPLACE'.$tagtoreplace.
'__',
'</'.$tagtoreplace.
'>', $result);
1510 $result = str_ireplace(
'__BEGINENDTAGTOREPLACE'.$tagtoreplace.
'__',
'<'.$tagtoreplace.
' />', $result);
1527 if (function_exists(
'mb_strtolower')) {
1528 return mb_strtolower($string, $encoding);
1530 return strtolower($string);
1543 if (function_exists(
'mb_strtoupper')) {
1544 return mb_strtoupper($string, $encoding);
1546 return strtoupper($string);
1559 if (function_exists(
'mb_substr')) {
1560 return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding).mb_substr($string, 1,
null, $encoding);
1562 return ucfirst($string);
1575 if (function_exists(
'mb_convert_case')) {
1576 return mb_convert_case($string, MB_CASE_TITLE, $encoding);
1578 return ucwords($string);
1603 function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename =
'', $restricttologhandler =
'', $logcontext =
null)
1605 global $conf, $user, $debugbar;
1608 if (empty($conf->syslog->enabled)) {
1613 if (defined(
'USEEXTERNALSERVER') && !defined(
'USEDOLIBARRSERVER') && !defined(
'USEDOLIBARREDITOR')) {
1614 global $website, $websitekey;
1615 if (is_object($website) && !empty($website->ref)) {
1616 $suffixinfilename .=
'_website_'.$website->ref;
1617 } elseif (!empty($websitekey)) {
1618 $suffixinfilename .=
'_website_'.$websitekey;
1623 if (defined(
'USESUFFIXINLOG')) {
1624 $suffixinfilename .= constant(
'USESUFFIXINLOG');
1628 foreach ($conf->loghandlers as $loghandlerinstance) {
1629 $loghandlerinstance->setIdent($ident);
1633 if (!empty($message)) {
1635 $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');
1636 if (!array_key_exists($level, $logLevels)) {
1637 throw new Exception(
'Incorrect log level');
1639 if ($level > $conf->global->SYSLOG_LEVEL) {
1643 if (empty($conf->global->MAIN_SHOW_PASSWORD_INTO_LOG)) {
1644 $message = preg_replace(
'/password=\'[^\']*\'/',
'password=\'hidden\'', $message);
1648 if ((!empty($_REQUEST[
'logtohtml']) && !empty($conf->global->MAIN_ENABLE_LOG_TO_HTML))
1649 || (!empty($user->rights->debugbar->read) && is_object($debugbar))) {
1650 $conf->logbuffer[] =
dol_print_date(time(),
"%Y-%m-%d %H:%M:%S").
" ".$logLevels[$level].
" ".$message;
1655 if (!empty($conf->global->MAIN_ENABLE_LOG_INLINE_HTML) && !empty($_GET[
"log"])) {
1656 print
"\n\n<!-- Log start\n";
1658 print
"Log end -->\n";
1662 'message' => $message,
1663 'script' => (isset($_SERVER[
'PHP_SELF']) ? basename($_SERVER[
'PHP_SELF'],
'.php') :
false),
1665 'user' => ((is_object($user) && $user->id) ? $user->login :
false),
1670 if (!empty($remoteip)) {
1671 $data[
'ip'] = $remoteip;
1673 if (!empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) && $_SERVER[
'HTTP_X_FORWARDED_FOR'] != $remoteip) {
1674 $data[
'ip'] = $_SERVER[
'HTTP_X_FORWARDED_FOR'].
' -> '.$data[
'ip'];
1675 } elseif (!empty($_SERVER[
'HTTP_CLIENT_IP']) && $_SERVER[
'HTTP_CLIENT_IP'] != $remoteip) {
1676 $data[
'ip'] = $_SERVER[
'HTTP_CLIENT_IP'].
' -> '.$data[
'ip'];
1678 } elseif (!empty($_SERVER[
'SERVER_ADDR'])) {
1680 $data[
'ip'] = $_SERVER[
'SERVER_ADDR'];
1681 } elseif (!empty($_SERVER[
'COMPUTERNAME'])) {
1683 $data[
'ip'] = $_SERVER[
'COMPUTERNAME'].(empty($_SERVER[
'USERNAME']) ?
'' :
'@'.$_SERVER[
'USERNAME']);
1684 } elseif (!empty($_SERVER[
'LOGNAME'])) {
1686 $data[
'ip'] =
'???@'.$_SERVER[
'LOGNAME'];
1690 foreach ($conf->loghandlers as $loghandlerinstance) {
1691 if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) {
1694 $loghandlerinstance->export($data, $suffixinfilename);
1700 foreach ($conf->loghandlers as $loghandlerinstance) {
1701 $loghandlerinstance->setIdent($ident);
1722 if (strpos($url,
'?') > 0) {
1723 $url .=
'&dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup='.urlencode($name);
1725 $url .=
'?dol_hide_topmenu=1&dol_hide_leftmenu=1&dol_openinpopup='.urlencode($name);
1730 $backtopagejsfieldsid =
''; $backtopagejsfieldslabel =
'';
1731 if ($backtopagejsfields) {
1732 $tmpbacktopagejsfields = explode(
':', $backtopagejsfields);
1733 if (empty($tmpbacktopagejsfields[1])) {
1734 $backtopagejsfields = $name.
":".$backtopagejsfields;
1735 $tmp2backtopagejsfields = explode(
',', $tmpbacktopagejsfields[0]);
1737 $tmp2backtopagejsfields = explode(
',', $tmpbacktopagejsfields[1]);
1739 $backtopagejsfieldsid = empty($tmp2backtopagejsfields[0]) ?
'' : $tmp2backtopagejsfields[0];
1740 $backtopagejsfieldslabel = empty($tmp2backtopagejsfields[1]) ?
'' : $tmp2backtopagejsfields[1];
1741 $url .=
'&backtopagejsfields='.urlencode($backtopagejsfields);
1745 $out .=
'<!-- a link for button to open url into a dialog popup backtopagejsfields = '.$backtopagejsfields.
' -->'.
"\n";
1746 $out .=
'<a class="cursorpointer button_'.$name.($morecss ?
' '.$morecss :
'').
'"'.$disabled.
' title="'.
dol_escape_htmltag($label).
'">'.$buttonstring.
'</a>';
1747 $out .=
'<div id="idfordialog'.$name.
'" class="hidden">div for dialog</div>';
1748 $out .=
'<div id="varforreturndialogid'.$name.
'" class="hidden">div for returned id</div>';
1749 $out .=
'<div id="varforreturndialoglabel'.$name.
'" class="hidden">div for returned label</div>';
1750 $out .=
'<!-- Add js code to open dialog popup on dialog -->';
1751 $out .=
'<script type="text/javascript">
1752 jQuery(document).ready(function () {
1753 jQuery(".button_'.$name.
'").click(function () {
1754 console.log(\'Open popup with jQuery(...).dialog() on URL '.
dol_escape_js(DOL_URL_ROOT.$url).
'\');
1755 var $tmpdialog = $(\
'#idfordialog'.$name.
'\');
1756 $tmpdialog.html(\
'<iframe class="iframedialog" id="iframedialog'.$name.
'" style="border: 0px;" src="'.DOL_URL_ROOT.$url.
'" width="100%" height="98%"></iframe>\');
1760 height: (window.innerHeight - 150),
1763 open:
function (event, ui) {
1764 console.log(
"open popup name='.$name.', backtopagejsfields='.$backtopagejsfields.'");
1766 close:
function (event, ui) {
1767 returnedid = jQuery(
"#varforreturndialogid'.$name.'").text();
1768 returnedlabel = jQuery(
"#varforreturndialoglabel'.$name.'").text();
1769 console.log(
"popup has been closed. returnedid (js var defined into parent page)="+returnedid+
" returnedlabel="+returnedlabel);
1770 if (returnedid !=
"" && returnedid !=
"div for returned id") {
1771 jQuery(
"#'.(empty($backtopagejsfieldsid)?"none
":$backtopagejsfieldsid).'").val(returnedid);
1773 if (returnedlabel !=
"" && returnedlabel !=
"div for returned label") {
1774 jQuery(
"#'.(empty($backtopagejsfieldslabel)?"none
":$backtopagejsfieldslabel).'").val(returnedlabel);
1779 $tmpdialog.dialog(\
'open\');
1802 function dol_fiche_head($links = array(), $active =
'0', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'')
1804 print
dol_get_fiche_head($links, $active, $title, $notab, $picto, $pictoisfullpath, $morehtmlright, $morecss, $limittoshow, $moretabssuffix);
1822 function dol_get_fiche_head($links = array(), $active =
'', $title =
'', $notab = 0, $picto =
'', $pictoisfullpath = 0, $morehtmlright =
'', $morecss =
'', $limittoshow = 0, $moretabssuffix =
'')
1824 global $conf, $langs, $hookmanager;
1828 if (!empty($conf->dol_optimize_smallscreen)) {
1832 $out =
"\n".
'<!-- dol_fiche_head - dol_get_fiche_head -->';
1834 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
1835 $out .=
'<div class="tabs'.($picto ?
'' :
' nopaddingleft').
'" data-role="controlgroup" data-type="horizontal">'.
"\n";
1839 if ($morehtmlright) {
1840 $out .=
'<div class="inline-block floatright tabsElem">'.$morehtmlright.
'</div>';
1844 if (!empty($title) && $showtitle && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1846 $out .=
'<a class="tabTitle">';
1848 $noprefix = $pictoisfullpath;
1849 if (strpos($picto,
'fontawesome_') !==
false) {
1852 $out .=
img_picto($title, ($noprefix ?
'' :
'object_').$picto,
'', $pictoisfullpath, 0, 0,
'',
'imgTabTitle').
' ';
1854 $out .=
'<span class="tabTitleText">'.dol_escape_htmltag(
dol_trunc($title, $limittitle)).
'</span>';
1862 if (is_array($links) && !empty($links)) {
1863 $keys = array_keys($links);
1865 $maxkey = max($keys);
1871 if (empty($limittoshow)) {
1872 $limittoshow = (empty($conf->global->MAIN_MAXTABS_IN_CARD) ? 99 : $conf->global->MAIN_MAXTABS_IN_CARD);
1874 if (!empty($conf->dol_optimize_smallscreen)) {
1882 for ($i = 0; $i <= $maxkey; $i++) {
1883 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
1885 if ($i >= $limittoshow) {
1891 for ($i = 0; $i <= $maxkey; $i++) {
1892 if ((is_numeric($active) && $i == $active) || (!empty($links[$i][2]) && !is_numeric($active) && $active == $links[$i][2])) {
1898 if ($i < $limittoshow || $isactive) {
1900 $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])).
' -->';
1902 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
1903 if (!empty($links[$i][0])) {
1904 $out .=
'<a class="tabimage'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">'.$links[$i][1].
'</a>'.
"\n";
1906 $out .=
'<span class="tabspan">'.$links[$i][1].
'</span>'.
"\n";
1908 } elseif (!empty($links[$i][1])) {
1910 $out .=
'<div class="tab tab'.($isactive?
'active':
'unactive').
'" style="margin: 0 !important">';
1911 if (!empty($links[$i][0])) {
1912 $titletoshow = preg_replace(
'/<.*$/',
'', $links[$i][1]);
1913 $out .=
'<a'.(!empty($links[$i][2]) ?
' id="'.$links[$i][2].
'"' :
'').
' class="tab inline-block valignmiddle'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'" title="'.
dol_escape_htmltag($titletoshow).
'">';
1915 $out .= $links[$i][1];
1916 if (!empty($links[$i][0])) {
1917 $out .=
'</a>'.
"\n";
1919 $out .= empty($links[$i][4]) ?
'' : $links[$i][4];
1928 $outmore .=
'<div class="popuptabset wordwrap">';
1930 $outmore .=
'<div class="popuptab wordwrap" style="display:inherit;">';
1931 if (isset($links[$i][2]) && $links[$i][2] ==
'image') {
1932 if (!empty($links[$i][0])) {
1933 $outmore .=
'<a class="tabimage'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">'.$links[$i][1].
'</a>'.
"\n";
1935 $outmore .=
'<span class="tabspan">'.$links[$i][1].
'</span>'.
"\n";
1937 } elseif (!empty($links[$i][1])) {
1938 $outmore .=
'<a'.(!empty($links[$i][2]) ?
' id="'.$links[$i][2].
'"' :
'').
' class="wordwrap inline-block'.($morecss ?
' '.$morecss :
'').
'" href="'.$links[$i][0].
'">';
1939 $outmore .= preg_replace(
'/([a-z])\/([a-z])/i',
'\\1 / \\2', $links[$i][1]);
1940 $outmore .=
'</a>'.
"\n";
1942 $outmore .=
'</div>';
1949 $outmore .=
'</div>';
1953 $left = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'right' :
'left');
1954 $right = ($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right');
1955 $widthofpopup = 200;
1957 $tabsname = $moretabssuffix;
1958 if (empty($tabsname)) {
1959 $tabsname = str_replace(
"@",
"", $picto);
1961 $out .=
'<div id="moretabs'.$tabsname.
'" class="inline-block tabsElem valignmiddle">';
1962 $out .=
'<div class="tab"><a href="#" class="tab moretab inline-block tabunactive"><span class="hideonsmartphone">'.$langs->trans(
"More").
'</span>... ('.$nbintab.
')</a></div>';
1963 $out .=
'<div id="moretabsList'.$tabsname.
'" style="width: '.$widthofpopup.
'px; position: absolute; '.$left.
': -999em; text-align: '.$left.
'; margin:0px; padding:2px; z-index:10;">';
1966 $out .=
'<div></div>';
1970 $out .=
"$('#moretabs".$tabsname.
"').mouseenter( function() {
1971 var x = this.offsetLeft, y = this.offsetTop;
1972 console.log('mouseenter ".$left.
" x='+x+' y='+y+' window.innerWidth='+window.innerWidth);
1973 if ((window.innerWidth - x) < ".($widthofpopup + 10).
") {
1974 $('#moretabsList".$tabsname.
"').css('".$right.
"','8px');
1976 $('#moretabsList".$tabsname.
"').css('".$left.
"','auto');
1979 $out .=
"$('#moretabs".$tabsname.
"').mouseleave( function() { console.log('mouseleave ".$left.
"'); $('#moretabsList".$tabsname.
"').css('".$left.
"','-999em');});";
1980 $out .=
"</script>";
1983 if ((!empty($title) && $showtitle) || $morehtmlright || !empty($links)) {
1987 if (!$notab || $notab == -1 || $notab == -2) {
1988 $out .=
"\n".
'<div class="tabBar'.($notab == -1 ?
'' : ($notab == -2 ?
' tabBarNoTop' :
' tabBarWithBottom')).
'">'.
"\n";
1991 $parameters = array(
'tabname' => $active,
'out' => $out);
1992 $reshook = $hookmanager->executeHooks(
'printTabsHead', $parameters);
1994 $out = $hookmanager->resPrint;
2020 if (!$notab || $notab == -1) {
2021 return "\n</div>\n";
2046 function dol_banner_tab($object, $paramid, $morehtml =
'', $shownav = 1, $fieldid =
'rowid', $fieldref =
'ref', $morehtmlref =
'', $moreparam =
'', $nodbprefix = 0, $morehtmlleft =
'', $morehtmlstatus =
'', $onlybanner = 0, $morehtmlright =
'')
2048 global $conf,
$form, $user, $langs, $hookmanager, $action;
2052 $maxvisiblephotos = 1;
2054 $entity = (empty($object->entity) ? $conf->entity : $object->entity);
2055 $showbarcode = empty($conf->barcode->enabled) ? 0 : (empty($object->barcode) ? 0 : 1);
2056 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) {
2059 $modulepart =
'unknown';
2061 if ($object->element ==
'societe' || $object->element ==
'contact' || $object->element ==
'product' || $object->element ==
'ticket') {
2062 $modulepart = $object->element;
2063 } elseif ($object->element ==
'member') {
2064 $modulepart =
'memberphoto';
2065 } elseif ($object->element ==
'user') {
2066 $modulepart =
'userphoto';
2069 if (class_exists(
"Imagick")) {
2070 if ($object->element ==
'expensereport' || $object->element ==
'propal' || $object->element ==
'commande' || $object->element ==
'facture' || $object->element ==
'supplier_proposal') {
2071 $modulepart = $object->element;
2072 } elseif ($object->element ==
'fichinter') {
2073 $modulepart =
'ficheinter';
2074 } elseif ($object->element ==
'contrat') {
2075 $modulepart =
'contract';
2076 } elseif ($object->element ==
'order_supplier') {
2077 $modulepart =
'supplier_order';
2078 } elseif ($object->element ==
'invoice_supplier') {
2079 $modulepart =
'supplier_invoice';
2083 if ($object->element ==
'product') {
2085 $cssclass =
'photowithmargin photoref';
2086 $showimage = $object->is_photo_available($conf->product->multidir_output[$entity]);
2087 $maxvisiblephotos = (isset($conf->global->PRODUCT_MAX_VISIBLE_PHOTO) ? $conf->global->PRODUCT_MAX_VISIBLE_PHOTO : 5);
2088 if ($conf->browser->layout ==
'phone') {
2089 $maxvisiblephotos = 1;
2092 $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>';
2094 if (!empty($conf->global->PRODUCT_NODISPLAYIFNOPHOTO)) {
2096 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
2098 $nophoto =
'/public/theme/common/nophoto.png';
2099 $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>';
2102 } elseif ($object->element ==
'ticket') {
2104 $cssclass =
'photoref';
2105 $showimage = $object->is_photo_available($conf->ticket->multidir_output[$entity].
'/'.$object->ref);
2106 $maxvisiblephotos = (isset($conf->global->TICKET_MAX_VISIBLE_PHOTO) ? $conf->global->TICKET_MAX_VISIBLE_PHOTO : 2);
2107 if ($conf->browser->layout ==
'phone') {
2108 $maxvisiblephotos = 1;
2112 $showphoto = $object->show_photos(
'ticket', $conf->ticket->multidir_output[$entity],
'small', $maxvisiblephotos, 0, 0, 0, $width, 0);
2113 if ($object->nbphoto > 0) {
2114 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$showphoto.
'</div>';
2120 if (!empty($conf->global->TICKET_NODISPLAYIFNOPHOTO)) {
2122 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"></div>';
2124 $nophoto =
img_picto(
'No photo',
'object_ticket');
2125 $morehtmlleft .=
'<!-- No photo to show -->';
2126 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
2127 $morehtmlleft .= $nophoto;
2128 $morehtmlleft .=
'</div></div>';
2133 if ($modulepart !=
'unknown') {
2136 if (in_array($modulepart, array(
'propal',
'commande',
'facture',
'ficheinter',
'contract',
'supplier_order',
'supplier_proposal',
'supplier_invoice',
'expensereport')) && class_exists(
"Imagick")) {
2138 $dir_output = (empty($conf->$modulepart->multidir_output[$entity]) ? $conf->$modulepart->dir_output : $conf->$modulepart->multidir_output[$entity]).
"/";
2139 if (in_array($modulepart, array(
'invoice_supplier',
'supplier_invoice'))) {
2140 $subdir =
get_exdir($object->id, 2, 0, 1, $object, $modulepart);
2141 $subdir .= ((!empty($subdir) && !preg_match(
'/\/$/', $subdir)) ?
'/' :
'').$objectref;
2143 $subdir =
get_exdir($object->id, 0, 0, 1, $object, $modulepart);
2145 if (empty($subdir)) {
2146 $subdir =
'errorgettingsubdirofobject';
2149 $filepath = $dir_output.$subdir.
"/";
2151 $filepdf = $filepath.$objectref.
".pdf";
2152 $relativepath = $subdir.
'/'.$objectref.
'.pdf';
2155 $fileimage = $filepdf.
'_preview.png';
2156 $relativepathimage = $relativepath.
'_preview.png';
2158 $pdfexists = file_exists($filepdf);
2163 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
2164 if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) {
2165 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2174 if ($pdfexists && !$error) {
2175 $heightforphotref = 80;
2176 if (!empty($conf->dol_optimize_smallscreen)) {
2177 $heightforphotref = 60;
2180 if (file_exists($fileimage)) {
2181 $phototoshow =
'<div class="photoref">';
2182 $phototoshow .=
'<img height="'.$heightforphotref.
'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart=apercu'.$modulepart.
'&file='.urlencode($relativepathimage).
'">';
2183 $phototoshow .=
'</div>';
2186 } elseif (!$phototoshow) {
2187 $phototoshow .=
$form->showphoto($modulepart, $object, 0, 0, 0,
'photowithmargin photoref',
'small', 1, 0, $maxvisiblephotos);
2191 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">';
2192 $morehtmlleft .= $phototoshow;
2193 $morehtmlleft .=
'</div>';
2197 if (empty($phototoshow)) {
2198 if ($object->element ==
'action') {
2200 $cssclass =
'photorefcenter';
2201 $nophoto =
img_picto(
'No photo',
'title_agenda');
2204 $cssclass =
'photorefcenter';
2205 $picto = $object->picto;
2206 $prefix =
'object_';
2207 if ($object->element ==
'project' && !$object->public) {
2210 if (strpos($picto,
'fontawesome_') !==
false) {
2213 $nophoto =
img_picto(
'No photo', $prefix.$picto);
2215 $morehtmlleft .=
'<!-- No photo to show -->';
2216 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref">';
2217 $morehtmlleft .= $nophoto;
2218 $morehtmlleft .=
'</div></div>';
2224 $morehtmlleft .=
'<div class="floatleft inline-block valignmiddle divphotoref">'.$form->showbarcode($object, 100,
'photoref valignmiddle').
'</div>';
2227 if ($object->element ==
'societe') {
2228 if (!empty($conf->use_javascript_ajax) && $user->rights->societe->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
2229 $morehtmlstatus .=
ajax_object_onoff($object,
'status',
'status',
'InActivity',
'ActivityCeased');
2231 $morehtmlstatus .= $object->getLibStatut(6);
2233 } elseif ($object->element ==
'product') {
2235 if (!empty($conf->use_javascript_ajax) && $user->rights->produit->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
2236 $morehtmlstatus .=
ajax_object_onoff($object,
'status',
'tosell',
'ProductStatusOnSell',
'ProductStatusNotOnSell');
2238 $morehtmlstatus .=
'<span class="statusrefsell">'.$object->getLibStatut(6, 0).
'</span>';
2240 $morehtmlstatus .=
' ';
2242 if (!empty($conf->use_javascript_ajax) && $user->rights->produit->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
2243 $morehtmlstatus .=
ajax_object_onoff($object,
'status_buy',
'tobuy',
'ProductStatusOnBuy',
'ProductStatusNotOnBuy');
2245 $morehtmlstatus .=
'<span class="statusrefbuy">'.$object->getLibStatut(6, 1).
'</span>';
2247 } elseif (in_array($object->element, array(
'facture',
'invoice',
'invoice_supplier',
'chargesociales',
'loan',
'tva',
'salary'))) {
2248 $tmptxt = $object->getLibStatut(6, $object->totalpaid);
2249 if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
2250 $tmptxt = $object->getLibStatut(5, $object->totalpaid);
2252 $morehtmlstatus .= $tmptxt;
2253 } elseif ($object->element ==
'contrat' || $object->element ==
'contract') {
2254 if ($object->statut == 0) {
2255 $morehtmlstatus .= $object->getLibStatut(5);
2257 $morehtmlstatus .= $object->getLibStatut(4);
2259 } elseif ($object->element ==
'facturerec') {
2260 if ($object->frequency == 0) {
2261 $morehtmlstatus .= $object->getLibStatut(2);
2263 $morehtmlstatus .= $object->getLibStatut(5);
2265 } elseif ($object->element ==
'project_task') {
2266 $object->fk_statut = 1;
2267 if ($object->progress > 0) {
2268 $object->fk_statut = 2;
2270 if ($object->progress >= 100) {
2271 $object->fk_statut = 3;
2273 $tmptxt = $object->getLibStatut(5);
2274 $morehtmlstatus .= $tmptxt;
2276 $tmptxt = $object->getLibStatut(6);
2277 if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) {
2278 $tmptxt = $object->getLibStatut(5);
2280 $morehtmlstatus .= $tmptxt;
2284 if (!empty($conf->accounting->enabled) && in_array($object->element, array(
'bank',
'paiementcharge',
'facture',
'invoice',
'invoice_supplier',
'expensereport',
'payment_various'))) {
2286 if (method_exists($object,
'getVentilExportCompta')) {
2287 $accounted = $object->getVentilExportCompta();
2288 $langs->load(
"accountancy");
2289 $morehtmlstatus .=
'</div><div class="statusref statusrefbis"><span class="opacitymedium">'.($accounted > 0 ? $langs->trans(
"Accounted") : $langs->trans(
"NotYetAccounted")).
'</span>';
2294 if (!empty($object->name_alias)) {
2295 $morehtmlref .=
'<div class="refidno">'.$object->name_alias.
'</div>';
2299 if (in_array($object->element, array(
'product',
'bank_account',
'project_task'))) {
2300 if (!empty($object->label)) {
2301 $morehtmlref .=
'<div class="refidno">'.$object->label.
'</div>';
2306 if (method_exists($object,
'getBannerAddress') && !in_array($object->element, array(
'product',
'bookmark',
'ecm_directories',
'ecm_files'))) {
2307 $moreaddress = $object->getBannerAddress(
'refaddress', $object);
2309 $morehtmlref .=
'<div class="refidno">';
2310 $morehtmlref .= $moreaddress;
2311 $morehtmlref .=
'</div>';
2314 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)) {
2315 $morehtmlref .=
'<div style="clear: both;"></div>';
2316 $morehtmlref .=
'<div class="refidno">';
2317 $morehtmlref .= $langs->trans(
"TechnicalID").
': '.$object->id;
2318 $morehtmlref .=
'</div>';
2321 $parameters=array(
'morehtmlref'=>$morehtmlref);
2322 $reshook = $hookmanager->executeHooks(
'formDolBanner', $parameters, $object, $action);
2325 } elseif (empty($reshook)) {
2326 $morehtmlref .= $hookmanager->resPrint;
2327 } elseif ($reshook > 0) {
2328 $morehtmlref = $hookmanager->resPrint;
2332 print
'<div class="'.($onlybanner ?
'arearefnobottom ' :
'arearef ').
'heightref valignmiddle centpercent">';
2333 print
$form->showrefnav($object, $paramid, $morehtml, $shownav, $fieldid, $fieldref, $morehtmlref, $moreparam, $nodbprefix, $morehtmlleft, $morehtmlstatus, $morehtmlright);
2335 print
'<div class="underrefbanner clearboth"></div>';
2351 if ($fieldrequired) {
2352 $ret .=
'<span class="fieldrequired">';
2354 $ret .=
'<label for="'.$fieldkey.
'">';
2355 $ret .= $langs->trans($langkey);
2357 if ($fieldrequired) {
2373 $ret =
' '.$bc[$var];
2375 $ret = preg_replace(
'/class=\"/',
'class="'.$moreclass.
' ', $ret);
2393 function dol_format_address($object, $withcountry = 0, $sep =
"\n", $outputlangs =
'', $mode = 0, $extralangcode =
'')
2395 global $conf, $langs, $hookmanager;
2398 $countriesusingstate = array(
'AU',
'CA',
'US',
'IN',
'GB',
'ES',
'UK',
'TR',
'CN');
2403 $ret .= ($extralangcode ? $object->array_languages[
'address'][$extralangcode] : (empty($object->address) ?
'' : $object->address));
2406 if (isset($object->country_code) && in_array($object->country_code, array(
'AU',
'CA',
'US',
'CN')) || !empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS)) {
2408 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2409 $ret .= (($ret && $town) ? $sep :
'').$town;
2411 if (!empty($object->state)) {
2412 $ret .= ($ret ? ($town ?
", " : $sep) :
'').$object->state;
2414 if (!empty($object->zip)) {
2415 $ret .= ($ret ? (($town || $object->state) ?
", " : $sep) :
'').$object->zip;
2417 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'GB',
'UK'))) {
2419 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2420 $ret .= ($ret ? $sep :
'').$town;
2421 if (!empty($object->state)) {
2422 $ret .= ($ret ?
", " :
'').$object->state;
2424 if (!empty($object->zip)) {
2425 $ret .= ($ret ? $sep :
'').$object->zip;
2427 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'ES',
'TR'))) {
2429 $ret .= ($ret ? $sep :
'').$object->zip;
2430 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2431 $ret .= ($town ? (($object->zip ?
' ' :
'').$town) :
'');
2432 if (!empty($object->state)) {
2433 $ret .=
"\n".$object->state;
2435 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'JP'))) {
2438 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2439 $ret .= ($ret ? $sep :
'').($object->state ? $object->state.
', ' :
'').$town.($object->zip ?
' ' :
'').$object->zip;
2440 } elseif (isset($object->country_code) && in_array($object->country_code, array(
'IT'))) {
2442 $ret .= ($ret ? $sep :
'').$object->zip;
2443 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2444 $ret .= ($town ? (($object->zip ?
' ' :
'').$town) :
'');
2445 $ret .= (empty($object->state_code) ?
'' : (
' '.$object->state_code));
2448 $town = ($extralangcode ? $object->array_languages[
'town'][$extralangcode] : (empty($object->town) ?
'' : $object->town));
2449 $ret .= !empty($object->zip) ? (($ret ? $sep :
'').$object->zip) :
'';
2450 $ret .= ($town ? (($object->zip ?
' ' : ($ret ? $sep :
'')).$town) :
'');
2451 if (!empty($object->state) && in_array($object->country_code, $countriesusingstate)) {
2452 $ret .= ($ret ?
", " :
'').$object->state;
2455 if (!is_object($outputlangs)) {
2456 $outputlangs = $langs;
2459 $langs->load(
"dict");
2460 $ret .= (empty($object->country_code) ?
'' : ($ret ? $sep :
'').$outputlangs->convToOutputCharset($outputlangs->transnoentitiesnoconv(
"Country".$object->country_code)));
2463 $parameters = array(
'withcountry' => $withcountry,
'sep' => $sep,
'outputlangs' => $outputlangs,
'mode' => $mode,
'extralangcode' => $extralangcode);
2464 $reshook = $hookmanager->executeHooks(
'formatAddress', $parameters, $object);
2468 $ret .= $hookmanager->resPrint;
2486 if ((abs($ts) <= 0x7FFFFFFF)) {
2487 return ($is_gmt) ? @gmstrftime($fmt, $ts) : @strftime($fmt, $ts);
2489 return 'Error date into a not supported range';
2514 function dol_print_date($time, $format =
'', $tzoutput =
'auto', $outputlangs =
'', $encodetooutput =
false)
2516 global $conf, $langs;
2523 if ($tzoutput ===
'auto') {
2524 $tzoutput = (empty($conf) ?
'tzserver' : (isset($conf->tzuserinputkey) ? $conf->tzuserinputkey :
'tzserver'));
2529 $offsettz = $offsetdst = 0;
2532 if (is_string($tzoutput)) {
2533 if ($tzoutput ==
'tzserver') {
2535 $offsettzstring = @date_default_timezone_get();
2538 } elseif ($tzoutput ==
'tzuser' || $tzoutput ==
'tzuserrel') {
2540 $offsettzstring = (empty($_SESSION[
'dol_tz_string']) ?
'UTC' : $_SESSION[
'dol_tz_string']);
2542 if (class_exists(
'DateTimeZone')) {
2543 $user_date_tz =
new DateTimeZone($offsettzstring);
2544 $user_dt =
new DateTime();
2545 $user_dt->setTimezone($user_date_tz);
2546 $user_dt->setTimestamp($tzoutput ==
'tzuser' ?
dol_now() : (
int) $time);
2547 $offsettz = $user_dt->getOffset();
2549 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
2550 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
2555 if (!is_object($outputlangs)) {
2556 $outputlangs = $langs;
2559 $format =
'daytextshort';
2564 $reduceformat = (!empty($conf->dol_optimize_smallscreen) && in_array($format, array(
'day',
'dayhour'))) ? 1 : 0;
2565 $format = preg_replace(
'/inputnoreduce/',
'', $format);
2566 $formatwithoutreduce = preg_replace(
'/reduceformat/',
'', $format);
2567 if ($formatwithoutreduce != $format) {
2568 $format = $formatwithoutreduce;
2574 if ($format ==
'day') {
2575 $format = ($outputlangs->trans(
"FormatDateShort") !=
"FormatDateShort" ? $outputlangs->trans(
"FormatDateShort") : $conf->format_date_short);
2576 } elseif ($format ==
'hour') {
2577 $format = ($outputlangs->trans(
"FormatHourShort") !=
"FormatHourShort" ? $outputlangs->trans(
"FormatHourShort") : $conf->format_hour_short);
2578 } elseif ($format ==
'hourduration') {
2579 $format = ($outputlangs->trans(
"FormatHourShortDuration") !=
"FormatHourShortDuration" ? $outputlangs->trans(
"FormatHourShortDuration") : $conf->format_hour_short_duration);
2580 } elseif ($format ==
'daytext') {
2581 $format = ($outputlangs->trans(
"FormatDateText") !=
"FormatDateText" ? $outputlangs->trans(
"FormatDateText") : $conf->format_date_text);
2582 } elseif ($format ==
'daytextshort') {
2583 $format = ($outputlangs->trans(
"FormatDateTextShort") !=
"FormatDateTextShort" ? $outputlangs->trans(
"FormatDateTextShort") : $conf->format_date_text_short);
2584 } elseif ($format ==
'dayhour') {
2585 $format = ($outputlangs->trans(
"FormatDateHourShort") !=
"FormatDateHourShort" ? $outputlangs->trans(
"FormatDateHourShort") : $conf->format_date_hour_short);
2586 } elseif ($format ==
'dayhoursec') {
2587 $format = ($outputlangs->trans(
"FormatDateHourSecShort") !=
"FormatDateHourSecShort" ? $outputlangs->trans(
"FormatDateHourSecShort") : $conf->format_date_hour_sec_short);
2588 } elseif ($format ==
'dayhourtext') {
2589 $format = ($outputlangs->trans(
"FormatDateHourText") !=
"FormatDateHourText" ? $outputlangs->trans(
"FormatDateHourText") : $conf->format_date_hour_text);
2590 } elseif ($format ==
'dayhourtextshort') {
2591 $format = ($outputlangs->trans(
"FormatDateHourTextShort") !=
"FormatDateHourTextShort" ? $outputlangs->trans(
"FormatDateHourTextShort") : $conf->format_date_hour_text_short);
2592 } elseif ($format ==
'dayhourlog') {
2594 $format =
'%Y%m%d%H%M%S';
2595 } elseif ($format ==
'dayhourlogsmall') {
2597 $format =
'%Y%m%d%H%M';
2598 } elseif ($format ==
'dayhourldap') {
2599 $format =
'%Y%m%d%H%M%SZ';
2600 } elseif ($format ==
'dayhourxcard') {
2601 $format =
'%Y%m%dT%H%M%SZ';
2602 } elseif ($format ==
'dayxcard') {
2604 } elseif ($format ==
'dayrfc') {
2605 $format =
'%Y-%m-%d';
2606 } elseif ($format ==
'dayhourrfc') {
2607 $format =
'%Y-%m-%dT%H:%M:%SZ';
2608 } elseif ($format ==
'standard') {
2609 $format =
'%Y-%m-%d %H:%M:%S';
2612 if ($reduceformat) {
2613 $format = str_replace(
'%Y',
'%y', $format);
2614 $format = str_replace(
'yyyy',
'yy', $format);
2618 if (preg_match(
'/%b/i', $format)) {
2620 $format = str_replace(
'%b',
'__b__', $format);
2621 $format = str_replace(
'%B',
'__B__', $format);
2623 if (preg_match(
'/%a/i', $format)) {
2625 $format = str_replace(
'%a',
'__a__', $format);
2626 $format = str_replace(
'%A',
'__A__', $format);
2632 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)) {
2633 dol_print_error(
'',
"Functions.lib::dol_print_date function called with a bad value from page ".$_SERVER[
"PHP_SELF"]);
2635 } elseif (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', $time, $reg)) {
2637 dol_syslog(
"Functions.lib::dol_print_date function called with a bad value from page ".$_SERVER[
"PHP_SELF"], LOG_WARNING);
2640 $syear = (!empty($reg[1]) ? $reg[1] :
'');
2641 $smonth = (!empty($reg[2]) ? $reg[2] :
'');
2642 $sday = (!empty($reg[3]) ? $reg[3] :
'');
2643 $shour = (!empty($reg[4]) ? $reg[4] :
'');
2644 $smin = (!empty($reg[5]) ? $reg[5] :
'');
2645 $ssec = (!empty($reg[6]) ? $reg[6] :
'');
2647 $time =
dol_mktime($shour, $smin, $ssec, $smonth, $sday, $syear,
true);
2648 $ret = adodb_strftime($format, $time + $offsettz + $offsetdst, $to_gmt);
2651 if ($time < 100000000000) {
2652 $timetouse = $time + $offsettz + $offsetdst;
2654 $ret = adodb_strftime($format, $timetouse, $to_gmt);
2656 $ret =
'Bad value '.$time.
' for date';
2660 if (preg_match(
'/__b__/i', $format)) {
2661 $timetouse = $time + $offsettz + $offsetdst;
2664 $month = adodb_strftime(
'%m', $timetouse, $to_gmt);
2665 $month = sprintf(
"%02d", $month);
2666 if ($encodetooutput) {
2667 $monthtext = $outputlangs->transnoentities(
'Month'.$month);
2668 $monthtextshort = $outputlangs->transnoentities(
'MonthShort'.$month);
2670 $monthtext = $outputlangs->transnoentitiesnoconv(
'Month'.$month);
2671 $monthtextshort = $outputlangs->transnoentitiesnoconv(
'MonthShort'.$month);
2674 $ret = str_replace(
'__b__', $monthtextshort, $ret);
2675 $ret = str_replace(
'__B__', $monthtext, $ret);
2679 if (preg_match(
'/__a__/i', $format)) {
2681 $timetouse = $time + $offsettz + $offsetdst;
2683 $w = adodb_strftime(
'%w', $timetouse, $to_gmt);
2684 $dayweek = $outputlangs->transnoentitiesnoconv(
'Day'.$w);
2685 $ret = str_replace(
'__A__', $dayweek, $ret);
2686 $ret = str_replace(
'__a__',
dol_substr($dayweek, 0, 3), $ret);
2716 $datetimeobj =
new DateTime();
2717 $datetimeobj->setTimestamp($timestamp);
2718 if ($forcetimezone) {
2719 $datetimeobj->setTimezone(
new DateTimeZone($forcetimezone ==
'gmt' ?
'UTC' : $forcetimezone));
2722 'year'=>((
int) date_format($datetimeobj,
'Y')),
2723 'mon'=>((
int) date_format($datetimeobj,
'm')),
2724 'mday'=>((
int) date_format($datetimeobj,
'd')),
2725 'wday'=>((
int) date_format($datetimeobj,
'w')),
2726 'yday'=>((
int) date_format($datetimeobj,
'z')),
2727 'hours'=>((
int) date_format($datetimeobj,
'H')),
2728 'minutes'=>((
int) date_format($datetimeobj,
'i')),
2729 'seconds'=>((
int) date_format($datetimeobj,
's')),
2757 function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm =
'auto', $check = 1)
2762 if ($gm ===
'auto') {
2763 $gm = (empty($conf) ?
'tzserver' : $conf->tzuserinputkey);
2768 if ($hour == -1 || empty($hour)) {
2771 if ($minute == -1 || empty($minute)) {
2774 if ($second == -1 || empty($second)) {
2780 if (!$month || !$day) {
2789 if ($hour < 0 || $hour > 24) {
2792 if ($minute < 0 || $minute > 60) {
2795 if ($second < 0 || $second > 60) {
2800 if (empty($gm) || ($gm ===
'server' || $gm ===
'tzserver')) {
2801 $default_timezone = @date_default_timezone_get();
2802 $localtz =
new DateTimeZone($default_timezone);
2803 } elseif ($gm ===
'user' || $gm ===
'tzuser' || $gm ===
'tzuserrel') {
2805 $default_timezone = (empty($_SESSION[
"dol_tz_string"]) ? @date_default_timezone_get() : $_SESSION[
"dol_tz_string"]);
2807 $localtz =
new DateTimeZone($default_timezone);
2809 dol_syslog(
"Warning dol_tz_string contains an invalid value ".$_SESSION[
"dol_tz_string"], LOG_WARNING);
2810 $default_timezone = @date_default_timezone_get();
2812 } elseif (strrpos($gm,
"tz,") !==
false) {
2813 $timezone = str_replace(
"tz,",
"", $gm);
2815 $localtz =
new DateTimeZone($timezone);
2817 dol_syslog(
"Warning passed timezone contains an invalid value ".$timezone, LOG_WARNING);
2821 if (empty($localtz)) {
2822 $localtz =
new DateTimeZone(
'UTC');
2826 $dt =
new DateTime(
'now', $localtz);
2827 $dt->setDate((
int) $year, (
int) $month, (
int) $day);
2828 $dt->setTime((
int) $hour, (
int) $minute, (
int) $second);
2829 $date = $dt->getTimestamp();
2849 if ($mode ===
'auto') {
2853 if ($mode ==
'gmt') {
2855 } elseif ($mode ==
'tzserver') {
2856 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2858 $ret = (int) (
dol_now(
'gmt') + ($tzsecond * 3600));
2864 } elseif ($mode ==
'tzuser' || $mode ==
'tzuserrel') {
2867 $offsettz = (empty($_SESSION[
'dol_tz']) ? 0 : $_SESSION[
'dol_tz']) * 60 * 60;
2868 $offsetdst = (empty($_SESSION[
'dol_dst']) ? 0 : $_SESSION[
'dol_dst']) * 60 * 60;
2869 $ret = (int) (
dol_now(
'gmt') + ($offsettz + $offsetdst));
2886 global $conf, $langs;
2889 if (!empty($conf->dol_optimize_smallscreen)) {
2894 if (empty($shortvalue) || $size < ($level * 10)) {
2896 $textunitshort = $langs->trans(
"b");
2897 $textunitlong = $langs->trans(
"Bytes");
2899 $ret = round($size / $level, 0);
2900 $textunitshort = $langs->trans(
"Kb");
2901 $textunitlong = $langs->trans(
"KiloBytes");
2904 if (empty($shortunit)) {
2905 $ret .=
' '.$textunitlong;
2907 $ret .=
' '.$textunitshort;
2930 $link =
'<a href="';
2931 if (!preg_match(
'/^http/i', $url)) {
2937 $link .=
' target="'.$target.
'"';
2940 if (!preg_match(
'/^http/i', $url)) {
2945 return '<div class="nospan float" style="margin-right: 10px">'.($withpicto ?
img_picto($langs->trans(
"Url"),
'globe').
' ' :
'').$link.
'</div>';
2960 function dol_print_email($email, $cid = 0, $socid = 0, $addlink = 0, $max = 64, $showinvalid = 1, $withpicto = 0)
2962 global $conf, $user, $langs, $hookmanager;
2966 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) {
2970 if (empty($email)) {
2974 if (!empty($addlink)) {
2975 $newemail =
'<a style="text-overflow: ellipsis;" href="';
2976 if (!preg_match(
'/^mailto:/i', $email)) {
2977 $newemail .=
'mailto:';
2979 $newemail .= $email;
2982 $newemail .=
'</a>';
2984 $langs->load(
"errors");
2985 $newemail .=
img_warning($langs->trans(
"ErrorBadEMail", $email));
2988 if (($cid || $socid) && !empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create) {
2991 if (!empty($conf->global->AGENDA_ADDACTIONFOREMAIL)) {
2992 $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>';
2995 $newemail =
'<div>'.$newemail.
' '.$link.
'</div>';
3000 $langs->load(
"errors");
3001 $newemail .=
img_warning($langs->trans(
"ErrorBadEMail", $email));
3006 $rep = ($withpicto ?
img_picto($langs->trans(
"EMail").
' : '.$email, (is_numeric($withpicto) ?
'email' : $withpicto)).
' ' :
'').$newemail;
3009 $parameters = array(
'cid' => $cid,
'socid' => $socid,
'addlink' => $addlink,
'picto' => $withpicto);
3011 $reshook = $hookmanager->executeHooks(
'printEmail', $parameters, $email);
3015 $rep .= $hookmanager->resPrint;
3030 $socialnetworks = array();
3032 require_once DOL_DOCUMENT_ROOT.
'/core/lib/memory.lib.php';
3033 $cachekey =
'socialnetworks_' . $conf->entity;
3035 if (!is_null($dataretrieved)) {
3036 $socialnetworks = $dataretrieved;
3038 $sql =
"SELECT rowid, code, label, url, icon, active FROM ".MAIN_DB_PREFIX.
"c_socialnetworks";
3039 $sql .=
" WHERE entity=".$conf->entity;
3040 $resql = $db->query($sql);
3042 while ($obj = $db->fetch_object(
$resql)) {
3043 $socialnetworks[$obj->code] = array(
3044 'rowid' => $obj->rowid,
3045 'label' => $obj->label,
3047 'icon' => $obj->icon,
3048 'active' => $obj->active,
3055 return $socialnetworks;
3070 global $conf, $user, $langs;
3074 if (empty($value)) {
3078 if (!empty($type)) {
3079 $htmllink =
'<div class="divsocialnetwork inline-block valignmiddle">';
3081 $htmllink .=
'<span class="fa paddingright '.($dictsocialnetworks[$type][
'icon'] ? $dictsocialnetworks[$type][
'icon'] :
'fa-link').
'"></span>';
3082 if ($type ==
'skype') {
3084 $htmllink .=
' ';
3085 $htmllink .=
'<a href="skype:';
3087 $htmllink .=
'?call" alt="'.$langs->trans(
"Call").
' '.$value.
'" title="'.
dol_escape_htmltag($langs->trans(
"Call").
' '.$value).
'">';
3088 $htmllink .=
'<img src="'.DOL_URL_ROOT.
'/theme/common/skype_callbutton.png" border="0">';
3089 $htmllink .=
'</a><a href="skype:';
3091 $htmllink .=
'?chat" alt="'.$langs->trans(
"Chat").
' '.$value.
'" title="'.
dol_escape_htmltag($langs->trans(
"Chat").
' '.$value).
'">';
3092 $htmllink .=
'<img class="paddingleft" src="'.DOL_URL_ROOT.
'/theme/common/skype_chatbutton.png" border="0">';
3093 $htmllink .=
'</a>';
3094 if (($cid || $socid) && !empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create) {
3095 $addlink =
'AC_SKYPE';
3097 if (!empty($conf->global->AGENDA_ADDACTIONFORSKYPE)) {
3098 $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>';
3100 $htmllink .= ($link ?
' '.$link :
'');
3103 if (!empty($dictsocialnetworks[$type][
'url'])) {
3104 $tmpvirginurl = preg_replace(
'/\/?{socialid}/',
'', $dictsocialnetworks[$type][
'url']);
3105 if ($tmpvirginurl) {
3106 $value = preg_replace(
'/^www\.'.preg_quote($tmpvirginurl,
'/').
'\/?/',
'', $value);
3107 $value = preg_replace(
'/^'.preg_quote($tmpvirginurl,
'/').
'\/?/',
'', $value);
3109 $tmpvirginurl3 = preg_replace(
'/^https:\/\//i',
'https://www.', $tmpvirginurl);
3110 if ($tmpvirginurl3) {
3111 $value = preg_replace(
'/^www\.'.preg_quote($tmpvirginurl3,
'/').
'\/?/',
'', $value);
3112 $value = preg_replace(
'/^'.preg_quote($tmpvirginurl3,
'/').
'\/?/',
'', $value);
3115 $tmpvirginurl2 = preg_replace(
'/^https?:\/\//i',
'', $tmpvirginurl);
3116 if ($tmpvirginurl2) {
3117 $value = preg_replace(
'/^www\.'.preg_quote($tmpvirginurl2,
'/').
'\/?/',
'', $value);
3118 $value = preg_replace(
'/^'.preg_quote($tmpvirginurl2,
'/').
'\/?/',
'', $value);
3121 $link = str_replace(
'{socialid}', $value, $dictsocialnetworks[$type][
'url']);
3122 if (preg_match(
'/^https?:\/\//i', $link)) {
3123 $htmllink .=
' <a href="'.dol_sanitizeUrl($link, 0).
'" target="_blank" rel="noopener noreferrer">'.
dol_escape_htmltag($value).
'</a>';
3125 $htmllink .=
' <a href="'.dol_sanitizeUrl($link, 1).
'" target="_blank" rel="noopener noreferrer">'.
dol_escape_htmltag($value).
'</a>';
3131 $htmllink .=
'</div>';
3133 $langs->load(
"errors");
3134 $htmllink .=
img_warning($langs->trans(
"ErrorBadSocialNetworkValue", $value));
3149 function dol_print_profids($profID, $profIDtype, $countrycode =
'', $addcpButton = 1, $separ =
' ')
3153 if (empty($profID) || empty($profIDtype)) {
3156 if (empty($countrycode)) $countrycode = $mysoc->country_code;
3157 $newProfID = $profID;
3158 $id = substr($profIDtype, -1);
3160 if (strtoupper($countrycode) ==
'FR') {
3162 if ($id == 1 &&
dol_strlen($newProfID) == 9) $newProfID = substr($newProfID, 0, 3).$separ.substr($newProfID, 3, 3).$separ.substr($newProfID, 6, 3);
3163 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);
3164 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);
3167 else $ret = $newProfID;
3185 function dol_print_phone($phone, $countrycode =
'', $cid = 0, $socid = 0, $addlink =
'', $separ =
" ", $withpicto =
'', $titlealt =
'', $adddivfloat = 0)
3187 global $conf, $user, $langs, $mysoc, $hookmanager;
3190 $phone = preg_replace(
"/[\s.-]/",
"", trim($phone));
3191 if (empty($phone)) {
3194 if (!empty($conf->global->MAIN_PHONE_SEPAR)) {
3195 $separ = $conf->global->MAIN_PHONE_SEPAR;
3197 if (empty($countrycode) && is_object($mysoc)) {
3198 $countrycode = $mysoc->country_code;
3202 if ($conf->dol_optimize_smallscreen) {
3207 if (strtoupper($countrycode) ==
"FR") {
3210 $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);
3212 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 2).$separ.substr($newphone, 5, 2);
3214 $newphone = substr($newphone, 0, 2).$separ.substr($newphone, 2, 3).$separ.substr($newphone, 5, 2).$separ.substr($newphone, 7, 2);
3216 $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);
3218 $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);
3220 $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);
3222 } elseif (strtoupper($countrycode) ==
"CA") {
3224 $newphone = ($separ !=
'' ?
'(' :
'').substr($newphone, 0, 3).($separ !=
'' ?
')' :
'').$separ.substr($newphone, 3, 3).($separ !=
'' ?
'-' :
'').substr($newphone, 6, 4);
3226 } elseif (strtoupper($countrycode) ==
"PT") {
3228 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3230 } elseif (strtoupper($countrycode) ==
"SR") {
3232 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3);
3234 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 4);
3236 } elseif (strtoupper($countrycode) ==
"DE") {
3238 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 4).$separ.substr($newphone, 11, 3);
3240 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 4).$separ.substr($newphone, 10, 3);
3242 } elseif (strtoupper($countrycode) ==
"ES") {
3244 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3246 } elseif (strtoupper($countrycode) ==
"BF") {
3248 $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);
3250 } elseif (strtoupper($countrycode) ==
"RO") {
3252 $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);
3254 } elseif (strtoupper($countrycode) ==
"TR") {
3256 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 4);
3258 } elseif (strtoupper($countrycode) ==
"US") {
3260 $newphone = substr($newphone, 0, 2).$separ.substr($newphone, 2, 3).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 4);
3262 } elseif (strtoupper($countrycode) ==
"MX") {
3264 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 2);
3266 $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);
3268 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 4);
3270 } elseif (strtoupper($countrycode) ==
"ML") {
3272 $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);
3274 } elseif (strtoupper($countrycode) ==
"TH") {
3276 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 3);
3278 $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);
3280 } elseif (strtoupper($countrycode) ==
"MU") {
3283 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 2).$separ.substr($newphone, 9, 2);
3285 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 4).$separ.substr($newphone, 8, 2).$separ.substr($newphone, 10, 2);
3287 } elseif (strtoupper($countrycode) ==
"ZA") {
3289 $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);
3291 } elseif (strtoupper($countrycode) ==
"SY") {
3293 $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);
3295 $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);
3297 } elseif (strtoupper($countrycode) ==
"AE") {
3299 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 2);
3301 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3303 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 4);
3305 } elseif (strtoupper($countrycode) ==
"DZ") {
3307 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 3).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3309 } elseif (strtoupper($countrycode) ==
"BE") {
3311 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 2).$separ.substr($newphone, 8, 3);
3313 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3315 } elseif (strtoupper($countrycode) ==
"PF") {
3317 $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);
3319 } elseif (strtoupper($countrycode) ==
"CO") {
3321 $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);
3323 } elseif (strtoupper($countrycode) ==
"JO") {
3325 $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);
3327 } elseif (strtoupper($countrycode) ==
"JM") {
3329 $newphone = substr($newphone, 0, 5).$separ.substr($newphone, 5, 3).$separ.substr($newphone, 8, 4);
3331 } elseif (strtoupper($countrycode) ==
"MG") {
3333 $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);
3335 } elseif (strtoupper($countrycode) ==
"GB") {
3337 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 4).$separ.substr($newphone, 7, 3).$separ.substr($newphone, 10, 3);
3339 } elseif (strtoupper($countrycode) ==
"CH") {
3341 $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);
3343 $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);
3345 } elseif (strtoupper($countrycode) ==
"TN") {
3347 $newphone = substr($newphone, 0, 4).$separ.substr($newphone, 4, 2).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3349 } elseif (strtoupper($countrycode) ==
"GF") {
3351 $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);
3353 } elseif (strtoupper($countrycode) ==
"GP") {
3355 $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);
3357 } elseif (strtoupper($countrycode) ==
"MQ") {
3359 $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);
3361 } elseif (strtoupper($countrycode) ==
"IT") {
3363 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 3).$separ.substr($newphone, 6, 3).$separ.substr($newphone, 9, 3);
3365 $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);
3367 } elseif (strtoupper($countrycode) ==
"AU") {
3371 $newphone = substr($newphone, 0, 3).$separ.substr($newphone, 3, 1).$separ.substr($newphone, 4, 4).$separ.substr($newphone, 8, 4);
3374 if (!empty($addlink)) {
3375 if ($conf->browser->layout ==
'phone' || (!empty($conf->clicktodial->enabled) && !empty($conf->global->CLICKTODIAL_USE_TEL_LINK_ON_PHONE_NUMBERS))) {
3376 $newphoneform = $newphone;
3377 $newphone =
'<a href="tel:'.$phone.
'"';
3378 $newphone .=
'>'.$newphoneform.
'</a>';
3379 } elseif (!empty($conf->clicktodial->enabled) && $addlink ==
'AC_TEL') {
3380 if (empty($user->clicktodial_loaded)) {
3381 $user->fetch_clicktodial();
3385 $urlmask =
'ErrorClickToDialModuleNotConfigured';
3386 if (!empty($conf->global->CLICKTODIAL_URL)) {
3387 $urlmask = $conf->global->CLICKTODIAL_URL;
3389 if (!empty($user->clicktodial_url)) {
3390 $urlmask = $user->clicktodial_url;
3393 $clicktodial_poste = (!empty($user->clicktodial_poste) ?urlencode($user->clicktodial_poste) :
'');
3394 $clicktodial_login = (!empty($user->clicktodial_login) ?urlencode($user->clicktodial_login) :
'');
3395 $clicktodial_password = (!empty($user->clicktodial_password) ?urlencode($user->clicktodial_password) :
'');
3397 $url = sprintf($urlmask, urlencode($phone), $clicktodial_poste, $clicktodial_login, $clicktodial_password);
3399 $substitarray = array(
'__PHONEFROM__'=>$clicktodial_poste,
3400 '__PHONETO__'=>urlencode($phone),
3401 '__LOGIN__'=>$clicktodial_login,
3402 '__PASS__'=>$clicktodial_password);
3404 $newphonesav = $newphone;
3405 if (empty($conf->global->CLICKTODIAL_DO_NOT_USE_AJAX_CALL)) {
3407 $newphone =
'<a href="'.$url.
'" class="cssforclicktodial"';
3408 $newphone .=
'>'.$newphonesav.
'</a>';
3411 $newphone =
'<a href="'.$url.
'"';
3412 if (!empty($conf->global->CLICKTODIAL_FORCENEWTARGET)) {
3413 $newphone .=
' target="_blank" rel="noopener noreferrer"';
3415 $newphone .=
'>'.$newphonesav.
'</a>';
3420 if (
isModEnabled(
'agenda') && $user->rights->agenda->myactions->create) {
3423 if ($addlink ==
'AC_FAX') {
3426 if (!empty($conf->global->AGENDA_ADDACTIONFORPHONE)) {
3427 $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>';
3430 $newphone =
'<div>'.$newphone.
' '.$link.
'</div>';
3435 if (empty($titlealt)) {
3436 $titlealt = ($withpicto ==
'fax' ? $langs->trans(
"Fax") : $langs->trans(
"Phone"));
3441 $parameters = array(
'countrycode' => $countrycode,
'cid' => $cid,
'socid' => $socid,
'titlealt' => $titlealt,
'picto' => $withpicto);
3442 $reshook = $hookmanager->executeHooks(
'printPhone', $parameters, $phone);
3443 $rep .= $hookmanager->resPrint;
3445 if (empty($reshook)) {
3448 if ($withpicto ==
'fax') {
3449 $picto =
'phoning_fax';
3450 } elseif ($withpicto ==
'phone') {
3452 } elseif ($withpicto ==
'mobile') {
3453 $picto =
'phoning_mobile';
3459 $rep .=
'<div class="nospan float" style="margin-right: 10px">';
3461 $rep .=
'<span style="margin-right: 10px;">';
3463 $rep .= ($withpicto ?
img_picto($titlealt,
'object_'.$picto.
'.png').
' ' :
'').$newphone;
3483 global $conf, $langs;
3494 if (file_exists(DOL_DOCUMENT_ROOT.
'/theme/common/flags/'.$countrycode.
'.png')) {
3495 $ret .=
' '.img_picto($countrycode.
' '.$langs->trans(
"AccordingToGeoIPDatabase"), DOL_URL_ROOT.
'/theme/common/flags/'.$countrycode.
'.png',
'', 1);
3497 $ret .=
' ('.$countrycode.
')';
3517 if (empty($_SERVER[
'HTTP_X_FORWARDED_FOR']) || preg_match(
'/[^0-9\.\:,\[\]]/', $_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
3518 if (empty($_SERVER[
'HTTP_CLIENT_IP']) || preg_match(
'/[^0-9\.\:,\[\]]/', $_SERVER[
'HTTP_CLIENT_IP'])) {
3519 if (empty($_SERVER[
"HTTP_CF_CONNECTING_IP"])) {
3520 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'' : $_SERVER[
'REMOTE_ADDR']);
3522 $ip = $_SERVER[
"HTTP_CF_CONNECTING_IP"];
3525 $ip = $_SERVER[
'HTTP_CLIENT_IP'];
3528 $ip = $_SERVER[
'HTTP_X_FORWARDED_FOR'];
3544 if (isset($_SERVER[
'HTTPS']) && $_SERVER[
'HTTPS'] ==
'on') {
3546 } 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') {
3564 if (!empty($conf->geoipmaxmind->enabled)) {
3568 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeoip.class.php';
3569 $geoip =
new DolGeoIP(
'country', $datafile);
3571 $countrycode = $geoip->getCountryCodeFromIP($ip);
3574 return $countrycode;
3586 global $conf, $langs, $user;
3590 if (!empty($conf->geoipmaxmind->enabled)) {
3595 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgeoip.class.php';
3596 $geoip =
new DolGeoIP(
'country', $datafile);
3597 $countrycode = $geoip->getCountryCodeFromIP($ip);
3598 $ret = $countrycode;
3617 global $conf, $user, $langs, $hookmanager;
3623 $parameters = array(
'element' => $element,
'id' => $id);
3624 $reshook = $hookmanager->executeHooks(
'printAddress', $parameters, $address);
3625 $out .= $hookmanager->resPrint;
3627 if (empty($reshook)) {
3628 if (empty($charfornl)) {
3629 $out .= nl2br($address);
3631 $out .= preg_replace(
'/[\r\n]+/', $charfornl, $address);
3635 $showgmap = $showomap = 0;
3636 if (($element ==
'thirdparty' || $element ==
'societe') && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS)) {
3639 if ($element ==
'contact' && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS_CONTACTS)) {
3642 if ($element ==
'member' && !empty($conf->google->enabled) && !empty($conf->global->GOOGLE_ENABLE_GMAPS_MEMBERS)) {
3645 if (($element ==
'thirdparty' || $element ==
'societe') && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS)) {
3648 if ($element ==
'contact' && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_CONTACTS)) {
3651 if ($element ==
'member' && !empty($conf->openstreetmap->enabled) && !empty($conf->global->OPENSTREETMAP_ENABLE_MAPS_MEMBERS)) {
3655 $url =
dol_buildpath(
'/google/gmaps.php?mode='.$element.
'&id='.$id, 1);
3656 $out .=
' <a href="'.$url.
'" target="_gmaps"><img id="'.$htmlid.
'" class="valigntextbottom" src="'.DOL_URL_ROOT.
'/theme/common/gmap.png"></a>';
3659 $url =
dol_buildpath(
'/openstreetmap/maps.php?mode='.$element.
'&id='.$id, 1);
3660 $out .=
' <a href="'.$url.
'" target="_gmaps"><img id="'.$htmlid.
'_openstreetmap" class="valigntextbottom" src="'.DOL_URL_ROOT.
'/theme/common/gmap.png"></a>';
3681 function isValidEmail($address, $acceptsupervisorkey = 0, $acceptuserkey = 0)
3683 if ($acceptsupervisorkey && $address ==
'__SUPERVISOREMAIL__') {
3686 if ($acceptuserkey && $address ==
'__USER_EMAIL__') {
3689 if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
3706 if (function_exists(
'idn_to_ascii') && function_exists(
'checkdnsrr')) {
3707 if (!checkdnsrr(idn_to_ascii($domain),
'MX')) {
3710 if (function_exists(
'getmxrr')) {
3713 getmxrr(idn_to_ascii($domain), $mxhosts, $weight);
3714 if (count($mxhosts) > 1) {
3717 if (count($mxhosts) == 1 && !empty($mxhosts[0])) {
3749 if (function_exists(
'mb_strlen')) {
3750 return mb_strlen($string, $stringencoding);
3752 return strlen($string);
3766 function dol_substr($string, $start, $length, $stringencoding =
'', $trunconbytes = 0)
3770 if (empty($stringencoding)) {
3771 $stringencoding = $langs->charset_output;
3775 if (empty($trunconbytes)) {
3776 if (function_exists(
'mb_substr')) {
3777 $ret = mb_substr($string, $start, $length, $stringencoding);
3779 $ret = substr($string, $start, $length);
3782 if (function_exists(
'mb_strcut')) {
3783 $ret = mb_strcut($string, $start, $length, $stringencoding);
3785 $ret = substr($string, $start, $length);
3805 function dol_trunc($string, $size = 40, $trunc =
'right', $stringencoding =
'UTF-8', $nodot = 0, $display = 0)
3809 if (empty($size) || !empty($conf->global->MAIN_DISABLE_TRUNC)) {
3813 if (empty($stringencoding)) {
3814 $stringencoding =
'UTF-8';
3817 if ($conf->dol_optimize_smallscreen == 1 && $display == 1) {
3818 $size = round($size / 3);
3822 if ($trunc ==
'right') {
3824 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
3826 return dol_substr($newstring, 0, $size, $stringencoding).($nodot ?
'' :
'…');
3831 } elseif ($trunc ==
'middle') {
3833 if (
dol_strlen($newstring, $stringencoding) > 2 &&
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
3834 $size1 = round($size / 2);
3835 $size2 = round($size / 2);
3836 return dol_substr($newstring, 0, $size1, $stringencoding).
'…'.
dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size2, $size2, $stringencoding);
3840 } elseif ($trunc ==
'left') {
3842 if (
dol_strlen($newstring, $stringencoding) > ($size + ($nodot ? 0 : 1))) {
3844 return '…'.dol_substr($newstring,
dol_strlen($newstring, $stringencoding) - $size, $size, $stringencoding);
3848 } elseif ($trunc ==
'wrap') {
3850 if (
dol_strlen($newstring, $stringencoding) > ($size + 1)) {
3856 return 'BadParam3CallingDolTrunc';
3880 function img_picto($titlealt, $picto, $moreatt =
'', $pictoisfullpath =
false, $srconly = 0, $notitle = 0, $alt =
'', $morecss =
'', $marginleftonlyshort = 2)
3882 global $conf, $langs;
3885 $url = DOL_URL_ROOT;
3886 $theme = isset($conf->theme) ? $conf->theme :
null;
3887 $path =
'theme/'.$theme;
3889 if ($pictoisfullpath) {
3891 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
3894 $fullpathpicto = $picto;
3896 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
3897 $morecss .= ($morecss ?
' ' :
'').$reg[1];
3898 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
3901 $pictowithouttext = preg_replace(
'/(\.png|\.gif|\.svg)$/',
'', $picto);
3902 $pictowithouttext = str_replace(
'object_',
'', $pictowithouttext);
3904 if (strpos($pictowithouttext,
'fontawesome_') !==
false || preg_match(
'/^fa-/', $pictowithouttext)) {
3906 $pictowithouttext = str_replace(
'fa-',
'', $pictowithouttext);
3907 $pictowithouttextarray = explode(
'_', $pictowithouttext);
3908 $marginleftonlyshort = 0;
3910 if (!empty($pictowithouttextarray[1])) {
3911 $fakey =
'fa-'.$pictowithouttextarray[1];
3912 $fa = empty($pictowithouttextarray[2]) ?
'fa' : $pictowithouttextarray[2];
3913 $facolor = empty($pictowithouttextarray[3]) ?
'' : $pictowithouttextarray[3];
3914 $fasize = empty($pictowithouttextarray[4]) ?
'' : $pictowithouttextarray[4];
3916 $fakey =
'fa-'.$pictowithouttext;
3926 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
3927 $morecss .= ($morecss ?
' ' :
'').$reg[1];
3928 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
3930 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
3931 $morestyle = $reg[1];
3932 $moreatt = str_replace(
'style="'.$reg[1].
'"',
'', $moreatt);
3934 $moreatt = trim($moreatt);
3936 $enabledisablehtml =
'<span class="'.$fa.
' '.$fakey.($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
3937 $enabledisablehtml .= ($morecss ?
' '.$morecss :
'').
'" style="'.($fasize ? (
'font-size: '.$fasize.
';') :
'').($facolor ? (
' color: '.$facolor.
';') :
'').($morestyle ?
' '.$morestyle :
'').
'"'.(($notitle || empty($titlealt)) ?
'' :
' title="'.
dol_escape_htmltag($titlealt).
'"').($moreatt ?
' '.$moreatt :
'').
'>';
3941 $enabledisablehtml .=
'</span>';
3943 return $enabledisablehtml;
3946 if (empty($srconly) && in_array($pictowithouttext, array(
3947 '1downarrow',
'1uparrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected',
3948 'accountancy',
'accounting_account',
'account',
'accountline',
'action',
'add',
'address',
'angle-double-down',
'angle-double-up',
'asset',
3949 'bank_account',
'barcode',
'bank',
'bell',
'bill',
'billa',
'billr',
'billd',
'bookmark',
'bom',
'briefcase-medical',
'bug',
'building',
3950 'card',
'calendarlist',
'calendar',
'calendarmonth',
'calendarweek',
'calendarday',
'calendarperuser',
'calendarpertype',
3951 'cash-register',
'category',
'chart',
'check',
'clock',
'close_title',
'cog',
'collab',
'company',
'contact',
'country',
'contract',
'conversation',
'cron',
'cubes',
3952 'currency',
'multicurrency',
3953 'delete',
'dolly',
'dollyrevert',
'donation',
'download',
'dynamicprice',
3954 'edit',
'ellipsis-h',
'email',
'entity',
'envelope',
'eraser',
'establishment',
'expensereport',
'external-link-alt',
'external-link-square-alt',
3955 'filter',
'file-code',
'file-export',
'file-import',
'file-upload',
'autofill',
'folder',
'folder-open',
'folder-plus',
3956 'generate',
'globe',
'globe-americas',
'graph',
'grip',
'grip_title',
'group',
3958 'images',
'incoterm',
'info',
'intervention',
'inventory',
'intracommreport',
'knowledgemanagement',
3959 'label',
'language',
'line',
'link',
'list',
'list-alt',
'listlight',
'loan',
'lot',
'long-arrow-alt-right',
3960 'margin',
'map-marker-alt',
'member',
'meeting',
'money-bill-alt',
'movement',
'mrp',
'note',
'next',
3961 'off',
'on',
'order',
3962 'paiment',
'paragraph',
'play',
'pdf',
'phone',
'phoning',
'phoning_mobile',
'phoning_fax',
'playdisabled',
'previous',
'poll',
'pos',
'printer',
'product',
'propal',
'puce',
3963 'stock',
'resize',
'service',
'stats',
'trip',
3964 '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',
3965 'github',
'google',
'jabber',
'skype',
'twitter',
'facebook',
'linkedin',
'instagram',
'snapchat',
'youtube',
'google-plus-g',
'whatsapp',
3966 'chevron-left',
'chevron-right',
'chevron-down',
'chevron-top',
'commercial',
'companies',
3967 'generic',
'home',
'hrm',
'members',
'products',
'invoicing',
3968 'partnership',
'payment',
'payment_vat',
'pencil-ruler',
'preview',
'project',
'projectpub',
'projecttask',
'question',
'refresh',
'region',
3969 'salary',
'shipment',
'state',
'supplier_invoice',
'supplier_invoicea',
'supplier_invoicer',
'supplier_invoiced',
3970 'technic',
'ticket',
3972 'recent',
'reception',
'recruitmentcandidature',
'recruitmentjobposition',
'resource',
'recurring',
3973 'shapes',
'square',
'stop-circle',
'supplier',
'supplier_proposal',
'supplier_order',
'supplier_invoice',
3974 'timespent',
'title_setup',
'title_accountancy',
'title_bank',
'title_hrm',
'title_agenda',
3975 'uncheck',
'user-cog',
'user-injured',
'user-md',
'vat',
'website',
'workstation',
'webhook',
'world',
'private',
3976 'conferenceorbooth',
'eventorganization',
3977 'stamp',
'signature'
3979 $fakey = $pictowithouttext;
3983 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'))) {
3986 if (in_array($pictowithouttext, array(
'black-tie',
'github',
'google',
'skype',
'twitter',
'facebook',
'linkedin',
'instagram',
'snapchat',
'stripe',
'stripe-s',
'youtube',
'google-plus-g',
'whatsapp'))) {
3990 $arrayconvpictotofa = array(
3991 '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',
3992 'bank_account'=>
'university',
3993 'bill'=>
'file-invoice-dollar',
'billa'=>
'file-excel',
'billr'=>
'file-invoice-dollar',
'billd'=>
'file-medical',
3994 'supplier_invoice'=>
'file-invoice-dollar',
'supplier_invoicea'=>
'file-excel',
'supplier_invoicer'=>
'file-invoice-dollar',
'supplier_invoiced'=>
'file-medical',
3996 'card'=>
'address-card',
'chart'=>
'chart-line',
'company'=>
'building',
'contact'=>
'address-book',
'contract'=>
'suitcase',
'collab'=>
'people-arrows',
'conversation'=>
'comments',
'country'=>
'globe-americas',
'cron'=>
'business-time',
3997 'donation'=>
'file-alt',
'dynamicprice'=>
'hand-holding-usd',
3998 'setup'=>
'cog',
'companies'=>
'building',
'products'=>
'cube',
'commercial'=>
'suitcase',
'invoicing'=>
'coins',
3999 'accounting'=>
'search-dollar',
'category'=>
'tag',
'dollyrevert'=>
'dolly',
4000 'generate'=>
'plus-square',
'hrm'=>
'user-tie',
'incoterm'=>
'truck-loading',
4001 'margin'=>
'calculator',
'members'=>
'user-friends',
'ticket'=>
'ticket-alt',
'globe'=>
'external-link-alt',
'lot'=>
'barcode',
4002 'email'=>
'at',
'establishment'=>
'building',
'edit'=>
'pencil-alt',
'entity'=>
'globe',
4003 'graph'=>
'chart-line',
'grip_title'=>
'arrows-alt',
'grip'=>
'arrows-alt',
'help'=>
'question-circle',
4004 'generic'=>
'file',
'holiday'=>
'umbrella-beach',
4005 'info'=>
'info-circle',
'inventory'=>
'boxes',
'intracommreport'=>
'globe-europe',
'knowledgemanagement'=>
'ticket-alt',
'label'=>
'layer-group',
'line'=>
'bars',
'loan'=>
'money-bill-alt',
4006 'member'=>
'user-alt',
'meeting'=>
'chalkboard-teacher',
'mrp'=>
'cubes',
'next'=>
'arrow-alt-circle-right',
4007 'trip'=>
'wallet',
'expensereport'=>
'wallet',
'group'=>
'users',
'movement'=>
'people-carry',
4008 'sign-out'=>
'sign-out-alt',
4009 'switch_off'=>
'toggle-off',
'switch_on'=>
'toggle-on',
'switch_on_red'=>
'toggle-on',
'check'=>
'check',
'bookmark'=>
'star',
4010 'bank'=>
'university',
'close_title'=>
'times',
'delete'=>
'trash',
'filter'=>
'filter',
4011 'list-alt'=>
'list-alt',
'calendarlist'=>
'bars',
'calendar'=>
'calendar-alt',
'calendarmonth'=>
'calendar-alt',
'calendarweek'=>
'calendar-week',
'calendarday'=>
'calendar-day',
'calendarperuser'=>
'table',
4012 'intervention'=>
'ambulance',
'invoice'=>
'file-invoice-dollar',
'currency'=>
'dollar-sign',
'multicurrency'=>
'dollar-sign',
'order'=>
'file-invoice',
4013 'error'=>
'exclamation-triangle',
'warning'=>
'exclamation-triangle',
4015 'playdisabled'=>
'play',
'pdf'=>
'file-pdf',
'poll'=>
'check-double',
'pos'=>
'cash-register',
'preview'=>
'binoculars',
'project'=>
'project-diagram',
'projectpub'=>
'project-diagram',
'projecttask'=>
'tasks',
'propal'=>
'file-signature',
4016 'partnership'=>
'handshake',
'payment'=>
'money-check-alt',
'payment_vat'=>
'money-check-alt',
'phoning'=>
'phone',
'phoning_mobile'=>
'mobile-alt',
'phoning_fax'=>
'fax',
'previous'=>
'arrow-alt-circle-left',
'printer'=>
'print',
'product'=>
'cube',
'puce'=>
'angle-right',
4017 'recent' =>
'question',
'reception'=>
'dolly',
'recruitmentjobposition'=>
'id-card-alt',
'recruitmentcandidature'=>
'id-badge',
4018 'resize'=>
'crop',
'supplier_order'=>
'dol-order_supplier',
'supplier_proposal'=>
'file-signature',
4019 'refresh'=>
'redo',
'region'=>
'map-marked',
'resource'=>
'laptop-house',
'recurring'=>
'history',
4020 'service'=>
'concierge-bell',
4021 'state'=>
'map-marked-alt',
'security'=>
'key',
'salary'=>
'wallet',
'shipment'=>
'dolly',
'stock'=>
'box-open',
'stats' =>
'chart-bar',
'split'=>
'code-branch',
'stripe'=>
'stripe-s',
4022 'supplier'=>
'building',
'technic'=>
'cogs',
4023 'timespent'=>
'clock',
'title_setup'=>
'tools',
'title_accountancy'=>
'money-check-alt',
'title_bank'=>
'university',
'title_hrm'=>
'umbrella-beach',
4024 'title_agenda'=>
'calendar-alt',
4025 'uncheck'=>
'times',
'uparrow'=>
'share',
'vat'=>
'money-check-alt',
'vcard'=>
'address-card',
4026 'jabber'=>
'comment-o',
4027 'website'=>
'globe-americas',
'workstation'=>
'pallet',
'webhook'=>
'bullseye',
'world'=>
'globe',
'private'=>
'user-lock',
4028 'conferenceorbooth'=>
'chalkboard-teacher',
'eventorganization'=>
'project-diagram'
4030 if ($pictowithouttext ==
'off') {
4031 $fakey =
'fa-square';
4033 } elseif ($pictowithouttext ==
'on') {
4034 $fakey =
'fa-check-square';
4036 } elseif ($pictowithouttext ==
'listlight') {
4037 $fakey =
'fa-download';
4038 $marginleftonlyshort = 1;
4039 } elseif ($pictowithouttext ==
'printer') {
4040 $fakey =
'fa-print';
4042 } elseif ($pictowithouttext ==
'note') {
4043 $fakey =
'fa-sticky-note';
4044 $marginleftonlyshort = 1;
4045 } elseif (in_array($pictowithouttext, array(
'1uparrow',
'1downarrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected'))) {
4046 $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');
4047 $fakey =
'fa-'.$convertarray[$pictowithouttext];
4048 if (preg_match(
'/selected/', $pictowithouttext)) {
4051 $marginleftonlyshort = 1;
4052 } elseif (!empty($arrayconvpictotofa[$pictowithouttext])) {
4053 $fakey =
'fa-'.$arrayconvpictotofa[$pictowithouttext];
4055 $fakey =
'fa-'.$pictowithouttext;
4058 if (in_array($pictowithouttext, array(
'dollyrevert',
'member',
'members',
'contract',
'group',
'resource',
'shipment'))) {
4059 $morecss .=
' em092';
4061 if (in_array($pictowithouttext, array(
'conferenceorbooth',
'collab',
'eventorganization',
'holiday',
'info',
'project',
'workstation'))) {
4062 $morecss .=
' em088';
4064 if (in_array($pictowithouttext, array(
'asset',
'intervention',
'payment',
'loan',
'partnership',
'stock',
'technic'))) {
4065 $morecss .=
' em080';
4069 $arrayconvpictotomarginleftonly = array(
4070 'bank',
'check',
'delete',
'generic',
'grip',
'grip_title',
'jabber',
4071 'grip_title',
'grip',
'listlight',
'note',
'on',
'off',
'playdisabled',
'printer',
'resize',
'sign-out',
'stats',
'switch_on',
'switch_on_red',
'switch_off',
4072 'uparrow',
'1uparrow',
'1downarrow',
'1leftarrow',
'1rightarrow',
'1uparrow_selected',
'1downarrow_selected',
'1leftarrow_selected',
'1rightarrow_selected'
4074 if (!isset($arrayconvpictotomarginleftonly[$pictowithouttext])) {
4075 $marginleftonlyshort = 0;
4079 $arrayconvpictotomorcess = array(
4080 'action'=>
'infobox-action',
'account'=>
'infobox-bank_account',
'accounting_account'=>
'infobox-bank_account',
'accountline'=>
'infobox-bank_account',
'accountancy'=>
'infobox-bank_account',
'asset'=>
'infobox-bank_account',
4081 'bank_account'=>
'infobox-bank_account',
4082 'bill'=>
'infobox-commande',
'billa'=>
'infobox-commande',
'billr'=>
'infobox-commande',
'billd'=>
'infobox-commande',
4083 'margin'=>
'infobox-bank_account',
'conferenceorbooth'=>
'infobox-project',
4084 'cash-register'=>
'infobox-bank_account',
'contract'=>
'infobox-contrat',
'check'=>
'font-status4',
'collab'=>
'infobox-action',
'conversation'=>
'infobox-contrat',
4085 'donation'=>
'infobox-commande',
'dolly'=>
'infobox-commande',
'dollyrevert'=>
'flip infobox-order_supplier',
4086 'ecm'=>
'infobox-action',
'eventorganization'=>
'infobox-project',
4087 'hrm'=>
'infobox-adherent',
'group'=>
'infobox-adherent',
'intervention'=>
'infobox-contrat',
4088 'incoterm'=>
'infobox-supplier_proposal',
4089 'currency'=>
'infobox-bank_account',
'multicurrency'=>
'infobox-bank_account',
4090 'members'=>
'infobox-adherent',
'member'=>
'infobox-adherent',
'money-bill-alt'=>
'infobox-bank_account',
4091 'order'=>
'infobox-commande',
4092 'user'=>
'infobox-adherent',
'users'=>
'infobox-adherent',
4093 'error'=>
'pictoerror',
'warning'=>
'pictowarning',
'switch_on'=>
'font-status4',
'switch_on_red'=>
'font-status8',
4094 'holiday'=>
'infobox-holiday',
'info'=>
'opacityhigh',
'invoice'=>
'infobox-commande',
4095 'knowledgemanagement'=>
'infobox-contrat rotate90',
'loan'=>
'infobox-bank_account',
4096 'payment'=>
'infobox-bank_account',
'payment_vat'=>
'infobox-bank_account',
'poll'=>
'infobox-adherent',
'pos'=>
'infobox-bank_account',
'project'=>
'infobox-project',
'projecttask'=>
'infobox-project',
4097 'propal'=>
'infobox-propal',
'private'=>
'infobox-project',
4098 'reception'=>
'flip',
'recruitmentjobposition'=>
'infobox-adherent',
'recruitmentcandidature'=>
'infobox-adherent',
4099 'resource'=>
'infobox-action',
4100 'salary'=>
'infobox-bank_account',
'shipment'=>
'infobox-commande',
'supplier_invoice'=>
'infobox-order_supplier',
'supplier_invoicea'=>
'infobox-order_supplier',
'supplier_invoiced'=>
'infobox-order_supplier',
4101 'supplier'=>
'infobox-order_supplier',
'supplier_order'=>
'infobox-order_supplier',
'supplier_proposal'=>
'infobox-supplier_proposal',
4102 'ticket'=>
'infobox-contrat',
'title_accountancy'=>
'infobox-bank_account',
'title_hrm'=>
'infobox-holiday',
'expensereport'=>
'infobox-expensereport',
'trip'=>
'infobox-expensereport',
'title_agenda'=>
'infobox-action',
4103 'vat'=>
'infobox-bank_account',
4105 'list-alt'=>
'imgforviewmode',
'calendar'=>
'imgforviewmode',
'calendarweek'=>
'imgforviewmode',
'calendarmonth'=>
'imgforviewmode',
'calendarday'=>
'imgforviewmode',
'calendarperuser'=>
'imgforviewmode'
4107 if (!empty($arrayconvpictotomorcess[$pictowithouttext])) {
4108 $morecss .= ($morecss ?
' ' :
'').$arrayconvpictotomorcess[$pictowithouttext];
4112 $arrayconvpictotocolor = array(
4113 'address'=>
'#6c6aa8',
'building'=>
'#6c6aa8',
'bom'=>
'#a69944',
4114 'cog'=>
'#999',
'companies'=>
'#6c6aa8',
'company'=>
'#6c6aa8',
'contact'=>
'#6c6aa8',
'cron'=>
'#555',
4115 'dynamicprice'=>
'#a69944',
4116 'edit'=>
'#444',
'note'=>
'#999',
'error'=>
'',
'help'=>
'#bbb',
'listlight'=>
'#999',
'language'=>
'#555',
4119 'map-marker-alt'=>
'#aaa',
'mrp'=>
'#a69944',
'product'=>
'#a69944',
'service'=>
'#a69944',
'inventory'=>
'#a69944',
'stock'=>
'#a69944',
'movement'=>
'#a69944',
4120 'other'=>
'#ddd',
'world'=>
'#986c6a',
4121 'partnership'=>
'#6c6aa8',
'playdisabled'=>
'#ccc',
'printer'=>
'#444',
'projectpub'=>
'#986c6a',
'reception'=>
'#a69944',
'resize'=>
'#444',
'rss'=>
'#cba',
4123 'security'=>
'#999',
'square'=>
'#888',
'stop-circle'=>
'#888',
'stats'=>
'#444',
'switch_off'=>
'#999',
'technic'=>
'#999',
'timespent'=>
'#555',
4124 'uncheck'=>
'#800',
'uparrow'=>
'#555',
'user-cog'=>
'#999',
'country'=>
'#aaa',
'globe-americas'=>
'#aaa',
'region'=>
'#aaa',
'state'=>
'#aaa',
4125 'website'=>
'#304',
'workstation'=>
'#a69944'
4127 if (isset($arrayconvpictotocolor[$pictowithouttext])) {
4128 $facolor = $arrayconvpictotocolor[$pictowithouttext];
4135 if (preg_match(
'/class="([^"]+)"/', $moreatt, $reg)) {
4136 $morecss .= ($morecss ?
' ' :
'').$reg[1];
4137 $moreatt = str_replace(
'class="'.$reg[1].
'"',
'', $moreatt);
4139 if (preg_match(
'/style="([^"]+)"/', $moreatt, $reg)) {
4140 $morestyle = $reg[1];
4141 $moreatt = str_replace(
'style="'.$reg[1].
'"',
'', $moreatt);
4143 $moreatt = trim($moreatt);
4145 $enabledisablehtml =
'<span class="'.$fa.
' '.$fakey.($marginleftonlyshort ? ($marginleftonlyshort == 1 ?
' marginleftonlyshort' :
' marginleftonly') :
'');
4146 $enabledisablehtml .= ($morecss ?
' '.$morecss :
'').
'" style="'.($fasize ? (
'font-size: '.$fasize.
';') :
'').($facolor ? (
' color: '.$facolor.
';') :
'').($morestyle ?
' '.$morestyle :
'').
'"'.(($notitle || empty($titlealt)) ?
'' :
' title="'.
dol_escape_htmltag($titlealt).
'"').($moreatt ?
' '.$moreatt :
'').
'>';
4150 $enabledisablehtml .=
'</span>';
4152 return $enabledisablehtml;
4155 if (!empty($conf->global->MAIN_OVERWRITE_THEME_PATH)) {
4156 $path = $conf->global->MAIN_OVERWRITE_THEME_PATH.
'/theme/'.$theme;
4157 } elseif (!empty($conf->global->MAIN_OVERWRITE_THEME_RES)) {
4158 $path = $conf->global->MAIN_OVERWRITE_THEME_RES.
'/theme/'.$conf->global->MAIN_OVERWRITE_THEME_RES;
4159 } elseif (!empty($conf->modules_parts[
'theme']) && array_key_exists($theme, $conf->modules_parts[
'theme'])) {
4160 $path = $theme.
'/theme/'.$theme;
4165 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $picto, $regs)) {
4171 if (!preg_match(
'/(\.png|\.gif|\.svg)$/i', $picto)) {
4176 foreach ($conf->file->dol_document_root as $type => $dirroot) {
4177 if ($type ==
'main') {
4181 if (file_exists($dirroot.
'/'.$path.
'/img/'.$picto)) {
4182 $url = DOL_URL_ROOT.$conf->file->dol_url_root[$type];
4188 $fullpathpicto = $url.
'/'.$path.
'/img/'.$picto;
4192 return $fullpathpicto;
4195 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 :
'').
'"').
'>';
4211 function img_object($titlealt, $picto, $moreatt =
'', $pictoisfullpath =
false, $srconly = 0, $notitle = 0)
4213 if (strpos($picto,
'^') === 0) {
4214 return img_picto($titlealt, str_replace(
'^',
'', $picto), $moreatt, $pictoisfullpath, $srconly, $notitle);
4216 return img_picto($titlealt,
'object_'.$picto, $moreatt, $pictoisfullpath, $srconly, $notitle);
4231 function img_weather($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $morecss =
'')
4235 if (is_numeric($picto)) {
4238 return '<i class="fa fa-weather-level'.$picto.
'"></i>';
4239 } elseif (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
4243 $path = DOL_URL_ROOT.
'/theme/'.$conf->theme.
'/img/weather/'.$picto;
4245 return img_picto($titlealt, $path, $moreatt, 1, 0, 0,
'', $morecss);
4259 function img_picto_common($titlealt, $picto, $moreatt =
'', $pictoisfullpath = 0, $notitle = 0)
4263 if (!preg_match(
'/(\.png|\.gif)$/i', $picto)) {
4267 if ($pictoisfullpath) {
4270 $path = DOL_URL_ROOT.
'/theme/common/'.$picto;
4272 if (!empty($conf->global->MAIN_MODULE_CAN_OVERWRITE_COMMONICONS)) {
4273 $themepath = DOL_DOCUMENT_ROOT.
'/theme/'.$conf->theme.
'/img/'.$picto;
4275 if (file_exists($themepath)) {
4281 return img_picto($titlealt, $path, $moreatt, 1, 0, $notitle);
4300 if (empty($titlealt) || $titlealt ==
'default') {
4301 if ($numaction ==
'-1' || $numaction ==
'ST_NO') {
4303 $titlealt = $langs->transnoentitiesnoconv(
'ChangeDoNotContact');
4304 } elseif ($numaction ==
'0' || $numaction ==
'ST_NEVER') {
4306 $titlealt = $langs->transnoentitiesnoconv(
'ChangeNeverContacted');
4307 } elseif ($numaction ==
'1' || $numaction ==
'ST_TODO') {
4309 $titlealt = $langs->transnoentitiesnoconv(
'ChangeToContact');
4310 } elseif ($numaction ==
'2' || $numaction ==
'ST_PEND') {
4312 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactInProcess');
4313 } elseif ($numaction ==
'3' || $numaction ==
'ST_DONE') {
4315 $titlealt = $langs->transnoentitiesnoconv(
'ChangeContactDone');
4317 $titlealt = $langs->transnoentitiesnoconv(
'ChangeStatus '.$numaction);
4321 if (!is_numeric($numaction)) {
4325 return img_picto($titlealt, !empty($picto) ? $picto :
'stcomm'.$numaction.
'.png');
4335 function img_pdf($titlealt =
'default', $size = 3)
4339 if ($titlealt ==
'default') {
4340 $titlealt = $langs->trans(
'Show');
4343 return img_picto($titlealt,
'pdf'.$size.
'.png');
4357 if ($titlealt ==
'default') {
4358 $titlealt = $langs->trans(
'Add');
4361 return img_picto($titlealt,
'edit_add.png', $other);
4374 if ($titlealt ==
'default') {
4375 $titlealt = $langs->trans(
'Remove');
4378 return img_picto($titlealt,
'edit_remove.png', $other);
4389 function img_edit($titlealt =
'default', $float = 0, $other =
'')
4393 if ($titlealt ==
'default') {
4394 $titlealt = $langs->trans(
'Modify');
4397 return img_picto($titlealt,
'edit.png', ($float ?
'style="float: '.($langs->tab_translate[
"DIRECTION"] ==
'rtl' ?
'left' :
'right').
'"' :
"").($other ?
' '.$other :
''));
4408 function img_view($titlealt =
'default', $float = 0, $other =
'class="valignmiddle"')
4412 if ($titlealt ==
'default') {
4413 $titlealt = $langs->trans(
'View');
4416 $moreatt = ($float ?
'style="float: right" ' :
'').$other;
4418 return img_picto($titlealt,
'view.png', $moreatt);
4429 function img_delete($titlealt =
'default', $other =
'class="pictodelete"', $morecss =
'')
4433 if ($titlealt ==
'default') {
4434 $titlealt = $langs->trans(
'Delete');
4437 return img_picto($titlealt,
'delete.png', $other,
false, 0, 0,
'', $morecss);
4450 if ($titlealt ==
"default") {
4451 $titlealt = $langs->trans(
"Print");
4453 return img_picto($titlealt,
'printer.png', $other);
4463 function img_split($titlealt =
'default', $other =
'class="pictosplit"')
4467 if ($titlealt ==
'default') {
4468 $titlealt = $langs->trans(
'Split');
4471 return img_picto($titlealt,
'split.png', $other);
4481 function img_help($usehelpcursor = 1, $usealttitle = 1)
4486 if (is_string($usealttitle)) {
4489 $usealttitle = $langs->trans(
'Info');
4493 return img_picto($usealttitle,
'info.png',
'style="vertical-align: middle;'.($usehelpcursor == 1 ?
' cursor: help' : ($usehelpcursor == 2 ?
' cursor: pointer' :
'')).
'"');
4506 if ($titlealt ==
'default') {
4507 $titlealt = $langs->trans(
'Informations');
4510 return img_picto($titlealt,
'info.png',
'style="vertical-align: middle;"');
4521 function img_warning($titlealt =
'default', $moreatt =
'', $morecss =
'pictowarning')
4525 if ($titlealt ==
'default') {
4526 $titlealt = $langs->trans(
'Warning');
4530 return img_picto($titlealt,
'warning.png',
'class="'.$morecss.
'"'.($moreatt ? ($moreatt ==
'1' ?
' style="float: right"' :
' '.$moreatt) :
''));
4543 if ($titlealt ==
'default') {
4544 $titlealt = $langs->trans(
'Error');
4547 return img_picto($titlealt,
'error.png');
4557 function img_next($titlealt =
'default', $moreatt =
'')
4561 if ($titlealt ==
'default') {
4562 $titlealt = $langs->trans(
'Next');
4566 return '<span class="fa fa-chevron-right paddingright paddingleft" title="'.dol_escape_htmltag($titlealt).
'"></span>';
4580 if ($titlealt ==
'default') {
4581 $titlealt = $langs->trans(
'Previous');
4585 return '<span class="fa fa-chevron-left paddingright paddingleft" title="'.dol_escape_htmltag($titlealt).
'"></span>';
4596 function img_down($titlealt =
'default', $selected = 0, $moreclass =
'')
4600 if ($titlealt ==
'default') {
4601 $titlealt = $langs->trans(
'Down');
4604 return img_picto($titlealt, ($selected ?
'1downarrow_selected.png' :
'1downarrow.png'),
'class="imgdown'.($moreclass ?
" ".$moreclass :
"").
'"');
4615 function img_up($titlealt =
'default', $selected = 0, $moreclass =
'')
4619 if ($titlealt ==
'default') {
4620 $titlealt = $langs->trans(
'Up');
4623 return img_picto($titlealt, ($selected ?
'1uparrow_selected.png' :
'1uparrow.png'),
'class="imgup'.($moreclass ?
" ".$moreclass :
"").
'"');
4634 function img_left($titlealt =
'default', $selected = 0, $moreatt =
'')
4638 if ($titlealt ==
'default') {
4639 $titlealt = $langs->trans(
'Left');
4642 return img_picto($titlealt, ($selected ?
'1leftarrow_selected.png' :
'1leftarrow.png'), $moreatt);
4653 function img_right($titlealt =
'default', $selected = 0, $moreatt =
'')
4657 if ($titlealt ==
'default') {
4658 $titlealt = $langs->trans(
'Right');
4661 return img_picto($titlealt, ($selected ?
'1rightarrow_selected.png' :
'1rightarrow.png'), $moreatt);
4675 if ($titlealt ==
'default') {
4676 $titlealt = $langs->trans(
'Active');
4680 return img_picto($titlealt,
'tick.png');
4695 if (is_null($morecss)) {
4699 if ($brand ==
'visa' || $brand ==
'Visa') {
4701 } elseif ($brand ==
'mastercard' || $brand ==
'MasterCard') {
4702 $brand =
'cc-mastercard';
4703 } elseif ($brand ==
'amex' || $brand ==
'American Express') {
4705 } elseif ($brand ==
'discover' || $brand ==
'Discover') {
4706 $brand =
'cc-discover';
4707 } elseif ($brand ==
'jcb' || $brand ==
'JCB') {
4709 } elseif ($brand ==
'diners' || $brand ==
'Diners club') {
4710 $brand =
'cc-diners-club';
4711 } elseif (!in_array($brand, array(
'cc-visa',
'cc-mastercard',
'cc-amex',
'cc-discover',
'cc-jcb',
'cc-diners-club'))) {
4712 $brand =
'credit-card';
4715 return '<span class="fa fa-'.$brand.
' fa-fw'.($morecss ?
' '.$morecss :
'').
'"></span>';
4726 function img_mime($file, $titlealt =
'', $morecss =
'')
4728 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
4734 if (empty($titlealt)) {
4735 $titlealt =
'Mime type: '.$mimetype;
4739 return '<i class="fa fa-'.$mimefa.
' paddingright'.($morecss ?
' '.$morecss :
'').
'"'.($titlealt ?
' title="'.$titlealt.
'"' :
'').
'></i>';
4752 global $conf, $langs;
4754 if ($titlealt ==
'default') {
4755 $titlealt = $langs->trans(
'Search');
4758 $img =
img_picto($titlealt,
'search.png', $other,
false, 1);
4760 $input =
'<input type="image" class="liste_titre" name="button_search" src="'.$img.
'" ';
4761 $input .=
'value="'.dol_escape_htmltag($titlealt).
'" title="'.
dol_escape_htmltag($titlealt).
'" >';
4775 global $conf, $langs;
4777 if ($titlealt ==
'default') {
4778 $titlealt = $langs->trans(
'Search');
4781 $img =
img_picto($titlealt,
'searchclear.png', $other,
false, 1);
4783 $input =
'<input type="image" class="liste_titre" name="button_removefilter" src="'.$img.
'" ';
4784 $input .=
'value="'.dol_escape_htmltag($titlealt).
'" title="'.
dol_escape_htmltag($titlealt).
'" >';
4800 function info_admin($text, $infoonimgalt = 0, $nodiv = 0, $admin =
'1', $morecss =
'hideonsmartphone', $textfordropdown =
'')
4802 global $conf, $langs;
4804 if ($infoonimgalt) {
4805 $result =
img_picto($text,
'info',
'class="'.($morecss ?
' '.$morecss :
'').
'"');
4807 if (empty($conf->use_javascript_ajax)) {
4808 $textfordropdown =
'';
4811 $class = (empty($admin) ?
'undefined' : ($admin ==
'1' ?
'info' : $admin));
4812 $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>');
4814 if ($textfordropdown) {
4815 $tmpresult =
'<span class="'.$class.
'text opacitymedium cursorpointer">'.$langs->trans($textfordropdown).
' '.
img_picto($langs->trans($textfordropdown),
'1downarrow').
'</span>';
4816 $tmpresult .=
'<script type="text/javascript">
4817 jQuery(document).ready(function() {
4818 jQuery(".'.$class.
'text").click(function() {
4819 console.log("toggle text");
4820 jQuery(".'.$class.
'").toggle();
4825 $result = $tmpresult.$result;
4846 global $conf, $langs, $argv;
4847 global $dolibarr_main_prod;
4854 require_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
4856 $langs->load(
"main");
4860 $langs->loadLangs(array(
'main',
'errors'));
4862 if ($_SERVER[
'DOCUMENT_ROOT']) {
4863 $out .= $langs->trans(
"DolibarrHasDetectedError").
".<br>\n";
4865 $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";
4867 $out .= $langs->trans(
"InformationToHelpDiagnose").
":<br>\n";
4869 $out .=
"<b>".$langs->trans(
"Date").
":</b> ".
dol_print_date(time(),
'dayhourlog').
"<br>\n";
4870 $out .=
"<b>".$langs->trans(
"Dolibarr").
":</b> ".DOL_VERSION.
" - https://www.dolibarr.org<br>\n";
4871 if (isset($conf->global->MAIN_FEATURES_LEVEL)) {
4872 $out .=
"<b>".$langs->trans(
"LevelOfFeature").
":</b> ".
getDolGlobalInt(
'MAIN_FEATURES_LEVEL').
"<br>\n";
4874 if (function_exists(
"phpversion")) {
4875 $out .=
"<b>".$langs->trans(
"PHP").
":</b> ".phpversion().
"<br>\n";
4877 $out .=
"<b>".$langs->trans(
"Server").
":</b> ".(isset($_SERVER[
"SERVER_SOFTWARE"]) ?
dol_htmlentities($_SERVER[
"SERVER_SOFTWARE"], ENT_COMPAT) :
'').
"<br>\n";
4878 if (function_exists(
"php_uname")) {
4879 $out .=
"<b>".$langs->trans(
"OS").
":</b> ".php_uname().
"<br>\n";
4881 $out .=
"<b>".$langs->trans(
"UserAgent").
":</b> ".(isset($_SERVER[
"HTTP_USER_AGENT"]) ?
dol_htmlentities($_SERVER[
"HTTP_USER_AGENT"], ENT_COMPAT) :
'').
"<br>\n";
4883 $out .=
"<b>".$langs->trans(
"RequestedUrl").
":</b> ".
dol_htmlentities($_SERVER[
"REQUEST_URI"], ENT_COMPAT).
"<br>\n";
4884 $out .=
"<b>".$langs->trans(
"Referer").
":</b> ".(isset($_SERVER[
"HTTP_REFERER"]) ?
dol_htmlentities($_SERVER[
"HTTP_REFERER"], ENT_COMPAT) :
'').
"<br>\n";
4885 $out .=
"<b>".$langs->trans(
"MenuManager").
":</b> ".(isset($conf->standard_menu) ?
dol_htmlentities($conf->standard_menu, ENT_COMPAT) :
'').
"<br>\n";
4887 $syslog .=
"url=".dol_escape_htmltag($_SERVER[
"REQUEST_URI"]);
4888 $syslog .=
", query_string=".dol_escape_htmltag($_SERVER[
"QUERY_STRING"]);
4891 $out .=
'> '.$langs->transnoentities(
"ErrorInternalErrorDetected").
":\n".$argv[0].
"\n";
4892 $syslog .=
"pid=".dol_getmypid();
4895 if (!empty($conf->modules)) {
4896 $out .=
"<b>".$langs->trans(
"Modules").
":</b> ".join(
', ', $conf->modules).
"<br>\n";
4899 if (is_object($db)) {
4900 if ($_SERVER[
'DOCUMENT_ROOT']) {
4901 $out .=
"<b>".$langs->trans(
"DatabaseTypeManager").
":</b> ".$db->type.
"<br>\n";
4902 $out .=
"<b>".$langs->trans(
"RequestLastAccessInError").
":</b> ".($db->lastqueryerror() ?
dol_escape_htmltag($db->lastqueryerror()) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
4903 $out .=
"<b>".$langs->trans(
"ReturnCodeLastAccessInError").
":</b> ".($db->lasterrno() ?
dol_escape_htmltag($db->lasterrno()) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
4904 $out .=
"<b>".$langs->trans(
"InformationLastAccessInError").
":</b> ".($db->lasterror() ?
dol_escape_htmltag($db->lasterror()) : $langs->trans(
"ErrorNoRequestInError")).
"<br>\n";
4909 $out .=
'> '.$langs->transnoentities(
"DatabaseTypeManager").
":\n".$db->type.
"\n";
4910 $out .=
'> '.$langs->transnoentities(
"RequestLastAccessInError").
":\n".($db->lastqueryerror() ? $db->lastqueryerror() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
4911 $out .=
'> '.$langs->transnoentities(
"ReturnCodeLastAccessInError").
":\n".($db->lasterrno() ? $db->lasterrno() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
4912 $out .=
'> '.$langs->transnoentities(
"InformationLastAccessInError").
":\n".($db->lasterror() ? $db->lasterror() : $langs->transnoentities(
"ErrorNoRequestInError")).
"\n";
4914 $syslog .=
", sql=".$db->lastquery();
4915 $syslog .=
", db_error=".$db->lasterror();
4918 if ($error || $errors) {
4919 $langs->load(
"errors");
4922 if (is_array($error) && is_array($errors)) {
4923 $errors = array_merge($error, $errors);
4924 } elseif (is_array($error)) {
4926 } elseif (is_array($errors)) {
4927 $errors = array_merge(array($error), $errors);
4929 $errors = array_merge(array($error));
4932 foreach ($errors as $msg) {
4936 if ($_SERVER[
'DOCUMENT_ROOT']) {
4940 $out .=
'> '.$langs->transnoentities(
"Message").
":\n".$msg.
"\n";
4942 $syslog .=
", msg=".$msg;
4945 if (empty($dolibarr_main_prod) && $_SERVER[
'DOCUMENT_ROOT'] && function_exists(
'xdebug_print_function_stack') && function_exists(
'xdebug_call_file')) {
4946 xdebug_print_function_stack();
4947 $out .=
'<b>XDebug informations:</b>'.
"<br>\n";
4948 $out .=
'File: '.xdebug_call_file().
"<br>\n";
4949 $out .=
'Line: '.xdebug_call_line().
"<br>\n";
4950 $out .=
'Function: '.xdebug_call_function().
"<br>\n";
4955 if (!headers_sent()) {
4956 http_response_code(500);
4959 if (empty($dolibarr_main_prod)) {
4962 if (empty($langs->defaultlang)) {
4963 $langs->setDefaultLang();
4965 $langs->loadLangs(array(
"main",
"errors"));
4967 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";
4968 print $langs->trans(
"DolibarrHasDetectedError").
'. ';
4969 print $langs->trans(
"YouCanSetOptionDolibarrMainProdToZero");
4970 define(
"MAIN_CORE_ERROR", 1);
4986 function dol_print_error_email($prefixcode, $errormessage =
'', $errormessages = array(), $morecss =
'error', $email =
'')
4988 global $langs, $conf;
4990 if (empty($email)) {
4991 $email = $conf->global->MAIN_INFO_SOCIETE_MAIL;
4994 $langs->load(
"errors");
4997 print
'<br><div class="center login_main_message"><div class="'.$morecss.
'">';
4998 print $langs->trans(
"ErrorContactEMail", $email, $prefixcode.dol_print_date($now,
'%Y%m%d%H%M%S'));
4999 if ($errormessage) {
5000 print
'<br><br>'.$errormessage;
5002 if (is_array($errormessages) && count($errormessages)) {
5003 foreach ($errormessages as $mesgtoshow) {
5004 print
'<br><br>'.$mesgtoshow;
5007 print
'</div></div>';
5026 function print_liste_field_titre($name, $file =
"", $field =
"", $begin =
"", $moreparam =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $tooltip =
"", $forcenowrapcolumntitle = 0)
5028 print
getTitleFieldOfList($name, 0, $file, $field, $begin, $moreparam, $moreattrib, $sortfield, $sortorder, $prefix, 0, $tooltip, $forcenowrapcolumntitle);
5049 function getTitleFieldOfList($name, $thead = 0, $file =
"", $field =
"", $begin =
"", $moreparam =
"", $moreattrib =
"", $sortfield =
"", $sortorder =
"", $prefix =
"", $disablesortlink = 0, $tooltip =
'', $forcenowrapcolumntitle = 0)
5051 global $conf, $langs,
$form;
5054 if ($moreattrib ==
'class="right"') {
5055 $prefix .=
'right ';
5058 $sortorder = strtoupper($sortorder);
5067 $tmpsortfield = explode(
',', $sortfield);
5068 $sortfield1 = trim($tmpsortfield[0]);
5069 $tmpfield = explode(
',', $field);
5070 $field1 = trim($tmpfield[0]);
5072 if (empty($conf->global->MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE) && empty($forcenowrapcolumntitle)) {
5073 $prefix =
'wrapcolumntitle '.$prefix;
5079 $liste_titre =
'liste_titre';
5080 if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace(
"/^[^\.]+\./",
"", $field1))) {
5081 $liste_titre =
'liste_titre_sel';
5084 $tagstart =
'<'.$tag.
' class="'.$prefix.$liste_titre.
'" '.$moreattrib;
5086 $tagstart .= ($name && empty($conf->global->MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE) && empty($forcenowrapcolumntitle) && !
dol_textishtml($name)) ?
' title="'.
dol_escape_htmltag($langs->trans($name)).
'"' :
'';
5089 if (empty($thead) && $field && empty($disablesortlink)) {
5090 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
5091 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
5092 $options = preg_replace(
'/&+/i',
'&', $options);
5093 if (!preg_match(
'/^&/', $options)) {
5094 $options =
'&'.$options;
5097 $sortordertouseinlink =
'';
5098 if ($field1 != $sortfield1) {
5099 if (preg_match(
'/^DESC/i', $sortorder)) {
5100 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
5102 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
5105 if (preg_match(
'/^ASC/i', $sortorder)) {
5106 $sortordertouseinlink .= str_repeat(
'desc,', count(explode(
',', $field)));
5108 $sortordertouseinlink .= str_repeat(
'asc,', count(explode(
',', $field)));
5111 $sortordertouseinlink = preg_replace(
'/,$/',
'', $sortordertouseinlink);
5112 $out .=
'<a class="reposition" href="'.$file.
'?sortfield='.$field.
'&sortorder='.$sortordertouseinlink.
'&begin='.$begin.$options.
'"';
5118 $tmptooltip = explode(
':', $tooltip);
5119 $out .=
$form->textwithpicto($langs->trans($name), $langs->trans($tmptooltip[0]), 1,
'help',
'', 0, 3, (empty($tmptooltip[1]) ?
'' :
'extra_'.str_replace(
'.',
'_', $field).
'_'.$tmptooltip[1]));
5121 $out .= $langs->trans($name);
5124 if (empty($thead) && $field && empty($disablesortlink)) {
5128 if (empty($thead) && $field) {
5129 $options = preg_replace(
'/sortfield=([a-zA-Z0-9,\s\.]+)/i',
'', (is_scalar($moreparam) ? $moreparam :
''));
5130 $options = preg_replace(
'/sortorder=([a-zA-Z0-9,\s\.]+)/i',
'', $options);
5131 $options = preg_replace(
'/&+/i',
'&', $options);
5132 if (!preg_match(
'/^&/', $options)) {
5133 $options =
'&'.$options;
5136 if (!$sortorder || $field1 != $sortfield1) {
5140 if (preg_match(
'/^DESC/', $sortorder)) {
5143 $sortimg .=
'<span class="nowrap">'.img_up(
"Z-A", 0,
'paddingright').
'</span>';
5145 if (preg_match(
'/^ASC/', $sortorder)) {
5148 $sortimg .=
'<span class="nowrap">'.img_down(
"A-Z", 0,
'paddingright').
'</span>';
5153 $tagend =
'</'.$tag.
'>';
5155 $out = $tagstart.$sortimg.$out.$tagend;
5170 dol_syslog(__FUNCTION__.
" is deprecated", LOG_WARNING);
5172 print
'<div class="titre">'.$title.
'</div>';
5204 function load_fiche_titre($titre, $morehtmlright =
'', $picto =
'generic', $pictoisfullpath = 0, $id =
'', $morecssontable =
'', $morehtmlcenter =
'')
5210 if ($picto ==
'setup') {
5215 $return .=
'<table '.($id ?
'id="'.$id.
'" ' :
'').
'class="centpercent notopnoleftnoright table-fiche-title'.($morecssontable ?
' '.$morecssontable :
'').
'">';
5216 $return .=
'<tr class="titre">';
5218 $return .=
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">'.img_picto(
'', $picto,
'class="valignmiddle widthpictotitle pictotitle"', $pictoisfullpath).
'</td>';
5220 $return .=
'<td class="nobordernopadding valignmiddle col-title">';
5221 $return .=
'<div class="titre inline-block">'.$titre.
'</div>';
5224 $return .=
'<td class="nobordernopadding center valignmiddle">'.$morehtmlcenter.
'</td>';
5227 $return .=
'<td class="nobordernopadding titre_right wordbreakimp right valignmiddle">'.$morehtmlright.
'</td>';
5229 $return .=
'</tr></table>'.
"\n";
5257 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 =
'')
5259 global $conf, $langs;
5262 $savtotalnboflines = $totalnboflines;
5263 $totalnboflines = abs((
int) $totalnboflines);
5265 if ($picto ==
'setup') {
5266 $picto =
'title_setup.png';
5268 if (($conf->browser->name ==
'ie') && $picto ==
'generic') {
5269 $picto =
'title.gif';
5272 $limit = $conf->liste_limit;
5274 if ($savlimit != 0 && (($num > $limit) || ($num == -1) || ($limit == 0))) {
5282 print
"<!-- Begin title -->\n";
5283 print
'<table class="centpercent notopnoleftnoright table-fiche-title'.($morecss ?
' '.$morecss :
'').
'"><tr>';
5287 if ($picto && $titre) {
5288 print
'<td class="nobordernopadding widthpictotitle valignmiddle col-picto">'.img_picto(
'', $picto,
'class="valignmiddle pictotitle widthpictotitle"', $pictoisfullpath).
'</td>';
5290 print
'<td class="nobordernopadding valignmiddle col-title">';
5291 print
'<div class="titre inline-block">'.$titre;
5292 if (!empty($titre) && $savtotalnboflines >= 0 && (string) $savtotalnboflines !=
'') {
5293 print
'<span class="opacitymedium colorblack paddingleft">('.$totalnboflines.
')</span>';
5295 print
'</div></td>';
5298 if ($morehtmlcenter) {
5299 print
'<td class="nobordernopadding center valignmiddle">'.$morehtmlcenter.
'</td>';
5303 print
'<td class="nobordernopadding valignmiddle right">';
5304 print
'<input type="hidden" name="pageplusoneold" value="'.((int) $page + 1).
'">';
5306 $options .=
"&sortfield=".urlencode($sortfield);
5309 $options .=
"&sortorder=".urlencode($sortorder);
5313 if ($savlimit != 0 && ($page > 0 || $num > $limit)) {
5314 if ($totalnboflines) {
5316 $maxnbofpage = (empty($conf->dol_optimize_smallscreen) ? 4 : 0);
5319 $nbpages = ceil($totalnboflines / $limit);
5323 $cpt = ($page - $maxnbofpage);
5329 if (empty($pagenavastextinput)) {
5330 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page=0'.$options.
'">1</a></li>';
5332 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
5333 } elseif ($cpt == 2) {
5334 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page=1'.$options.
'">2</a></li>';
5340 if ($pagenavastextinput) {
5341 if ($cpt == $page) {
5342 $pagelist .=
'<li class="pagination"><input type="text" class="width25 center pageplusone" name="pageplusone" value="'.($page + 1).
'"></li>';
5346 if ($cpt == $page) {
5347 $pagelist .=
'<li class="pagination"><span class="active">'.($page + 1).
'</span></li>';
5349 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page='.$cpt.$options.
'">'.($cpt + 1).
'</a></li>';
5353 }
while ($cpt < $nbpages && $cpt <= ($page + $maxnbofpage));
5355 if (empty($pagenavastextinput)) {
5356 if ($cpt < $nbpages) {
5357 if ($cpt < $nbpages - 2) {
5358 $pagelist .=
'<li class="pagination"><span class="inactive">...</span></li>';
5359 } elseif ($cpt == $nbpages - 2) {
5360 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page='.($nbpages - 2).$options.
'">'.($nbpages - 1).
'</a></li>';
5362 $pagelist .=
'<li class="pagination"><a href="'.$file.
'?page='.($nbpages - 1).$options.
'">'.$nbpages.
'</a></li>';
5366 $pagelist .=
'<li class="pagination paginationlastpage"><a href="'.$file.
'?page='.($nbpages - 1).$options.
'">'.$nbpages.
'</a></li>';
5369 $pagelist .=
'<li class="pagination"><span class="active">'.($page + 1).
"</li>";
5373 if ($savlimit || $morehtmlright || $morehtmlrightbeforearrow) {
5374 print_fleche_navigation($page, $file, $options, $nextpage, $pagelist, $morehtmlright, $savlimit, $totalnboflines, $hideselectlimit, $morehtmlrightbeforearrow);
5378 if ($pagenavastextinput) {
5384 print
'</tr></table>'.
"\n";
5385 print
"<!-- End title -->\n\n";
5403 function print_fleche_navigation($page, $file, $options =
'', $nextpage = 0, $betweenarrows =
'', $afterarrows =
'', $limit = -1, $totalnboflines = 0, $hideselectlimit = 0, $beforearrows =
'')
5405 global $conf, $langs;
5407 print
'<div class="pagination"><ul>';
5408 if ($beforearrows) {
5409 print
'<li class="paginationbeforearrows">';
5410 print $beforearrows;
5413 if ((
int) $limit > 0 && empty($hideselectlimit)) {
5414 $pagesizechoices =
'10:10,15:15,20:20,30:30,40:40,50:50,100:100,250:250,500:500,1000:1000';
5415 $pagesizechoices .=
',5000:5000,10000:10000,20000:20000';
5418 if (!empty($conf->global->MAIN_PAGESIZE_CHOICES)) {
5419 $pagesizechoices = $conf->global->MAIN_PAGESIZE_CHOICES;
5422 print
'<li class="pagination">';
5423 print
'<select class="flat selectlimit" name="limit" title="'.dol_escape_htmltag($langs->trans(
"MaxNbOfRecordPerPage")).
'">';
5424 $tmpchoice = explode(
',', $pagesizechoices);
5425 $tmpkey = $limit.
':'.$limit;
5426 if (!in_array($tmpkey, $tmpchoice)) {
5427 $tmpchoice[] = $tmpkey;
5429 $tmpkey = $conf->liste_limit.
':'.$conf->liste_limit;
5430 if (!in_array($tmpkey, $tmpchoice)) {
5431 $tmpchoice[] = $tmpkey;
5433 asort($tmpchoice, SORT_NUMERIC);
5434 foreach ($tmpchoice as $val) {
5436 $tmp = explode(
':', $val);
5439 if ($key !=
'' && $val !=
'') {
5440 if ((
int) $key == (
int) $limit) {
5441 $selected =
' selected="selected"';
5443 print
'<option name="'.$key.
'"'.$selected.
'>'.
dol_escape_htmltag($val).
'</option>'.
"\n";
5447 if ($conf->use_javascript_ajax) {
5448 print
'<!-- JS CODE TO ENABLE select limit to launch submit of page -->
5450 jQuery(document).ready(function () {
5451 jQuery(".selectlimit").change(function() {
5452 console.log("Change limit. Send submit");
5453 $(this).parents(\'form:first\').submit();
5462 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>';
5464 if ($betweenarrows) {
5465 print
'<!--<div class="betweenarrows nowraponall inline-block">-->';
5466 print $betweenarrows;
5467 print
'<!--</div>-->';
5469 if ($nextpage > 0) {
5470 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>';
5473 print
'<li class="paginationafterarrows">';
5477 print
'</ul></div>'.
"\n";
5492 function vatrate($rate, $addpercent =
false, $info_bits = 0, $usestarfornpr = 0, $html = 0)
5496 if (preg_match(
'/%/', $rate)) {
5497 $rate = str_replace(
'%',
'', $rate);
5501 if (preg_match(
'/\((.*)\)/', $rate, $reg)) {
5502 $morelabel =
' ('.$reg[1].
')';
5503 $rate = preg_replace(
'/\s*'.preg_quote($morelabel,
'/').
'/',
'', $rate);
5504 $morelabel =
' '.($html ?
'<span class="opacitymedium">' :
'').
'('.$reg[1].
')'.($html ?
'</span>' :
'');
5506 if (preg_match(
'/\*/', $rate)) {
5507 $rate = str_replace(
'*',
'', $rate);
5512 if (!preg_match(
'/\//', $rate)) {
5513 $ret =
price($rate, 0,
'', 0, 0).($addpercent ?
'%' :
'');
5516 $ret = $rate.($addpercent ?
'%' :
'');
5518 if (($info_bits & 1) && $usestarfornpr >= 0) {
5541 function price($amount,
$form = 0, $outlangs =
'', $trunc = 1, $rounding = -1, $forcerounding = -1, $currency_code =
'')
5543 global $langs, $conf;
5546 if (empty($amount)) {
5549 $amount = (is_numeric($amount) ? $amount : 0);
5550 if ($rounding < 0) {
5551 $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
5553 $nbdecimal = $rounding;
5555 if ($outlangs ===
'none') {
5565 if (!is_object($outlangs)) {
5569 if ($outlangs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
5570 $dec = $outlangs->transnoentitiesnoconv(
"SeparatorDecimal");
5572 if ($outlangs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
5573 $thousand = $outlangs->transnoentitiesnoconv(
"SeparatorThousand");
5575 if ($thousand ==
'None') {
5577 } elseif ($thousand ==
'Space') {
5584 $amount = str_replace(
',',
'.', $amount);
5586 $datas = explode(
'.', $amount);
5587 $decpart = isset($datas[1]) ? $datas[1] :
'';
5588 $decpart = preg_replace(
'/0+$/i',
'', $decpart);
5597 if ($trunc && $nbdecimal > $conf->global->MAIN_MAX_DECIMALS_SHOWN) {
5598 $nbdecimal = $conf->global->MAIN_MAX_DECIMALS_SHOWN;
5599 if (preg_match(
'/\.\.\./i', $conf->global->MAIN_MAX_DECIMALS_SHOWN)) {
5606 if ($forcerounding >= 0) {
5607 $nbdecimal = $forcerounding;
5611 $output = number_format($amount, $nbdecimal, $dec, $thousand);
5613 $output = preg_replace(
'/\s/',
' ', $output);
5614 $output = preg_replace(
'/\'/',
''', $output);
5617 $cursymbolbefore = $cursymbolafter =
'';
5618 if ($currency_code && is_object($outlangs)) {
5619 if ($currency_code ==
'auto') {
5620 $currency_code = $conf->currency;
5623 $listofcurrenciesbefore = array(
'AUD',
'CAD',
'CNY',
'COP',
'CLP',
'GBP',
'HKD',
'MXN',
'PEN',
'USD');
5624 $listoflanguagesbefore = array(
'nl_NL');
5625 if (in_array($currency_code, $listofcurrenciesbefore) || in_array($outlangs->defaultlang, $listoflanguagesbefore)) {
5626 $cursymbolbefore .= $outlangs->getCurrencySymbol($currency_code);
5628 $tmpcur = $outlangs->getCurrencySymbol($currency_code);
5629 $cursymbolafter .= ($tmpcur == $currency_code ?
' '.$tmpcur : $tmpcur);
5632 $output = $cursymbolbefore.$output.$end.($cursymbolafter ?
' ' :
'').$cursymbolafter;
5663 global $langs, $conf;
5670 if (is_null($langs)) {
5674 if ($langs->transnoentitiesnoconv(
"SeparatorDecimal") !=
"SeparatorDecimal") {
5675 $dec = $langs->transnoentitiesnoconv(
"SeparatorDecimal");
5677 if ($langs->transnoentitiesnoconv(
"SeparatorThousand") !=
"SeparatorThousand") {
5678 $thousand = $langs->transnoentitiesnoconv(
"SeparatorThousand");
5681 if ($thousand ==
'None') {
5683 } elseif ($thousand ==
'Space') {
5691 if (!is_numeric($amount)) {
5692 $amount = preg_replace(
'/[a-zA-Z\/\\\*\(\)<>\_]/',
'', $amount);
5695 if ($option == 2 && $thousand ==
'.' && preg_match(
'/\.(\d\d\d)$/', (
string) $amount)) {
5696 $amount = str_replace($thousand,
'', $amount);
5702 if (is_numeric($amount)) {
5704 $temps = sprintf(
"%0.10F", $amount - intval($amount));
5705 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
5707 $amount = number_format($amount, $nbofdec, $dec, $thousand);
5712 if ($thousand !=
',' && $thousand !=
'.') {
5713 $amount = str_replace(
',',
'.', $amount);
5716 $amount = str_replace(
' ',
'', $amount);
5717 $amount = str_replace($thousand,
'', $amount);
5718 $amount = str_replace($dec,
'.', $amount);
5720 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
5726 $nbofdectoround =
'';
5727 if ($rounding ==
'MU') {
5728 $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_UNIT;
5729 } elseif ($rounding ==
'MT') {
5730 $nbofdectoround = $conf->global->MAIN_MAX_DECIMALS_TOT;
5731 } elseif ($rounding ==
'MS') {
5732 $nbofdectoround = isset($conf->global->MAIN_MAX_DECIMALS_STOCK) ? $conf->global->MAIN_MAX_DECIMALS_STOCK : 5;
5733 } elseif ($rounding ==
'CU') {
5734 $nbofdectoround = max($conf->global->MAIN_MAX_DECIMALS_UNIT, 8);
5735 } elseif ($rounding ==
'CT') {
5736 $nbofdectoround = max($conf->global->MAIN_MAX_DECIMALS_TOT, 8);
5737 } elseif (is_numeric($rounding)) {
5738 $nbofdectoround = (int) $rounding;
5743 $amount = round(is_string($amount) ? (
float) $amount : $amount, $nbofdectoround);
5745 return 'ErrorBadParameterProvidedToFunction';
5751 if (is_numeric($amount)) {
5753 $temps = sprintf(
"%0.10F", $amount - intval($amount));
5754 $temps = preg_replace(
'/([\.1-9])0+$/',
'\\1', $temps);
5756 $amount = number_format($amount, min($nbofdec, $nbofdectoround), $dec, $thousand);
5762 if ($thousand !=
',' && $thousand !=
'.') {
5763 $amount = str_replace(
',',
'.', $amount);
5766 $amount = str_replace(
' ',
'', $amount);
5767 $amount = str_replace($thousand,
'', $amount);
5768 $amount = str_replace($dec,
'.', $amount);
5770 $amount = preg_replace(
'/[^0-9\-\.]/',
'', $amount);
5788 function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round = -1, $forceunitoutput =
'no', $use_short_label = 0)
5790 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
5792 if (($forceunitoutput ==
'no' && $dimension < 1 / 10000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -6)) {
5793 $dimension = $dimension * 1000000;
5795 } elseif (($forceunitoutput ==
'no' && $dimension < 1 / 10 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == -3)) {
5796 $dimension = $dimension * 1000;
5798 } elseif (($forceunitoutput ==
'no' && $dimension > 100000000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 6)) {
5799 $dimension = $dimension / 1000000;
5801 } elseif (($forceunitoutput ==
'no' && $dimension > 100000 && $unit < 90) || (is_numeric($forceunitoutput) && $forceunitoutput == 3)) {
5802 $dimension = $dimension / 1000;
5818 $ret =
price($dimension, 0, $outputlangs, 0, 0, $round);
5819 $ret .=
' '.measuringUnitString(0, $type, $unit, $use_short_label, $outputlangs);
5837 function get_localtax($vatrate, $local, $thirdparty_buyer =
"", $thirdparty_seller =
"", $vatnpr = 0)
5839 global $db, $conf, $mysoc;
5841 if (empty($thirdparty_seller) || !is_object($thirdparty_seller)) {
5842 $thirdparty_seller = $mysoc;
5845 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);
5847 $vatratecleaned = $vatrate;
5849 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
5850 $vatratecleaned = trim($reg[1]);
5851 $vatratecode = $reg[2];
5860 if ($mysoc->country_code ==
'ES') {
5862 if (!$mysoc->localtax1_assuj || (
string) $vatratecleaned ==
"0") {
5865 if ($thirdparty_seller->id == $mysoc->id) {
5866 if (!$thirdparty_buyer->localtax1_assuj) {
5870 if (!$thirdparty_seller->localtax1_assuj) {
5878 if (!$mysoc->localtax2_assuj) {
5881 if ($thirdparty_seller->id == $mysoc->id) {
5882 if (!$thirdparty_buyer->localtax2_assuj) {
5886 if (!$thirdparty_seller->localtax2_assuj) {
5892 if ($local == 1 && !$thirdparty_seller->localtax1_assuj) {
5895 if ($local == 2 && !$thirdparty_seller->localtax2_assuj) {
5901 if (in_array($mysoc->country_code, array(
'ES'))) {
5902 $conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY = 1;
5906 if (!empty($conf->global->MAIN_GET_LOCALTAXES_VALUES_FROM_THIRDPARTY)) {
5908 if ($thirdparty_seller != $mysoc) {
5910 return $thirdparty_seller->localtax1_value;
5914 return $conf->global->MAIN_INFO_VALUE_LOCALTAX1;
5919 if ($thirdparty_seller != $mysoc) {
5922 return $thirdparty_seller->localtax2_value;
5925 if (in_array($mysoc->country_code, array(
'ES'))) {
5926 return $thirdparty_buyer->localtax2_value;
5928 return $conf->global->MAIN_INFO_VALUE_LOCALTAX2;
5935 $sql =
"SELECT t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
5936 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
5937 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($thirdparty_seller->country_code).
"'";
5938 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
5939 if (!empty($vatratecode)) {
5940 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
5942 $sql .=
" AND t.recuperableonly = '".$db->escape($vatnpr).
"'";
5945 $resql = $db->query($sql);
5948 $obj = $db->fetch_object(
$resql);
5951 return $obj->localtax1;
5952 } elseif ($local == 2) {
5953 return $obj->localtax2;
5974 $valors = explode(
":", $tax);
5976 if (count($valors) > 1) {
5993 $sql =
" SELECT t.localtax".$local.
" as localtax";
5994 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t INNER JOIN ".MAIN_DB_PREFIX.
"c_country as c ON c.rowid = t.fk_pays";
5995 $sql .=
" WHERE c.code = '".$db->escape($mysoc->country_code).
"' AND t.active = 1 AND t.taux = (";
5996 $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";
5997 $sql .=
" WHERE c.code = '".$db->escape($mysoc->country_code).
"' AND tt.active = 1)";
5998 $sql .=
" AND t.localtax".$local.
"_type <> '0'";
5999 $sql .=
" ORDER BY t.rowid DESC";
6001 $resql = $db->query($sql);
6003 $obj = $db->fetch_object(
$resql);
6004 return $obj->localtax;
6024 function getTaxesFromId($vatrate, $buyer =
null, $seller =
null, $firstparamisid = 1)
6028 dol_syslog(
"getTaxesFromId vat id or rate = ".$vatrate);
6031 $sql =
"SELECT t.rowid, t.code, t.taux as rate, t.recuperableonly as npr, t.accountancy_code_sell, t.accountancy_code_buy,";
6032 $sql .=
" t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type";
6033 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t";
6034 if ($firstparamisid) {
6035 $sql .=
" WHERE t.rowid = ".(int) $vatrate;
6037 $vatratecleaned = $vatrate;
6040 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
6041 $vatratecleaned = $reg[1];
6042 $vatratecode = $reg[2];
6045 $sql .=
", ".MAIN_DB_PREFIX.
"c_country as c";
6048 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($seller->country_code).
"'";
6049 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
6051 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
6055 $resql = $db->query($sql);
6057 $obj = $db->fetch_object(
$resql);
6060 'rowid'=>$obj->rowid,
6063 'localtax1'=>$obj->localtax1,
6064 'localtax1_type'=>$obj->localtax1_type,
6065 'localtax2'=>$obj->localtax2,
6066 'localtax2_type'=>$obj->localtax2_type,
6068 'accountancy_code_sell'=>$obj->accountancy_code_sell,
6069 'accountancy_code_buy'=>$obj->accountancy_code_buy
6101 dol_syslog(
"getLocalTaxesFromRate vatrate=".$vatrate.
" local=".$local);
6104 $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";
6105 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t";
6106 if ($firstparamisid) {
6107 $sql .=
" WHERE t.rowid = ".(int) $vatrate;
6109 $vatratecleaned = $vatrate;
6112 if (preg_match(
'/^(.*)\s*\((.*)\)$/', $vatrate, $reg)) {
6113 $vatratecleaned = $reg[1];
6114 $vatratecode = $reg[2];
6117 $sql .=
", ".MAIN_DB_PREFIX.
"c_country as c";
6118 if (!empty($mysoc) && $mysoc->country_code ==
'ES') {
6119 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($buyer->country_code).
"'";
6121 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape(empty($seller->country_code) ? $mysoc->country_code : $seller->country_code).
"'";
6123 $sql .=
" AND t.taux = ".((float) $vatratecleaned).
" AND t.active = 1";
6125 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
6129 $resql = $db->query($sql);
6131 $obj = $db->fetch_object(
$resql);
6134 $vateratestring = $obj->rate.($obj->code ?
' ('.$obj->code.
')' :
'');
6137 return array($obj->localtax1_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
6138 } elseif ($local == 2) {
6139 return array($obj->localtax2_type,
get_localtax($vateratestring, $local, $buyer, $seller), $obj->accountancy_code_sell, $obj->accountancy_code_buy);
6141 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);
6161 global $db, $conf, $mysoc;
6163 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
6171 $result = $product->fetch($idprod);
6173 if ($mysoc->country_code == $thirdpartytouse->country_code) {
6174 if ($idprodfournprice > 0) {
6175 $product->get_buyprice($idprodfournprice, 0, 0, 0);
6176 $ret = $product->vatrate_supplier;
6177 if ($product->default_vat_code) {
6178 $ret .=
' ('.$product->default_vat_code.
')';
6181 $ret = $product->tva_tx;
6182 if ($product->default_vat_code) {
6183 $ret .=
' ('.$product->default_vat_code.
')';
6194 if (empty($conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS)) {
6196 $sql =
"SELECT t.taux as vat_rate, t.code as default_vat_code";
6197 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
6198 $sql .=
" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$db->escape($thirdpartytouse->country_code).
"'";
6199 $sql .=
" ORDER BY t.taux DESC, t.code ASC, t.recuperableonly ASC";
6200 $sql .= $db->plimit(1);
6202 $resql = $db->query($sql);
6204 $obj = $db->fetch_object(
$resql);
6206 $ret = $obj->vat_rate;
6207 if ($obj->default_vat_code) {
6208 $ret .=
' ('.$obj->default_vat_code.
')';
6216 $ret = $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS;
6220 dol_syslog(
"get_product_vat_for_country: ret=".$ret);
6237 if (!class_exists(
'Product')) {
6238 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
6247 $result = $product->fetch($idprod);
6249 if ($mysoc->country_code == $thirdpartytouse->country_code) {
6263 $sql =
"SELECT taux as vat_rate, localtax1, localtax2";
6264 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
6265 $sql .=
" WHERE t.active=1 AND t.fk_pays = c.rowid AND c.code='".$db->escape($thirdpartytouse->country_code).
"'";
6266 $sql .=
" ORDER BY t.taux DESC, t.recuperableonly ASC";
6267 $sql .= $db->plimit(1);
6269 $resql = $db->query($sql);
6271 $obj = $db->fetch_object(
$resql);
6274 $ret = $obj->localtax1;
6275 } elseif ($local == 2) {
6276 $ret = $obj->localtax2;
6284 dol_syslog(
"get_product_localtax_for_country: ret=".$ret);
6308 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
6311 $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;
6313 $seller_country_code = $thirdparty_seller->country_code;
6314 $seller_in_cee =
isInEEC($thirdparty_seller);
6316 $buyer_country_code = $thirdparty_buyer->country_code;
6317 $buyer_in_cee =
isInEEC($thirdparty_buyer);
6319 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 :
''));
6323 if (!empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC)) {
6324 if ($seller_in_cee && $buyer_in_cee) {
6325 $isacompany = $thirdparty_buyer->
isACompany();
6326 if ($isacompany && !empty($conf->global->MAIN_USE_VAT_COMPANIES_IN_EEC_WITH_INVALID_VAT_ID_ARE_INDIVIDUAL)) {
6327 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
6341 if (!$seller_use_vat) {
6349 if (($seller_country_code == $buyer_country_code)
6350 || (in_array($seller_country_code, array(
'FR',
'MC')) && in_array($buyer_country_code, array(
'FR',
'MC')))) {
6360 if (($seller_in_cee && $buyer_in_cee)) {
6361 $isacompany = $thirdparty_buyer->
isACompany();
6362 if ($isacompany && !empty($conf->global->MAIN_USE_VAT_COMPANIES_IN_EEC_WITH_INVALID_VAT_ID_ARE_INDIVIDUAL)) {
6363 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
6380 if (!empty($conf->global->MAIN_USE_VAT_OF_PRODUCT_FOR_INDIVIDUAL_CUSTOMER_OUT_OF_EEC) && empty($buyer_in_cee)) {
6381 $isacompany = $thirdparty_buyer->
isACompany();
6409 if ($idprodfournprice > 0) {
6410 if (!class_exists(
'ProductFournisseur')) {
6411 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
6414 $prodprice->fetch_product_fournisseur_price($idprodfournprice);
6415 return $prodprice->fourn_tva_npr;
6416 } elseif ($idprod > 0) {
6417 if (!class_exists(
'Product')) {
6418 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
6421 $prod->fetch($idprod);
6422 return $prod->tva_npr;
6445 if (!is_object($thirdparty_seller)) {
6448 if (!is_object($thirdparty_buyer)) {
6453 if ($mysoc->country_code ==
'ES') {
6454 if (is_numeric($thirdparty_buyer->localtax1_assuj) && !$thirdparty_buyer->localtax1_assuj) {
6459 if (is_numeric($thirdparty_seller->localtax1_assuj) && !$thirdparty_seller->localtax1_assuj) {
6462 if (!is_numeric($thirdparty_seller->localtax1_assuj) && $thirdparty_seller->localtax1_assuj ==
'localtax1off') {
6466 } elseif ($local == 2) {
6468 if (is_numeric($thirdparty_seller->localtax2_assuj) && !$thirdparty_seller->localtax2_assuj) {
6471 if (!is_numeric($thirdparty_seller->localtax2_assuj) && $thirdparty_seller->localtax2_assuj ==
'localtax2off') {
6476 if ($thirdparty_seller->country_code == $thirdparty_buyer->country_code) {
6491 function yn($yesno, $case = 1, $color = 0)
6495 $result =
'unknown';
6497 if ($yesno == 1 || strtolower($yesno) ==
'yes' || strtolower($yesno) ==
'true') {
6498 $result = $langs->trans(
'yes');
6499 if ($case == 1 || $case == 3) {
6500 $result = $langs->trans(
"Yes");
6503 $result =
'<input type="checkbox" value="1" checked disabled>';
6506 $result =
'<input type="checkbox" value="1" checked disabled> '.$result;
6510 } elseif ($yesno == 0 || strtolower($yesno) ==
'no' || strtolower($yesno) ==
'false') {
6511 $result = $langs->trans(
"no");
6512 if ($case == 1 || $case == 3) {
6513 $result = $langs->trans(
"No");
6516 $result =
'<input type="checkbox" value="0" disabled>';
6519 $result =
'<input type="checkbox" value="0" disabled> '.$result;
6525 $classname =
'error';
6529 return '<span class="'.$classname.
'">'.$result.
'</span>';
6549 function get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart =
'')
6553 if (empty($modulepart) && !empty($object->module)) {
6554 $modulepart = $object->module;
6559 $arrayforoldpath = array(
'cheque',
'category',
'holiday',
'supplier_invoice',
'invoice_supplier',
'mailing',
'supplier_payment');
6560 if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
6561 $arrayforoldpath[] =
'product';
6563 if (!empty($level) && in_array($modulepart, $arrayforoldpath)) {
6565 if (empty($alpha)) {
6566 $num = preg_replace(
'/([^0-9])/i',
'', $num);
6568 $num = preg_replace(
'/^.*\-/i',
'', $num);
6570 $num = substr(
"000".$num, -$level);
6572 $path = substr($num, 0, 1);
6575 $path = substr($num, 1, 1).
'/'.substr($num, 0, 1);
6578 $path = substr($num, 2, 1).
'/'.substr($num, 1, 1).
'/'.substr($num, 0, 1);
6588 if (empty($withoutslash) && !empty($path)) {
6607 dol_syslog(
"functions.lib::dol_mkdir: dir=".$dir, LOG_INFO);
6610 if (@is_dir($dir_osencoded)) {
6618 if (!empty($dataroot)) {
6620 $dir = str_replace($dataroot.
'/',
'', $dir);
6621 $ccdir = $dataroot.
'/';
6624 $cdir = explode(
"/", $dir);
6625 $num = count($cdir);
6626 for ($i = 0; $i < $num; $i++) {
6628 $ccdir .=
'/'.$cdir[$i];
6630 $ccdir .= $cdir[$i];
6632 if (preg_match(
"/^.:$/", $ccdir, $regs)) {
6640 if (!@is_dir($ccdir_osencoded)) {
6641 dol_syslog(
"functions.lib::dol_mkdir: Directory '".$ccdir.
"' does not exists or is outside open_basedir PHP setting.", LOG_DEBUG);
6644 $dirmaskdec = octdec((
string) $newmask);
6645 if (empty($newmask)) {
6646 $dirmaskdec = empty($conf->global->MAIN_UMASK) ? octdec(
'0755') : octdec($conf->global->MAIN_UMASK);
6648 $dirmaskdec |= octdec(
'0111');
6649 if (!@mkdir($ccdir_osencoded, $dirmaskdec)) {
6651 dol_syslog(
"functions.lib::dol_mkdir: Fails to create directory '".$ccdir.
"' or directory already exists.", LOG_WARNING);
6654 dol_syslog(
"functions.lib::dol_mkdir: Directory '".$ccdir.
"' created", LOG_DEBUG);
6663 return ($nberr ? -$nberr : $nbcreated);
6674 return '<span class="fieldrequired">*</span>';
6694 function dol_string_nohtmltag($stringtoclean, $removelinefeed = 1, $pagecodeto =
'UTF-8', $strip_tags = 0, $removedoublespaces = 1)
6696 if ($removelinefeed == 2) {
6697 $stringtoclean = preg_replace(
'/<br[^>]*>(\n|\r)+/ims',
'<br>', $stringtoclean);
6699 $temp = preg_replace(
'/<br[^>]*>/i',
"\n", $stringtoclean);
6704 $temp = str_replace(
'< ',
'__ltspace__', $temp);
6707 $temp = strip_tags($temp);
6710 $pattern =
"/<[^<>]+>/";
6717 $tempbis = str_replace(
'<>',
'', $temp);
6718 $tempbis = preg_replace($pattern,
'', $tempbis);
6720 }
while ($tempbis != $temp);
6725 $temp = preg_replace(
'/<+([a-z]+)/i',
'\1', $temp);
6731 if ($removelinefeed == 1) {
6732 $temp = str_replace(array(
"\r\n",
"\r",
"\n"),
" ", $temp);
6736 if ($removedoublespaces) {
6737 while (strpos($temp,
" ")) {
6738 $temp = str_replace(
" ",
" ", $temp);
6742 $temp = str_replace(
'__ltspace__',
'< ', $temp);
6762 $allowed_tags = array(
6763 "html",
"head",
"meta",
"body",
"article",
"a",
"abbr",
"b",
"blockquote",
"br",
"cite",
"div",
"dl",
"dd",
"dt",
"em",
"font",
"img",
"ins",
"hr",
"i",
"li",
"link",
6764 "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",
6768 $allowed_tags[] =
"iframe";
6771 $allowed_tags_string = join(
"><", $allowed_tags);
6772 $allowed_tags_string =
'<'.$allowed_tags_string.
'>';
6774 $stringtoclean = str_replace(
'<!DOCTYPE html>',
'__!DOCTYPE_HTML__', $stringtoclean);
6779 $stringtoclean = preg_replace(
'/<!--([^>]*)-->/',
'<comment>\1</comment>', $stringtoclean);
6781 $stringtoclean = preg_replace(
'/:/i',
':', $stringtoclean);
6782 $stringtoclean = preg_replace(
'/:|�+58|:/i',
'', $stringtoclean);
6783 $stringtoclean = preg_replace(
'/javascript\s*:/i',
'', $stringtoclean);
6785 $temp = strip_tags($stringtoclean, $allowed_tags_string);
6787 if ($cleanalsosomestyles) {
6788 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)\s*!\s*important/i',
'', $temp);
6790 if ($removeclassattribute) {
6791 $temp = preg_replace(
'/(<[^>]+)\s+class=((["\']).*?\\3|\\w*)/i',
'\\1', $temp);
6796 if ($cleanalsojavascript) {
6797 $temp = preg_replace(
'/javascript\s*:/i',
'', $temp);
6800 $temp = str_replace(
'__!DOCTYPE_HTML__',
'<!DOCTYPE html>', $temp);
6802 $temp = preg_replace(
'/<comment>([^>]*)<\/comment>/',
'<!--\1-->', $temp);
6820 function dol_string_onlythesehtmlattributes($stringtoclean, $allowed_attributes = array(
"allow",
"allowfullscreen",
"alt",
"class",
"contenteditable",
"data-html",
"frameborder",
"height",
"href",
"id",
"name",
"src",
"style",
"target",
"title",
"width"))
6822 if (class_exists(
'DOMDocument') && !empty($stringtoclean)) {
6823 $stringtoclean =
'<?xml encoding="UTF-8"><html><body>'.$stringtoclean.
'</body></html>';
6825 $dom =
new DOMDocument(
null,
'UTF-8');
6826 $dom->loadHTML($stringtoclean, LIBXML_ERR_NONE|LIBXML_HTML_NOIMPLIED|LIBXML_HTML_NODEFDTD|LIBXML_NONET|LIBXML_NOWARNING|LIBXML_NOXMLDECL);
6828 if (is_object($dom)) {
6829 for ($els = $dom->getElementsByTagname(
'*'), $i = $els->length - 1; $i >= 0; $i--) {
6830 for ($attrs = $els->item($i)->attributes, $ii = $attrs->length - 1; $ii >= 0; $ii--) {
6832 if (! empty($attrs->item($ii)->name)) {
6834 if (! in_array($attrs->item($ii)->name, $allowed_attributes)) {
6835 $els->item($i)->removeAttribute($attrs->item($ii)->name);
6836 } elseif (in_array($attrs->item($ii)->name, array(
'style'))) {
6837 $valuetoclean = $attrs->item($ii)->value;
6839 if (isset($valuetoclean)) {
6841 $oldvaluetoclean = $valuetoclean;
6842 $valuetoclean = preg_replace(
'/\/\*.*\*\//m',
'', $valuetoclean);
6843 $valuetoclean = preg_replace(
'/position\s*:\s*[a-z]+/mi',
'', $valuetoclean);
6844 if ($els->item($i)->tagName ==
'a') {
6845 $valuetoclean = preg_replace(
'/display\s*://m',
'', $valuetoclean);
6846 $valuetoclean = preg_replace(
'/z-index\s*://m',
'', $valuetoclean);
6847 $valuetoclean = preg_replace(
'/\s+(top|left|right|bottom)\s*://m',
'', $valuetoclean);
6849 }
while ($oldvaluetoclean != $valuetoclean);
6852 $attrs->item($ii)->value = $valuetoclean;
6859 $return = $dom->saveHTML();
6862 $return = preg_replace(
'/^'.preg_quote(
'<?xml encoding="UTF-8">',
'/').
'/',
'', $return);
6863 $return = preg_replace(
'/^'.preg_quote(
'<html><body>',
'/').
'/',
'', $return);
6864 $return = preg_replace(
'/'.preg_quote(
'</body></html>',
'/').
'$/',
'', $return);
6865 return trim($return);
6867 return $stringtoclean;
6884 $temp = $stringtoclean;
6885 foreach ($disallowed_tags as $tagtoremove) {
6886 $temp = preg_replace(
'/<\/?'.$tagtoremove.
'>/',
'', $temp);
6887 $temp = preg_replace(
'/<\/?'.$tagtoremove.
'\s+[^>]*>/',
'', $temp);
6890 if ($cleanalsosomestyles) {
6891 $temp = preg_replace(
'/position\s*:\s*(absolute|fixed)\s*!\s*important/',
'', $temp);
6909 if ($nboflines == 1) {
6911 $firstline = preg_replace(
'/<br[^>]*>.*$/s',
'', $text);
6912 $firstline = preg_replace(
'/<div[^>]*>.*$/s',
'', $firstline);
6914 $firstline = preg_replace(
'/[\n\r].*/',
'', $text);
6916 return $firstline.((strlen($firstline) != strlen($text)) ?
'...' :
'');
6920 $text = preg_replace(
'/\n/',
'', $text);
6922 $repTable = array(
"\t" =>
" ",
"\n" =>
" ",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
6924 $repTable = array(
"\t" =>
" ",
"\n" =>
"<br>",
"\r" =>
" ",
"\0" =>
" ",
"\x0B" =>
" ");
6927 $text = strtr($text, $repTable);
6928 if ($charset ==
'UTF-8') {
6929 $pattern =
'/(<br[^>]*>)/Uu';
6932 $pattern =
'/(<br[^>]*>)/U';
6934 $a = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
6939 while (($i < $nba) && ($i < ($nboflines * 2))) {
6941 $firstline .= $a[$i];
6942 } elseif (($i < (($nboflines * 2) - 1)) && ($i < ($nba - 1))) {
6943 $firstline .= ($ishtml ?
"<br>\n" :
"\n");
6948 return $firstline.(($i < $nba) ?
'...' :
'');
6963 function dol_nl2br($stringtoencode, $nl2brmode = 0, $forxml =
false)
6966 return nl2br($stringtoencode, $forxml);
6968 $ret = preg_replace(
'/(\r\n|\r|\n)/i', ($forxml ?
'<br />' :
'<br>'), $stringtoencode);
6991 function dol_htmlentitiesbr($stringtoencode, $nl2brmode = 0, $pagecodefrom =
'UTF-8', $removelasteolbr = 1)
6993 $newstring = $stringtoencode;
6995 $newstring = preg_replace(
'/<br(\s[\sa-zA-Z_="]*)?\/?>/i',
'<br>', $newstring);
6996 if ($removelasteolbr) {
6997 $newstring = preg_replace(
'/<br>$/i',
'', $newstring);
6999 $newstring = strtr($newstring, array(
'&'=>
'__and__',
'<'=>
'__lt__',
'>'=>
'__gt__',
'"'=>
'__dquot__'));
7001 $newstring = strtr($newstring, array(
'__and__'=>
'&',
'__lt__'=>
'<',
'__gt__'=>
'>',
'__dquot__'=>
'"'));
7003 if ($removelasteolbr) {
7004 $newstring = preg_replace(
'/(\r\n|\r|\n)$/i',
'', $newstring);