44 $len = strlen($source);
46 $charAt = substr($source, $pos, 1);
49 $charAt = substr($source, $pos, 1);
53 $unicodeHexVal = substr($source, $pos, 4);
54 $unicode = hexdec($unicodeHexVal);
55 $entity =
"&#".$unicode.
';';
56 $decodedStr .= utf8_encode($entity);
60 $hexVal = substr($source, $pos, 2);
61 $decodedStr .= chr(hexdec($hexVal));
65 $decodedStr .= $charAt;
84 $modulesdir = array();
86 foreach ($conf->file->dol_document_root as $type => $dirroot) {
88 if ($type ===
'main') {
89 $modulesdir[$dirroot.
'/core/modules'.$subdir.
'/'] = $dirroot.
'/core/modules'.$subdir.
'/';
93 $handle = @opendir($dirroot);
94 if (is_resource($handle)) {
95 while (($file = readdir($handle)) !==
false) {
96 if (preg_match(
'/disabled/', $file)) {
100 if (is_dir($dirroot.
'/'.$file) && substr($file, 0, 1) <>
'.' && substr($file, 0, 3) <>
'CVS' && $file !=
'includes') {
101 if (is_dir($dirroot.
'/'.$file.
'/core/modules'.$subdir.
'/')) {
102 $modulesdir[$dirroot.
'/'.$file.
'/core/modules'.$subdir.
'/'] = $dirroot.
'/'.$file.
'/core/modules'.$subdir.
'/';
125 $outputlangs = $langs;
128 if ($outputlangs->defaultlang ==
'ca_CA') {
131 if ($outputlangs->defaultlang ==
'en_US') {
132 $selected =
'USLetter';
150 foreach ($langs->dir as $searchdir) {
151 $formfile = ($searchdir.
"/langs/".$langs->defaultlang.
"/".$filename);
152 dol_syslog(
'functions2::dol_print_file search file '.$formfile, LOG_DEBUG);
153 if (is_readable($formfile)) {
154 $content = file_get_contents($formfile);
156 if (!$isutf8 && $conf->file->character_set_client ==
'UTF-8') {
157 print utf8_encode($content);
158 } elseif ($isutf8 && $conf->file->character_set_client ==
'ISO-8859-1') {
159 print utf8_decode($content);
165 dol_syslog(
'functions2::dol_print_file not found', LOG_DEBUG);
170 if ($langs->defaultlang !=
"en_US") {
171 $formfilealt = $searchdir.
"/langs/en_US/".$filename;
173 $formfilealt = $searchdir.
"/langs/fr_FR/".$filename;
175 dol_syslog(
'functions2::dol_print_file search alt file '.$formfilealt, LOG_DEBUG);
177 if (is_readable($formfilealt)) {
178 $content = file_get_contents($formfilealt);
180 if (!$isutf8 && $conf->file->character_set_client ==
'UTF-8') {
181 print utf8_encode($content);
182 } elseif ($isutf8 && $conf->file->character_set_client ==
'ISO-8859-1') {
183 print utf8_decode($content);
189 dol_syslog(
'functions2::dol_print_file not found', LOG_DEBUG);
210 $langs->loadLangs(array(
'other',
'admin'));
212 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
215 $deltadateforclient = ((int) $_SESSION[
'dol_tz'] + (
int) $_SESSION[
'dol_dst']);
217 $deltadateforuser = round($deltadateforclient - $deltadateforserver);
221 print
'<table class="border tableforfield centpercent">';
225 if (!empty($object->import_key)) {
227 print
'<tr><td class="titlefield">';
229 print $langs->trans(
"ImportedWithSet");
235 print $object->import_key;
244 if (!empty($object->user_creation) || !empty($object->user_creation_id)) {
246 print
'<tr><td class="titlefield">';
248 print $langs->trans(
"CreatedBy");
254 if (is_object($object->user_creation)) {
255 if ($object->user_creation->id) {
256 print $object->user_creation->getNomUrl(-1,
'', 0, 0, 0);
258 print $langs->trans(
"Unknown");
261 $userstatic =
new User($db);
262 $userstatic->fetch($object->user_creation_id ? $object->user_creation_id : $object->user_creation);
263 if ($userstatic->id) {
264 print $userstatic->getNomUrl(-1,
'', 0, 0, 0);
266 print $langs->trans(
"Unknown");
277 if (!empty($object->date_creation)) {
279 print
'<tr><td class="titlefield">';
281 print $langs->trans(
"DateCreation");
287 print
dol_print_date($object->date_creation,
'dayhour',
'tzserver');
288 if ($deltadateforuser) {
289 print
' <span class="opacitymedium">'.$langs->trans(
"CurrentHour").
'</span> / '.
dol_print_date($object->date_creation,
"dayhour",
"tzuserrel").
' <span class="opacitymedium">'.$langs->trans(
"ClientHour").
'</span>';
299 if (!empty($object->user_modification) || !empty($object->user_modification_id)) {
301 print
'<tr><td class="titlefield">';
303 print $langs->trans(
"ModifiedBy");
309 if (is_object($object->user_modification)) {
310 if ($object->user_modification->id) {
311 print $object->user_modification->getNomUrl(-1,
'', 0, 0, 0);
313 print $langs->trans(
"Unknown");
316 $userstatic =
new User($db);
317 $userstatic->fetch($object->user_modification_id ? $object->user_modification_id : $object->user_modification);
318 if ($userstatic->id) {
319 print $userstatic->getNomUrl(-1,
'', 0, 0, 0);
321 print $langs->trans(
"Unknown");
332 if (!empty($object->date_modification)) {
334 print
'<tr><td class="titlefield">';
336 print $langs->trans(
"DateLastModification");
342 print
dol_print_date($object->date_modification,
'dayhour',
'tzserver');
343 if ($deltadateforuser) {
344 print
' <span class="opacitymedium">'.$langs->trans(
"CurrentHour").
'</span> / '.
dol_print_date($object->date_modification,
"dayhour",
"tzuserrel").
' <span class="opacitymedium">'.$langs->trans(
"ClientHour").
'</span>';
354 if (!empty($object->user_validation) || !empty($object->user_validation_id)) {
356 print
'<tr><td class="titlefield">';
358 print $langs->trans(
"ValidatedBy");
364 if (is_object($object->user_validation)) {
365 if ($object->user_validation->id) {
366 print $object->user_validation->getNomUrl(-1,
'', 0, 0, 0);
368 print $langs->trans(
"Unknown");
371 $userstatic =
new User($db);
372 $userstatic->fetch($object->user_validation_id ? $object->user_validation_id : $object->user_validation);
373 if ($userstatic->id) {
374 print $userstatic->getNomUrl(-1,
'', 0, 0, 0);
376 print $langs->trans(
"Unknown");
387 if (!empty($object->date_validation)) {
389 print
'<tr><td class="titlefield">';
391 print $langs->trans(
"DateValidation");
397 print
dol_print_date($object->date_validation,
'dayhour',
'tzserver');
398 if ($deltadateforuser) {
399 print
' <span class="opacitymedium">'.$langs->trans(
"CurrentHour").
'</span> / '.
dol_print_date($object->date_validation,
"dayhour",
'tzuserrel').
' <span class="opacitymedium">'.$langs->trans(
"ClientHour").
'</span>';
409 if (!empty($object->user_approve) || !empty($object->user_approve_id)) {
411 print
'<tr><td class="titlefield">';
413 print $langs->trans(
"ApprovedBy");
419 if (!empty($object->user_approve) && is_object($object->user_approve)) {
420 if ($object->user_approve->id) {
421 print $object->user_approve->getNomUrl(-1,
'', 0, 0, 0);
423 print $langs->trans(
"Unknown");
426 $userstatic =
new User($db);
427 $userstatic->fetch($object->user_approve_id ? $object->user_approve_id : $object->user_approve);
428 if ($userstatic->id) {
429 print $userstatic->getNomUrl(-1,
'', 0, 0, 0);
431 print $langs->trans(
"Unknown");
442 if (!empty($object->date_approve) || !empty($object->date_approval)) {
444 print
'<tr><td class="titlefield">';
446 print $langs->trans(
"DateApprove");
452 print
dol_print_date($object->date_approve ? $object->date_approve : $object->date_approval,
'dayhour',
'tzserver');
453 if ($deltadateforuser) {
454 print
' <span class="opacitymedium">'.$langs->trans(
"CurrentHour").
'</span> / '.
dol_print_date($object->date_approve,
"dayhour",
'tzuserrel').
' <span class="opacitymedium">'.$langs->trans(
"ClientHour").
'</span>';
464 if (!empty($object->user_approve_id2)) {
466 print
'<tr><td class="titlefield">';
468 print $langs->trans(
"ApprovedBy");
474 $userstatic =
new User($db);
475 $userstatic->fetch($object->user_approve_id2);
476 if ($userstatic->id) {
477 print $userstatic->getNomUrl(-1,
'', 0, 0, 0);
479 print $langs->trans(
"Unknown");
489 if (!empty($object->date_approve2)) {
491 print
'<tr><td class="titlefield">';
493 print $langs->trans(
"DateApprove2");
499 print
dol_print_date($object->date_approve2,
'dayhour',
'tzserver');
500 if ($deltadateforuser) {
501 print
' <span class="opacitymedium">'.$langs->trans(
"CurrentHour").
'</span> / '.
dol_print_date($object->date_approve2,
"dayhour",
'tzuserrel').
' <span class="opacitymedium">'.$langs->trans(
"ClientHour").
'</span>';
511 if (!empty($object->user_signature) || !empty($object->user_signature_id)) {
513 print
'<tr><td class="titlefield">';
515 print $langs->trans(
'SignedBy');
521 if (is_object($object->user_signature)) {
522 if ($object->user_signature->id) {
523 print $object->user_signature->getNomUrl(-1,
'', 0, 0, 0);
525 print $langs->trans(
'Unknown');
528 $userstatic =
new User($db);
529 $userstatic->fetch($object->user_signature_id ? $object->user_signature_id : $object->user_signature);
530 if ($userstatic->id) {
531 print $userstatic->getNomUrl(-1,
'', 0, 0, 0);
533 print $langs->trans(
'Unknown');
544 if (!empty($object->date_signature)) {
546 print
'<tr><td class="titlefield">';
548 print $langs->trans(
'DateSigning');
555 if ($deltadateforuser) {
556 print
' <span class="opacitymedium">'.$langs->trans(
'CurrentHour').
'</span> / '.
dol_print_date($object->date_signature,
'dayhour',
'tzuserrel').
' <span class="opacitymedium">'.$langs->trans(
'ClientHour').
'</span>';
566 if (!empty($object->user_cloture) || !empty($object->user_closing) || !empty($object->user_closing_id)) {
567 if (isset($object->user_cloture) && !empty($object->user_cloture)) {
568 $object->user_closing = $object->user_cloture;
571 print
'<tr><td class="titlefield">';
573 print $langs->trans(
"ClosedBy");
579 if (is_object($object->user_closing)) {
580 if ($object->user_closing->id) {
581 print $object->user_closing->getNomUrl(-1,
'', 0, 0, 0);
583 print $langs->trans(
"Unknown");
586 $userstatic =
new User($db);
587 $userstatic->fetch($object->user_closing_id ? $object->user_closing_id : $object->user_closing);
588 if ($userstatic->id) {
589 print $userstatic->getNomUrl(-1,
'', 0, 0, 0);
591 print $langs->trans(
"Unknown");
602 if (!empty($object->date_cloture) || !empty($object->date_closing)) {
603 if (isset($object->date_cloture) && !empty($object->date_cloture)) {
604 $object->date_closing = $object->date_cloture;
607 print
'<tr><td class="titlefield">';
609 print $langs->trans(
"DateClosing");
615 print
dol_print_date($object->date_closing,
'dayhour',
'tzserver');
616 if ($deltadateforuser) {
617 print
' <span class="opacitymedium">'.$langs->trans(
"CurrentHour").
'</span> / '.
dol_print_date($object->date_closing,
"dayhour",
'tzuserrel').
' <span class="opacitymedium">'.$langs->trans(
"ClientHour").
'</span>';
627 if (!empty($object->user_rappro) || !empty($object->user_rappro_id)) {
629 print
'<tr><td class="titlefield">';
631 print $langs->trans(
"ReconciledBy");
637 if (is_object($object->user_rappro)) {
638 if ($object->user_rappro->id) {
639 print $object->user_rappro->getNomUrl(-1,
'', 0, 0, 0);
641 print $langs->trans(
"Unknown");
644 $userstatic =
new User($db);
645 $userstatic->fetch($object->user_rappro_id ? $object->user_rappro_id : $object->user_rappro);
646 if ($userstatic->id) {
647 print $userstatic->getNomUrl(1,
'', 0, 0, 0);
649 print $langs->trans(
"Unknown");
660 if (!empty($object->date_rappro)) {
662 print
'<tr><td class="titlefield">';
664 print $langs->trans(
"DateConciliating");
670 print
dol_print_date($object->date_rappro,
'dayhour',
'tzserver');
671 if ($deltadateforuser) {
672 print
' <span class="opacitymedium">'.$langs->trans(
"CurrentHour").
'</span> / '.
dol_print_date($object->date_rappro,
"dayhour",
'tzuserrel').
' <span class="opacitymedium">'.$langs->trans(
"ClientHour").
'</span>';
682 if (!empty($object->date_envoi)) {
684 print
'<tr><td class="titlefield">';
686 print $langs->trans(
"DateLastSend");
693 if ($deltadateforuser) {
694 print
' <span class="opacitymedium">'.$langs->trans(
"CurrentHour").
'</span> / '.
dol_print_date($object->date_envoi,
"dayhour",
'tzuserrel').
' <span class="opacitymedium">'.$langs->trans(
"ClientHour").
'</span>';
719 $tmp = explode(
'@', $email);
720 return $tmp[0].
'+'.$trackingid.
'@'.(isset($tmp[1]) ? $tmp[1] :
'');
731 list($user, $domain) = explode(
"@", $mail, 2);
748 function isValidUrl($url, $http = 0, $pass = 0, $port = 0, $path = 0, $query = 0, $anchor = 0)
755 $urlregex .=
"^(http:\/\/|https:\/\/)";
760 $urlregex .=
"([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)";
766 $urlregex .=
"([a-z0-9+\$_\\\:-])+(\.[a-z0-9+\$_-][a-z0-9+\$_-]+)*";
771 $urlregex .=
"(\:[0-9]{2,5})";
775 $urlregex .=
"(\/([a-z0-9+\$_-]\.?)+)*\/";
779 $urlregex .=
"(\?[a-z+&\$_.-][a-z0-9;:@\/&%=+\$_.-]*)";
783 $urlregex .=
"(#[a-z_.-][a-z0-9+\$_.-]*)$";
787 if (preg_match(
'/'.$urlregex.
'/i', $url)) {
803 if ($company->isInEEC()) {
809 $vatprefix =
'[a-zA-Z][a-zA-Z]';
810 if (!preg_match(
'/^'.$vatprefix.
'[a-zA-Z0-9\-\.]{5,14}$/i', str_replace(
' ',
'', $company->tva_intra))) {
831 if (preg_match(
'/^(https?:[\\/]+)?([0-9A-Z.-]+\.[A-Z]{2,4})(:[0-9]+)?/i', $url, $regs)) {
834 $port = isset($regs[3]) ? $regs[3] :
'';
842 if (preg_match(
'/^http:[\\/]+/i', $url)) {
843 $url = preg_replace(
'/^http:[\\/]+/i',
'', $url);
849 $CleanUrl = preg_replace(
'/^'.preg_quote($proto.$domain,
'/').
'/i', $newproto.strtolower($domain), $url);
870 function dolObfuscateEmail($mail, $replace =
"*", $nbreplace = 8, $nbdisplaymail = 4, $nbdisplaydomain = 3, $displaytld =
true)
875 $tab = explode(
'@', $mail);
876 $tab2 = explode(
'.', $tab[1]);
877 $string_replace =
'';
878 $mail_name = $tab[0];
879 $mail_domaine = $tab2[0];
882 $nbofelem = count($tab2);
883 for ($i = 1; $i < $nbofelem && $displaytld; $i++) {
884 $mail_tld .=
'.'.$tab2[$i];
887 for ($i = 0; $i < $nbreplace; $i++) {
888 $string_replace .= $replace;
891 if (strlen($mail_name) > $nbdisplaymail) {
892 $mail_name = substr($mail_name, 0, $nbdisplaymail);
895 if (strlen($mail_domaine) > $nbdisplaydomain) {
896 $mail_domaine = substr($mail_domaine, strlen($mail_domaine) - $nbdisplaydomain);
899 return $mail_name.$string_replace.$mail_domaine.$mail_tld;
912 function array2tr($data, $troptions =
'', $tdoptions =
'')
914 $text =
'<tr '.$troptions.
'>';
915 foreach ($data as $key => $item) {
916 $text .=
'<td '.$tdoptions.
'>'.$item.
'</td>';
932 function array2table($data, $tableMarkup = 1, $tableoptions =
'', $troptions =
'', $tdoptions =
'')
936 $text =
'<table '.$tableoptions.
'>';
938 foreach ($data as $key => $item) {
939 if (is_array($item)) {
940 $text .=
array2tr($item, $troptions, $tdoptions);
942 $text .=
'<tr '.$troptions.
'>';
943 $text .=
'<td '.$tdoptions.
'>'.$key.
'</td>';
944 $text .=
'<td '.$tdoptions.
'>'.$item.
'</td>';
970 function get_next_value($db, $mask, $table, $field, $where =
'', $objsoc =
'', $date =
'', $mode =
'next', $bentityon =
true, $objuser =
null, $forceentity =
null)
974 if (!is_object($objsoc)) {
975 $valueforccc = $objsoc;
976 } elseif ($table ==
"commande_fournisseur" || $table ==
"facture_fourn") {
982 $sharetable = $table;
983 if ($table ==
'facture' || $table ==
'invoice') {
984 $sharetable =
'invoicenumber';
1000 $hasglobalcounter =
false;
1003 if (preg_match(
'/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i', $mask, $reg)) {
1004 $masktri = $reg[1].(!empty($reg[2]) ? $reg[2] :
'').(!empty($reg[3]) ? $reg[3] :
'');
1005 $maskcounter = $reg[1];
1006 $hasglobalcounter =
true;
1010 $maskcounter =
'00000';
1015 $resetEveryMonth =
false;
1016 if (
dol_strlen($maskcounter) < 3 && empty($conf->global->MAIN_COUNTER_WITH_LESS_3_DIGITS)) {
1017 return 'ErrorCounterMustHaveMoreThan3Digits';
1021 $regClientRef = array();
1022 if (preg_match(
'/\{(c+)(0*)\}/i', $mask, $regClientRef)) {
1023 $maskrefclient = $regClientRef[1].$regClientRef[2];
1024 $maskrefclient_maskclientcode = $regClientRef[1];
1025 $maskrefclient_maskcounter = $regClientRef[2];
1026 $maskrefclient_maskoffset = 0;
1027 $maskrefclient_clientcode = substr($valueforccc, 0,
dol_strlen($maskrefclient_maskclientcode));
1028 $maskrefclient_clientcode = str_pad($maskrefclient_clientcode,
dol_strlen($maskrefclient_maskclientcode),
"#", STR_PAD_RIGHT);
1030 if (
dol_strlen($maskrefclient_maskcounter) > 0 &&
dol_strlen($maskrefclient_maskcounter) < 3) {
1031 return 'ErrorCounterMustHaveMoreThan3Digits';
1034 $maskrefclient =
'';
1038 if (!$hasglobalcounter && ($maskrefclient_maskcounter ==
'')) {
1039 return 'ErrorBadMask';
1044 if (preg_match(
'/\{(t+)\}/i', $mask, $regType)) {
1045 $masktype = $regType[1];
1046 $masktype_value =
dol_substr(preg_replace(
'/^TE_/',
'', $objsoc->typent_code), 0,
dol_strlen($regType[1]));
1047 $masktype_value = str_pad($masktype_value,
dol_strlen($regType[1]),
"#", STR_PAD_RIGHT);
1050 $masktype_value =
'';
1055 if (preg_match(
'/\{(u+)\}/i', $mask, $regType)) {
1056 $lastname =
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
1057 if (is_object($objuser)) {
1058 $lastname = $objuser->lastname;
1061 $maskuser = $regType[1];
1062 $maskuser_value = substr($lastname, 0,
dol_strlen($regType[1]));
1063 $maskuser_value = str_pad($maskuser_value,
dol_strlen($regType[1]),
"#", STR_PAD_RIGHT);
1066 $maskuser_value =
'';
1070 $maskperso = array();
1071 $maskpersonew = array();
1074 while (preg_match(
'/\{([A-Z]+)\-([1-9])\}/', $tmpmask, $regKey)) {
1075 $maskperso[$regKey[1]] =
'{'.$regKey[1].
'-'.$regKey[2].
'}';
1076 $maskpersonew[$regKey[1]] = str_pad(
'', $regKey[2],
'_', STR_PAD_RIGHT);
1077 $tmpmask = preg_replace(
'/\{'.$regKey[1].
'\-'.$regKey[2].
'\}/i', $maskpersonew[$regKey[1]], $tmpmask);
1080 if (strstr($mask,
'user_extra_')) {
1081 $start =
"{user_extra_";
1084 if (!empty($user->array_options[
'options_'.$extra])) {
1085 $mask = preg_replace(
'#('.$start.
')(.*?)('.$end.
')#si', $user->array_options[
'options_'.$extra], $mask);
1088 $maskwithonlyymcode = $mask;
1089 $maskwithonlyymcode = preg_replace(
'/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i', $maskcounter, $maskwithonlyymcode);
1090 $maskwithonlyymcode = preg_replace(
'/\{dd\}/i',
'dd', $maskwithonlyymcode);
1091 $maskwithonlyymcode = preg_replace(
'/\{(c+)(0*)\}/i', $maskrefclient, $maskwithonlyymcode);
1092 $maskwithonlyymcode = preg_replace(
'/\{(t+)\}/i', $masktype_value, $maskwithonlyymcode);
1093 $maskwithonlyymcode = preg_replace(
'/\{(u+)\}/i', $maskuser_value, $maskwithonlyymcode);
1094 foreach ($maskperso as $key => $val) {
1095 $maskwithonlyymcode = preg_replace(
'/'.preg_quote($val,
'/').
'/i', $maskpersonew[$key], $maskwithonlyymcode);
1097 $maskwithnocode = $maskwithonlyymcode;
1098 $maskwithnocode = preg_replace(
'/\{yyyy\}/i',
'yyyy', $maskwithnocode);
1099 $maskwithnocode = preg_replace(
'/\{yy\}/i',
'yy', $maskwithnocode);
1100 $maskwithnocode = preg_replace(
'/\{y\}/i',
'y', $maskwithnocode);
1101 $maskwithnocode = preg_replace(
'/\{mm\}/i',
'mm', $maskwithnocode);
1108 if (!empty($reg[2]) && preg_match(
'/^\+/', $reg[2])) {
1109 $maskoffset = preg_replace(
'/^\+/',
'', $reg[2]);
1111 if (!empty($reg[3]) && preg_match(
'/^\+/', $reg[3])) {
1112 $maskoffset = preg_replace(
'/^\+/',
'', $reg[3]);
1118 $yearoffsettype =
false;
1121 if (!empty($reg[2]) && preg_match(
'/^@/', $reg[2])) {
1122 $yearoffsettype = preg_replace(
'/^@/',
'', $reg[2]);
1124 if (!empty($reg[3]) && preg_match(
'/^@/', $reg[3])) {
1125 $yearoffsettype = preg_replace(
'/^@/',
'', $reg[3]);
1129 if (is_numeric($yearoffsettype) && $yearoffsettype >= 1) {
1130 $maskraz = $yearoffsettype;
1131 } elseif ($yearoffsettype ===
'0' || (!empty($yearoffsettype) && !is_numeric($yearoffsettype) && $conf->global->SOCIETE_FISCAL_MONTH_START > 1)) {
1132 $maskraz = $conf->global->SOCIETE_FISCAL_MONTH_START;
1137 if ($maskraz == 99) {
1138 $maskraz = date(
'm', $date);
1139 $resetEveryMonth =
true;
1141 if ($maskraz > 12) {
1142 return 'ErrorBadMaskBadRazMonth';
1147 if (preg_match(
'/^(.*)\{(y+)\}\{(m+)\}/i', $maskwithonlyymcode, $reg)) {
1150 } elseif (preg_match(
'/^(.*)\{(m+)\}\{(y+)\}/i', $maskwithonlyymcode, $reg)) {
1154 return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
1158 return 'ErrorCantUseRazWithYearOnOneDigit';
1162 if (preg_match(
'/^(.*)\{(m+)\}\{(y+)\}/i', $maskwithonlyymcode, $reg)) {
1165 } elseif (preg_match(
'/^(.*)\{(y+)\}\{(m+)\}/i', $maskwithonlyymcode, $reg)) {
1168 } elseif (preg_match(
'/^(.*)\{(y+)\}/i', $maskwithonlyymcode, $reg)) {
1172 return 'ErrorCantUseRazIfNoYearInMask';
1176 $yearlen = $posy ?
dol_strlen($reg[$posy]) : 0;
1177 $monthlen = $posm ?
dol_strlen($reg[$posm]) : 0;
1180 $monthpos = ($yearpos + $yearlen);
1181 if ($posy == 3 && $posm == 2) {
1183 $yearpos = ($monthpos + $monthlen);
1188 $monthcomp = $maskraz;
1191 if (!empty($yearoffsettype) && !is_numeric($yearoffsettype) && $yearoffsettype !=
'=') {
1192 $currentyear = date(
"Y", $date);
1193 $fiscaldate =
dol_mktime(
'0',
'0',
'0', $maskraz,
'1', $currentyear);
1194 $newyeardate =
dol_mktime(
'0',
'0',
'0',
'1',
'1', $currentyear);
1195 $nextnewyeardate =
dol_mktime(
'0',
'0',
'0',
'1',
'1', $currentyear + 1);
1199 if ($date >= $fiscaldate) {
1201 if ($date < $nextnewyeardate && $yearoffsettype ==
'+') {
1204 } elseif ($date >= $newyeardate && $yearoffsettype ==
'-') {
1208 } elseif (date(
"m", $date) < $maskraz && empty($resetEveryMonth)) {
1213 if ($yearlen == 4) {
1214 $yearcomp = sprintf(
"%04d", date(
"Y", $date) + $yearoffset);
1215 } elseif ($yearlen == 2) {
1216 $yearcomp = sprintf(
"%02d", date(
"y", $date) + $yearoffset);
1217 } elseif ($yearlen == 1) {
1218 $yearcomp = substr(date(
'y', $date), 1, 1) + $yearoffset;
1220 if ($monthcomp > 1 && empty($resetEveryMonth)) {
1221 if ($yearlen == 4) {
1222 $yearcomp1 = sprintf(
"%04d", date(
"Y", $date) + $yearoffset + 1);
1223 } elseif ($yearlen == 2) {
1224 $yearcomp1 = sprintf(
"%02d", date(
"y", $date) + $yearoffset + 1);
1228 $sqlwhere .=
" (SUBSTRING(".$field.
", ".$yearpos.
", ".$yearlen.
") = '".$db->escape($yearcomp).
"'";
1229 $sqlwhere .=
" AND SUBSTRING(".$field.
", ".$monthpos.
", ".$monthlen.
") >= '".str_pad($monthcomp, $monthlen,
'0', STR_PAD_LEFT).
"')";
1231 $sqlwhere .=
" (SUBSTRING(".$field.
", ".$yearpos.
", ".$yearlen.
") = '".$db->escape($yearcomp1).
"'";
1232 $sqlwhere .=
" AND SUBSTRING(".$field.
", ".$monthpos.
", ".$monthlen.
") < '".str_pad($monthcomp, $monthlen,
'0', STR_PAD_LEFT).
"') ";
1234 } elseif ($resetEveryMonth) {
1235 $sqlwhere .=
"(SUBSTRING(".$field.
", ".$yearpos.
", ".$yearlen.
") = '".$db->escape($yearcomp).
"'";
1236 $sqlwhere .=
" AND SUBSTRING(".$field.
", ".$monthpos.
", ".$monthlen.
") = '".str_pad($monthcomp, $monthlen,
'0', STR_PAD_LEFT).
"')";
1238 $sqlwhere .=
"(SUBSTRING(".$field.
", ".$yearpos.
", ".$yearlen.
") = '".$db->escape($yearcomp).
"')";
1245 if (function_exists(
'mb_strrpos')) {
1246 $posnumstart = mb_strrpos($maskwithnocode, $maskcounter, 0,
'UTF-8');
1248 $posnumstart = strrpos($maskwithnocode, $maskcounter);
1250 if ($posnumstart < 0) {
1251 return 'ErrorBadMaskFailedToLocatePosOfSequence';
1253 $sqlstring =
"SUBSTRING(".$field.
", ".($posnumstart + 1).
", ".
dol_strlen($maskcounter).
")";
1257 $maskLike = str_replace(
"%",
"_", $maskLike);
1260 $maskLike = preg_replace(
'/\{yyyy\}/i',
'____', $maskLike);
1261 $maskLike = preg_replace(
'/\{yy\}/i',
'__', $maskLike);
1262 $maskLike = preg_replace(
'/\{y\}/i',
'_', $maskLike);
1263 $maskLike = preg_replace(
'/\{mm\}/i',
'__', $maskLike);
1264 $maskLike = preg_replace(
'/\{dd\}/i',
'__', $maskLike);
1266 if ($maskrefclient) {
1275 foreach ($maskperso as $key => $val) {
1276 $maskLike = str_replace(
dol_string_nospecial($maskperso[$key]), $maskpersonew[$key], $maskLike);
1281 $sql =
"SELECT MAX(".$sqlstring.
") as val";
1282 $sql .=
" FROM ".MAIN_DB_PREFIX.$table;
1283 $sql .=
" WHERE ".$field.
" LIKE '".$db->escape($maskLike).
"'";
1284 $sql .=
" AND ".$field.
" NOT LIKE '(PROV%)'";
1288 $sql .=
" AND ". $db->regexpsql($sqlstring,
'^[0-9]+$',
true);
1292 $sql .=
" AND entity IN (".getEntity($sharetable).
")";
1293 } elseif (!empty($forceentity)) {
1294 $sql .=
" AND entity IN (".$db->sanitize($forceentity).
")";
1300 $sql .=
" AND ".$sqlwhere;
1304 dol_syslog(
"functions2::get_next_value mode=".$mode, LOG_DEBUG);
1305 $resql = $db->query($sql);
1307 $obj = $db->fetch_object(
$resql);
1308 $counter = $obj->val;
1314 if (empty($counter)) {
1315 $counter = $maskoffset;
1316 } elseif (preg_match(
'/[^0-9]/i', $counter)) {
1318 dol_syslog(
"Error, the last counter found is '".$counter.
"' so is not a numeric value. We will restart to 1.", LOG_ERR);
1319 } elseif ($counter < $maskoffset && empty($conf->global->MAIN_NUMBERING_OFFSET_ONLY_FOR_FIRST)) {
1320 $counter = $maskoffset;
1323 if ($mode ==
'last') {
1324 $counterpadded = str_pad($counter,
dol_strlen($maskcounter),
"0", STR_PAD_LEFT);
1328 $maskLike = str_replace(
"%",
"_", $maskLike);
1330 $maskLike = preg_replace(
'/\{yyyy\}/i',
'____', $maskLike);
1331 $maskLike = preg_replace(
'/\{yy\}/i',
'__', $maskLike);
1332 $maskLike = preg_replace(
'/\{y\}/i',
'_', $maskLike);
1333 $maskLike = preg_replace(
'/\{mm\}/i',
'__', $maskLike);
1334 $maskLike = preg_replace(
'/\{dd\}/i',
'__', $maskLike);
1336 if ($maskrefclient) {
1347 $sql =
"SELECT ".$field.
" as ref";
1348 $sql .=
" FROM ".MAIN_DB_PREFIX.$table;
1349 $sql .=
" WHERE ".$field.
" LIKE '".$db->escape($maskLike).
"'";
1350 $sql .=
" AND ".$field.
" NOT LIKE '%PROV%'";
1352 $sql .=
" AND entity IN (".getEntity($sharetable).
")";
1353 } elseif (!empty($forceentity)) {
1354 $sql .=
" AND entity IN (".$db->sanitize($forceentity).
")";
1360 $sql .=
" AND ".$sqlwhere;
1363 dol_syslog(
"functions2::get_next_value mode=".$mode, LOG_DEBUG);
1364 $resql = $db->query($sql);
1366 $obj = $db->fetch_object(
$resql);
1375 } elseif ($mode ==
'next') {
1377 $maskrefclient_counter = 0;
1380 if ($counter >= pow(10,
dol_strlen($maskcounter))) {
1381 $counter =
'ErrorMaxNumberReachForThisMask';
1384 if (!empty($maskrefclient_maskcounter)) {
1388 $maskrefclient_posnumstart = strpos($maskwithnocode, $maskrefclient_maskcounter, strpos($maskwithnocode, $maskrefclient));
1389 if ($maskrefclient_posnumstart <= 0) {
1390 return 'ErrorBadMask';
1392 $maskrefclient_sqlstring =
'SUBSTRING('.$field.
', '.($maskrefclient_posnumstart + 1).
', '.
dol_strlen($maskrefclient_maskcounter).
')';
1397 $maskrefclient_maskLike = str_replace(
"%",
"_", $maskrefclient_maskLike);
1399 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{yyyy}'),
'____', $maskrefclient_maskLike);
1400 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{yy}'),
'__', $maskrefclient_maskLike);
1401 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{y}'),
'_', $maskrefclient_maskLike);
1402 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{mm}'),
'__', $maskrefclient_maskLike);
1403 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{dd}'),
'__', $maskrefclient_maskLike);
1404 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{'.$masktri.
'}'), str_pad(
"",
dol_strlen($maskcounter),
"_"), $maskrefclient_maskLike);
1405 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{'.$maskrefclient.
'}'), $maskrefclient_clientcode.str_pad(
"",
dol_strlen($maskrefclient_maskcounter),
"_"), $maskrefclient_maskLike);
1408 $maskrefclient_sql =
"SELECT MAX(".$maskrefclient_sqlstring.
") as val";
1409 $maskrefclient_sql .=
" FROM ".MAIN_DB_PREFIX.$table;
1411 $maskrefclient_sql .=
" WHERE ".$field.
" LIKE '".$db->escape($maskrefclient_maskLike).
"'";
1413 $maskrefclient_sql .=
" AND entity IN (".getEntity($sharetable).
")";
1414 } elseif (!empty($forceentity)) {
1415 $sql .=
" AND entity IN (".$db->sanitize($forceentity).
")";
1418 $maskrefclient_sql .= $where;
1421 $maskrefclient_sql .=
' AND '.$sqlwhere;
1423 $maskrefclient_sql .=
" AND (SUBSTRING(".$field.
", ".(strpos($maskwithnocode, $maskrefclient) + 1).
", ".
dol_strlen($maskrefclient_maskclientcode).
") = '".$db->escape($maskrefclient_clientcode).
"')";
1425 dol_syslog(
"functions2::get_next_value maskrefclient", LOG_DEBUG);
1426 $maskrefclient_resql = $db->query($maskrefclient_sql);
1427 if ($maskrefclient_resql) {
1428 $maskrefclient_obj = $db->fetch_object($maskrefclient_resql);
1429 $maskrefclient_counter = $maskrefclient_obj->val;
1434 if (empty($maskrefclient_counter) || preg_match(
'/[^0-9]/i', $maskrefclient_counter)) {
1435 $maskrefclient_counter = $maskrefclient_maskoffset;
1437 $maskrefclient_counter++;
1444 if (!empty($yearoffsettype) && !is_numeric($yearoffsettype) && $yearoffsettype !=
'=') {
1445 $numFinal = preg_replace(
'/\{yyyy\}/i', date(
"Y", $date) + $yearoffset, $numFinal);
1446 $numFinal = preg_replace(
'/\{yy\}/i', date(
"y", $date) + $yearoffset, $numFinal);
1447 $numFinal = preg_replace(
'/\{y\}/i', substr(date(
"y", $date), 1, 1) + $yearoffset, $numFinal);
1450 $numFinal = preg_replace(
'/\{yyyy\}/i', date(
"Y", $date), $numFinal);
1451 $numFinal = preg_replace(
'/\{yy\}/i', date(
"y", $date), $numFinal);
1452 $numFinal = preg_replace(
'/\{y\}/i', substr(date(
"y", $date), 1, 1), $numFinal);
1454 $numFinal = preg_replace(
'/\{mm\}/i', date(
"m", $date), $numFinal);
1455 $numFinal = preg_replace(
'/\{dd\}/i', date(
"d", $date), $numFinal);
1458 $maskbefore =
'{'.$masktri.
'}';
1459 $maskafter = str_pad($counter,
dol_strlen($maskcounter),
"0", STR_PAD_LEFT);
1461 $numFinal = str_replace($maskbefore, $maskafter, $numFinal);
1464 if ($maskrefclient) {
1466 $maskrefclient_maskbefore =
'{'.$maskrefclient.
'}';
1467 $maskrefclient_maskafter = $maskrefclient_clientcode;
1468 if (
dol_strlen($maskrefclient_maskcounter) > 0) {
1469 $maskrefclient_maskafter .= str_pad($maskrefclient_counter,
dol_strlen($maskrefclient_maskcounter),
"0", STR_PAD_LEFT);
1471 $numFinal = str_replace($maskrefclient_maskbefore, $maskrefclient_maskafter, $numFinal);
1476 $masktype_maskbefore =
'{'.$masktype.
'}';
1477 $masktype_maskafter = $masktype_value;
1478 $numFinal = str_replace($masktype_maskbefore, $masktype_maskafter, $numFinal);
1483 $maskuser_maskbefore =
'{'.$maskuser.
'}';
1484 $maskuser_maskafter = $maskuser_value;
1485 $numFinal = str_replace($maskuser_maskbefore, $maskuser_maskafter, $numFinal);
1489 dol_syslog(
"functions2::get_next_value return ".$numFinal, LOG_DEBUG);
1503 $string =
" ".$string;
1504 $ini = strpos($string, $start);
1508 $ini += strlen($start);
1509 $len = strpos($string, $end, $ini) - $ini;
1510 return substr($string, $ini, $len);
1524 $hasglobalcounter =
false;
1527 if (preg_match(
'/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i', $mask, $reg)) {
1528 $masktri = $reg[1].(isset($reg[2]) ? $reg[2] :
'').(isset($reg[3]) ? $reg[3] :
'');
1529 $maskcounter = $reg[1];
1530 $hasglobalcounter =
true;
1534 $maskcounter =
'00000';
1539 return 'ErrorCounterMustHaveMoreThan3Digits';
1543 $regClientRef = array();
1544 if (preg_match(
'/\{(c+)(0*)\}/i', $mask, $regClientRef)) {
1545 $maskrefclient = $regClientRef[1].$regClientRef[2];
1546 $maskrefclient_maskclientcode = $regClientRef[1];
1547 $maskrefclient_maskcounter = $regClientRef[2];
1548 $maskrefclient_maskoffset = 0;
1549 $maskrefclient_clientcode = substr(
'', 0,
dol_strlen($maskrefclient_maskclientcode));
1550 $maskrefclient_clientcode = str_pad($maskrefclient_clientcode,
dol_strlen($maskrefclient_maskclientcode),
"#", STR_PAD_RIGHT);
1552 if (
dol_strlen($maskrefclient_maskcounter) > 0 &&
dol_strlen($maskrefclient_maskcounter) < 3) {
1553 return 'ErrorCounterMustHaveMoreThan3Digits';
1556 $maskrefclient =
'';
1560 if (!$hasglobalcounter && ($maskrefclient_maskcounter ==
'')) {
1561 return 'ErrorBadMask';
1564 $maskwithonlyymcode = $mask;
1565 $maskwithonlyymcode = preg_replace(
'/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i', $maskcounter, $maskwithonlyymcode);
1566 $maskwithonlyymcode = preg_replace(
'/\{dd\}/i',
'dd', $maskwithonlyymcode);
1567 $maskwithonlyymcode = preg_replace(
'/\{(c+)(0*)\}/i', $maskrefclient, $maskwithonlyymcode);
1568 $maskwithnocode = $maskwithonlyymcode;
1569 $maskwithnocode = preg_replace(
'/\{yyyy\}/i',
'yyyy', $maskwithnocode);
1570 $maskwithnocode = preg_replace(
'/\{yy\}/i',
'yy', $maskwithnocode);
1571 $maskwithnocode = preg_replace(
'/\{y\}/i',
'y', $maskwithnocode);
1572 $maskwithnocode = preg_replace(
'/\{mm\}/i',
'mm', $maskwithnocode);
1578 if (!empty($reg[2]) && preg_match(
'/^\+/', $reg[2])) {
1579 $maskoffset = preg_replace(
'/^\+/',
'', $reg[2]);
1581 if (!empty($reg[3]) && preg_match(
'/^\+/', $reg[3])) {
1582 $maskoffset = preg_replace(
'/^\+/',
'', $reg[3]);
1588 if (!empty($reg[2]) && preg_match(
'/^@/', $reg[2])) {
1589 $maskraz = preg_replace(
'/^@/',
'', $reg[2]);
1591 if (!empty($reg[3]) && preg_match(
'/^@/', $reg[3])) {
1592 $maskraz = preg_replace(
'/^@/',
'', $reg[3]);
1594 if ($maskraz >= 0) {
1595 if ($maskraz == 99) {
1596 $maskraz = date(
'm');
1597 $resetEveryMonth =
true;
1599 if ($maskraz > 12) {
1600 return 'ErrorBadMaskBadRazMonth';
1604 if ($maskraz > 1 && !preg_match(
'/^(.*)\{(y+)\}\{(m+)\}/i', $maskwithonlyymcode, $reg)) {
1605 return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
1607 if ($maskraz <= 1 && !preg_match(
'/^(.*)\{(y+)\}/i', $maskwithonlyymcode, $reg)) {
1608 return 'ErrorCantUseRazIfNoYearInMask';
1614 if (function_exists(
'mb_strrpos')) {
1615 $posnumstart = mb_strrpos($maskwithnocode, $maskcounter, 0,
'UTF-8');
1617 $posnumstart = strrpos($maskwithnocode, $maskcounter);
1619 if ($posnumstart < 0) {
1620 return 'ErrorBadMaskFailedToLocatePosOfSequence';
1632 dol_syslog(
"functions2::check_value result=".$result, LOG_DEBUG);
1644 function binhex($bin, $pad =
false, $upper =
false)
1647 for ($i = 0; $i <= $last; $i++) {
1648 $x += $bin[$last - $i] * pow(2, $i);
1657 $x = strtoupper($x);
1672 for ($i = 0; $i < $strLength; $i++) {
1673 $bin .= str_pad(decbin(hexdec($hexa[$i])), 4,
'0', STR_PAD_LEFT);
1686 $stime = strftime(
'%Y-%m-%d', $time);
1688 if (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/i', $stime, $reg)) {
1703 if (date(
"w", mktime(12, 0, 0, $mois, $jour, $annee)) == 0) {
1704 $jeudiSemaine = mktime(12, 0, 0, $mois, $jour, $annee) - 3 * 24 * 60 * 60;
1705 } elseif (date(
"w", mktime(12, 0, 0, $mois, $jour, $annee)) < 4) {
1706 $jeudiSemaine = mktime(12, 0, 0, $mois, $jour, $annee) + (4 - date(
"w", mktime(12, 0, 0, $mois, $jour, $annee))) * 24 * 60 * 60;
1707 } elseif (date(
"w", mktime(12, 0, 0, $mois, $jour, $annee)) > 4) {
1708 $jeudiSemaine = mktime(12, 0, 0, $mois, $jour, $annee) - (date(
"w", mktime(12, 0, 0, $mois, $jour, $annee)) - 4) * 24 * 60 * 60;
1710 $jeudiSemaine = mktime(12, 0, 0, $mois, $jour, $annee);
1714 if (date(
"w", mktime(12, 0, 0, 1, 1, date(
"Y", $jeudiSemaine))) == 0) {
1715 $premierJeudiAnnee = mktime(12, 0, 0, 1, 1, date(
"Y", $jeudiSemaine)) + 4 * 24 * 60 * 60;
1716 } elseif (date(
"w", mktime(12, 0, 0, 1, 1, date(
"Y", $jeudiSemaine))) < 4) {
1717 $premierJeudiAnnee = mktime(12, 0, 0, 1, 1, date(
"Y", $jeudiSemaine)) + (4 - date(
"w", mktime(12, 0, 0, 1, 1, date(
"Y", $jeudiSemaine)))) * 24 * 60 * 60;
1718 } elseif (date(
"w", mktime(12, 0, 0, 1, 1, date(
"Y", $jeudiSemaine))) > 4) {
1719 $premierJeudiAnnee = mktime(12, 0, 0, 1, 1, date(
"Y", $jeudiSemaine)) + (7 - (date(
"w", mktime(12, 0, 0, 1, 1, date(
"Y", $jeudiSemaine))) - 4)) * 24 * 60 * 60;
1722 $premierJeudiAnnee = mktime(12, 0, 0, 1, 1, date(
"Y", $jeudiSemaine));
1728 date(
"z", mktime(12, 0, 0, date(
"m", $jeudiSemaine), date(
"d", $jeudiSemaine), date(
"Y", $jeudiSemaine)))
1730 date(
"z", mktime(12, 0, 0, date(
"m", $premierJeudiAnnee), date(
"d", $premierJeudiAnnee), date(
"Y", $premierJeudiAnnee)))
1735 if ($numeroSemaine == 53) {
1737 if (date(
"w", mktime(12, 0, 0, 1, 1, date(
"Y", $jeudiSemaine))) == 4 || (date(
"w", mktime(12, 0, 0, 1, 1, date(
"Y", $jeudiSemaine))) == 3 && date(
"z", mktime(12, 0, 0, 12, 31, date(
"Y", $jeudiSemaine))) == 365)) {
1738 $numeroSemaine = 53;
1746 return sprintf(
"%02d", $numeroSemaine);
1764 $weight = is_numeric($weight) ? $weight : 0;
1765 while ($from_unit <> $to_unit) {
1766 if ($from_unit > $to_unit) {
1767 $weight = $weight * 10;
1768 $from_unit = $from_unit - 1;
1771 if ($from_unit < $to_unit) {
1772 $weight = $weight / 10;
1773 $from_unit = $from_unit + 1;
1795 if (count($tab) < 1) {
1802 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"user_param";
1803 $sql .=
" WHERE fk_user = ".((int) $user->id);
1804 $sql .=
" AND entity = ".((int) $conf->entity);
1805 $sql .=
" AND param in (";
1807 foreach ($tab as $key => $value) {
1811 $sql .=
"'".$db->escape($key).
"'";
1815 dol_syslog(
"functions2.lib::dol_set_user_param", LOG_DEBUG);
1817 $resql = $db->query($sql);
1824 foreach ($tab as $key => $value) {
1827 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"user_param(fk_user,entity,param,value)";
1828 $sql .=
" VALUES (".((int) $user->id).
",".((int) $conf->entity).
",";
1829 $sql .=
" '".$db->escape($key).
"','".$db->escape($value).
"')";
1831 dol_syslog(
"functions2.lib::dol_set_user_param", LOG_DEBUG);
1832 $result = $db->query($sql);
1838 $user->conf->$key = $value;
1841 unset($user->conf->$key);
1859 if ($reduction == 100) {
1860 $string = $langs->transnoentities(
"Offered");
1862 $string =
vatrate($reduction,
true);
1877 if ($option ==
'smr') {
1878 $osversion = php_uname(
's').
' '.php_uname(
'm').
' '.php_uname(
'r');
1880 $osversion = php_uname();
1893 return phpversion();
1914 return $_SERVER[
"SERVER_SOFTWARE"];
1927 global $conf, $langs;
1932 $sql =
"SELECT nom as id, nom as doc_template_name, libelle as label, description as description";
1933 $sql .=
" FROM ".MAIN_DB_PREFIX.
"document_model";
1934 $sql .=
" WHERE type = '".$db->escape($type).
"'";
1935 $sql .=
" AND entity IN (0,".$conf->entity.
")";
1936 $sql .=
" ORDER BY description DESC";
1938 dol_syslog(
'/core/lib/function2.lib.php::getListOfModels', LOG_DEBUG);
1939 $resql = $db->query($sql);
1941 $num = $db->num_rows(
$resql);
1946 $obj = $db->fetch_object(
$resql);
1950 if (!empty($obj->description)) {
1951 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1953 $const = $obj->description;
1955 $dirtoscan = preg_replace(
'/[\r\n]+/',
',', trim($conf->global->$const));
1957 $listoffiles = array();
1960 $listofdir = explode(
',', $dirtoscan);
1961 foreach ($listofdir as $key => $tmpdir) {
1962 $tmpdir = trim($tmpdir);
1963 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
1965 unset($listofdir[$key]);
1968 if (is_dir($tmpdir)) {
1970 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'',
'',
'name', SORT_ASC, 0);
1971 if (count($tmpfiles)) {
1972 $listoffiles = array_merge($listoffiles, $tmpfiles);
1977 if (count($listoffiles)) {
1978 foreach ($listoffiles as $record) {
1979 $max = ($maxfilenamelength ? $maxfilenamelength : 28);
1980 $liste[$obj->id.
':'.$record[
'fullname']] =
dol_trunc($record[
'name'], $max,
'middle');
1983 $liste[0] = $obj->label.
': '.$langs->trans(
"None");
1986 if ($type ==
'member' && $obj->doc_template_name ==
'standard') {
1987 global $_Avery_Labels;
1988 include_once DOL_DOCUMENT_ROOT.
'/core/lib/format_cards.lib.php';
1989 foreach ($_Avery_Labels as $key => $val) {
1990 $liste[$obj->id.
':'.$key] = ($obj->label ? $obj->label : $obj->doc_template_name).
' '.$val[
'name'];
1994 $liste[$obj->id] = $obj->label ? $obj->label : $obj->doc_template_name;
2021 if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
2023 if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE)) {
2028 if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)) {
2050 if (!empty($conf->global->MAIN_BUILD_LOGIN_RULE) && $conf->global->MAIN_BUILD_LOGIN_RULE ==
'f.lastname') {
2052 $login .= ($login ?
'.' :
'');
2057 $login .= ($login ?
'.' :
'');
2077 $proxyuse = (empty($conf->global->MAIN_PROXY_USE) ?
false:
true);
2078 $proxyhost = (empty($conf->global->MAIN_PROXY_USE) ?
false:$conf->global->MAIN_PROXY_HOST);
2079 $proxyport = (empty($conf->global->MAIN_PROXY_USE) ?
false:$conf->global->MAIN_PROXY_PORT);
2080 $proxyuser = (empty($conf->global->MAIN_PROXY_USE) ?
false:$conf->global->MAIN_PROXY_USER);
2081 $proxypass = (empty($conf->global->MAIN_PROXY_USE) ?
false:$conf->global->MAIN_PROXY_PASS);
2082 $timeout = (empty($conf->global->MAIN_USE_CONNECT_TIMEOUT) ? 10 : $conf->global->MAIN_USE_CONNECT_TIMEOUT);
2083 $response_timeout = (empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT) ? 30 : $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
2086 $params = array(
'connection_timeout'=>$timeout,
2087 'response_timeout'=>$response_timeout,
2089 'proxy_host' => $proxyhost,
2090 'proxy_port' => $proxyport,
2091 'proxy_login' => $proxyuser,
2092 'proxy_password' => $proxypass,
2096 $params = array(
'connection_timeout'=>$timeout,
2097 'response_timeout'=>$response_timeout,
2099 'proxy_host' =>
false,
2100 'proxy_port' =>
false,
2101 'proxy_login' =>
false,
2102 'proxy_password' =>
false,
2121 global $db, $conf, $langs;
2127 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $objecttype, $regs)) {
2128 $myobject = $regs[1];
2132 $module = $myobject = $objecttype;
2133 if (preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
2135 $myobject = $regs[2];
2140 $classpath = $module.
'/class';
2143 if ($objecttype ==
'facture' || $objecttype ==
'invoice') {
2144 $langs->load(
'bills');
2145 $classpath =
'compta/facture/class';
2146 $module =
'facture';
2147 $myobject =
'facture';
2148 } elseif ($objecttype ==
'commande' || $objecttype ==
'order') {
2149 $langs->load(
'orders');
2150 $classpath =
'commande/class';
2151 $module =
'commande';
2152 $myobject =
'commande';
2153 } elseif ($objecttype ==
'propal') {
2154 $langs->load(
'propal');
2155 $classpath =
'comm/propal/class';
2156 } elseif ($objecttype ==
'supplier_proposal') {
2157 $langs->load(
'supplier_proposal');
2158 $classpath =
'supplier_proposal/class';
2159 } elseif ($objecttype ==
'shipping') {
2160 $langs->load(
'sendings');
2161 $classpath =
'expedition/class';
2162 $myobject =
'expedition';
2163 $module =
'expedition_bon';
2164 } elseif ($objecttype ==
'delivery') {
2165 $langs->load(
'deliveries');
2166 $classpath =
'delivery/class';
2167 $myobject =
'delivery';
2168 $module =
'delivery_note';
2169 } elseif ($objecttype ==
'contract') {
2170 $langs->load(
'contracts');
2171 $classpath =
'contrat/class';
2172 $module =
'contrat';
2173 $myobject =
'contrat';
2174 } elseif ($objecttype ==
'member') {
2175 $langs->load(
'members');
2176 $classpath =
'adherents/class';
2177 $module =
'adherent';
2178 $myobject =
'adherent';
2179 } elseif ($objecttype ==
'cabinetmed_cons') {
2180 $classpath =
'cabinetmed/class';
2181 $module =
'cabinetmed';
2182 $myobject =
'cabinetmedcons';
2183 } elseif ($objecttype ==
'fichinter') {
2184 $langs->load(
'interventions');
2185 $classpath =
'fichinter/class';
2186 $module =
'ficheinter';
2187 $myobject =
'fichinter';
2188 } elseif ($objecttype ==
'project') {
2189 $langs->load(
'projects');
2190 $classpath =
'projet/class';
2192 } elseif ($objecttype ==
'task') {
2193 $langs->load(
'projects');
2194 $classpath =
'projet/class';
2197 } elseif ($objecttype ==
'stock') {
2198 $classpath =
'product/stock/class';
2200 $myobject =
'stock';
2201 } elseif ($objecttype ==
'inventory') {
2202 $classpath =
'product/inventory/class';
2204 $myobject =
'inventory';
2205 } elseif ($objecttype ==
'mo') {
2206 $classpath =
'mrp/class';
2209 } elseif ($objecttype ==
'productlot') {
2210 $classpath =
'product/stock/class';
2212 $myobject =
'productlot';
2216 $classfile = strtolower($myobject);
2217 $classname = ucfirst($myobject);
2220 if ($objecttype ==
'invoice_supplier') {
2221 $classfile =
'fournisseur.facture';
2222 $classname =
'FactureFournisseur';
2223 $classpath =
'fourn/class';
2224 $module =
'fournisseur';
2225 } elseif ($objecttype ==
'order_supplier') {
2226 $classfile =
'fournisseur.commande';
2227 $classname =
'CommandeFournisseur';
2228 $classpath =
'fourn/class';
2229 $module =
'fournisseur';
2230 } elseif ($objecttype ==
'supplier_proposal') {
2231 $classfile =
'supplier_proposal';
2232 $classname =
'SupplierProposal';
2233 $classpath =
'supplier_proposal/class';
2234 $module =
'supplier_proposal';
2235 } elseif ($objecttype ==
'stock') {
2236 $classpath =
'product/stock/class';
2237 $classfile =
'entrepot';
2238 $classname =
'Entrepot';
2239 } elseif ($objecttype ==
'facturerec') {
2240 $classpath =
'compta/facture/class';
2241 $classfile =
'facture-rec';
2242 $classname =
'FactureRec';
2243 $module =
'facture';
2244 } elseif ($objecttype ==
'mailing') {
2245 $classpath =
'comm/mailing/class';
2246 $classfile =
'mailing';
2247 $classname =
'Mailing';
2253 if (class_exists($classname)) {
2254 $object =
new $classname($db);
2255 $res = $object->fetch($objectid);
2257 $ret = $object->getNomUrl($withpicto, $option);
2258 } elseif ($res == 0) {
2259 $ret = $langs->trans(
'Deleted');
2263 dol_syslog(
"Class with classname ".$classname.
" is unknown even after the include", LOG_ERR);
2282 $listofid = array();
2283 $listofparentid = array();
2286 $sql =
"SELECT rowid, ".$fieldfkparent.
" as parent_id FROM ".MAIN_DB_PREFIX.$tabletocleantree;
2287 $resql = $db->query($sql);
2289 $num = $db->num_rows(
$resql);
2292 $obj = $db->fetch_object(
$resql);
2293 $listofid[] = $obj->rowid;
2294 if ($obj->parent_id > 0) {
2295 $listofparentid[$obj->rowid] = $obj->parent_id;
2303 if (count($listofid)) {
2304 print
'Code requested to clean tree (may be to solve data corruption), so we check/clean orphelins and loops.'.
"<br>\n";
2307 $sql =
"UPDATE ".MAIN_DB_PREFIX.$tabletocleantree.
" SET ".$fieldfkparent.
" = 0 WHERE ".$fieldfkparent.
" = rowid";
2308 $resql = $db->query($sql);
2310 $nb = $db->affected_rows($sql);
2312 print
'<br>Some record that were parent of themself were cleaned.';
2320 $listofidtoclean = array();
2321 foreach ($listofparentid as $id => $pid) {
2326 $arrayidparsed = array();
2327 while ($cursor > 0) {
2328 $arrayidparsed[$cursor] = 1;
2329 if ($arrayidparsed[$listofparentid[$cursor]]) {
2330 print
'Found a loop between id '.$id.
' - '.$cursor.
'<br>';
2331 unset($arrayidparsed);
2332 $listofidtoclean[$cursor] = $id;
2335 $cursor = $listofparentid[$cursor];
2338 if (count($listofidtoclean)) {
2343 $sql =
"UPDATE ".MAIN_DB_PREFIX.$tabletocleantree;
2344 $sql .=
" SET ".$fieldfkparent.
" = 0";
2345 $sql .=
" WHERE rowid IN (".$db->sanitize(join(
',', $listofidtoclean)).
")";
2346 $resql = $db->query($sql);
2348 $nb = $db->affected_rows($sql);
2351 print
'<br>Some records were detected to have parent that is a child, we set them as root record for id: ';
2352 print join(
',', $listofidtoclean);
2360 $sql =
"UPDATE ".MAIN_DB_PREFIX.$tabletocleantree;
2361 $sql .=
" SET ".$fieldfkparent.
" = 0";
2362 $sql .=
" WHERE ".$fieldfkparent.
" NOT IN (".$db->sanitize(join(
',', $listofid), 1).
")";
2363 $resql = $db->query($sql);
2365 $nb = $db->affected_rows($sql);
2368 print
'<br>Some orphelins were found and modified to be parent so records are visible again for id: ';
2369 print join(
',', $listofid);
2376 print
'<br>We fixed '.$totalnb.
' record(s). Some records may still be corrupted. New check may be required.';
2393 if (!is_array($arraycolor)) {
2394 return $colorifnotfound;
2396 if (empty($arraycolor)) {
2397 return $colorifnotfound;
2399 return sprintf(
"%02s", dechex($arraycolor[0])).sprintf(
"%02s", dechex($arraycolor[1])).sprintf(
"%02s", dechex($arraycolor[2]));
2414 if (is_array($stringcolor)) {
2415 return $stringcolor;
2418 $tmp = preg_match(
'/^#?([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])$/', $stringcolor, $reg);
2420 $tmp = explode(
',', $stringcolor);
2421 if (count($tmp) < 3) {
2422 return $colorifnotfound;
2426 return array(hexdec($reg[1]), hexdec($reg[2]), hexdec($reg[3]));
2436 if (!$allow_white && ($color ===
'#fff' || $color ===
'#ffffff')) {
2440 if (preg_match(
'/^#[a-f0-9]{6}$/i', $color)) {
2457 if (empty($ratio)) {
2462 $ratio = max(-100, min(100, $ratio));
2465 $hex = str_replace(
'#',
'', $hex);
2466 if (strlen($hex) == 3) {
2467 $hex = str_repeat(substr($hex, 0, 1), 2).str_repeat(substr($hex, 1, 1), 2).str_repeat(substr($hex, 2, 1), 2);
2471 $color_parts = str_split($hex, 2);
2474 foreach ($color_parts as $color) {
2475 $color = hexdec($color);
2478 $color += ((255 - $color) * ($ratio / 100));
2481 $color -= ($color * ($ratio / 100));
2486 $color -= (($color - 128) * (abs($ratio) / 100));
2489 $color += ((128 - $color) * (abs($ratio) / 100));
2492 if ($brightness > 0) {
2493 $color = ($color * (100 + abs($brightness)) / 100);
2495 $color = ($color * (100 - abs($brightness)) / 100);
2498 $color = max(0, min(255, $color));
2499 $return .= str_pad(dechex($color), 2,
'0', STR_PAD_LEFT);
2515 $steps = max(-255, min(255, $steps));
2518 $hex = str_replace(
'#',
'', $hex);
2519 if (strlen($hex) == 3) {
2520 $hex = str_repeat(substr($hex, 0, 1), 2).str_repeat(substr($hex, 1, 1), 2).str_repeat(substr($hex, 2, 1), 2);
2524 $color_parts = str_split($hex, 2);
2527 foreach ($color_parts as $color) {
2528 $color = hexdec($color);
2529 $color = max(0, min(255, $color + $steps));
2530 $return .= str_pad(dechex($color), 2,
'0', STR_PAD_LEFT);
2543 $steps = intval(255 * $percent / 100) * -1;
2554 $steps = intval(255 * $percent / 100);
2568 $hex = str_replace(
'#',
'', $hex);
2569 $length = strlen($hex);
2571 $rgb[
'r'] = hexdec($length == 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0));
2572 $rgb[
'g'] = hexdec($length == 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0));
2573 $rgb[
'b'] = hexdec($length == 6 ? substr($hex, 4, 2) : ($length == 3 ? str_repeat(substr($hex, 2, 1), 2) : 0));
2574 if ($alpha !==
false) {
2575 $rgb[
'a'] = floatval($alpha);
2576 $string =
'rgba('.implode(
',', $rgb).
')';
2578 $string =
'rgb('.implode(
',', $rgb).
')';
2599 $input = array_filter($input);
2601 $result = array(array());
2603 foreach ($input as $key => $values) {
2606 foreach ($result as $product) {
2607 foreach ($values as $item) {
2608 $product[$key] = $item;
2609 $append[] = $product;
2628 $moduledirforclass = $moduleobject;
2629 if ($moduledirforclass !=
'api') {
2630 $moduledirforclass = preg_replace(
'/api$/i',
'', $moduledirforclass);
2633 if ($moduleobject ==
'contracts') {
2634 $moduledirforclass =
'contrat';
2635 } elseif (in_array($moduleobject, array(
'admin',
'login',
'setup',
'access',
'status',
'tools',
'documents'))) {
2636 $moduledirforclass =
'api';
2637 } elseif ($moduleobject ==
'contact' || $moduleobject ==
'contacts' || $moduleobject ==
'customer' || $moduleobject ==
'thirdparty' || $moduleobject ==
'thirdparties') {
2638 $moduledirforclass =
'societe';
2639 } elseif ($moduleobject ==
'propale' || $moduleobject ==
'proposals') {
2640 $moduledirforclass =
'comm/propal';
2641 } elseif ($moduleobject ==
'agenda' || $moduleobject ==
'agendaevents') {
2642 $moduledirforclass =
'comm/action';
2643 } elseif ($moduleobject ==
'adherent' || $moduleobject ==
'members' || $moduleobject ==
'memberstypes' || $moduleobject ==
'subscriptions') {
2644 $moduledirforclass =
'adherents';
2645 } elseif ($moduleobject ==
'don' || $moduleobject ==
'donations') {
2646 $moduledirforclass =
'don';
2647 } elseif ($moduleobject ==
'banque' || $moduleobject ==
'bankaccounts') {
2648 $moduledirforclass =
'compta/bank';
2649 } elseif ($moduleobject ==
'category' || $moduleobject ==
'categorie') {
2650 $moduledirforclass =
'categories';
2651 } elseif ($moduleobject ==
'order' || $moduleobject ==
'orders') {
2652 $moduledirforclass =
'commande';
2653 } elseif ($moduleobject ==
'shipments') {
2654 $moduledirforclass =
'expedition';
2655 } elseif ($moduleobject ==
'multicurrencies') {
2656 $moduledirforclass =
'multicurrency';
2657 } elseif ($moduleobject ==
'facture' || $moduleobject ==
'invoice' || $moduleobject ==
'invoices') {
2658 $moduledirforclass =
'compta/facture';
2659 } elseif ($moduleobject ==
'project' || $moduleobject ==
'projects' || $moduleobject ==
'task' || $moduleobject ==
'tasks') {
2660 $moduledirforclass =
'projet';
2661 } elseif ($moduleobject ==
'stock' || $moduleobject ==
'stockmovements' || $moduleobject ==
'warehouses') {
2662 $moduledirforclass =
'product/stock';
2663 } elseif ($moduleobject ==
'supplierproposals' || $moduleobject ==
'supplierproposal' || $moduleobject ==
'supplier_proposal') {
2664 $moduledirforclass =
'supplier_proposal';
2665 } elseif ($moduleobject ==
'fournisseur' || $moduleobject ==
'supplierinvoices' || $moduleobject ==
'supplierorders') {
2666 $moduledirforclass =
'fourn';
2667 } elseif ($moduleobject ==
'ficheinter' || $moduleobject ==
'interventions') {
2668 $moduledirforclass =
'fichinter';
2669 } elseif ($moduleobject ==
'mos') {
2670 $moduledirforclass =
'mrp';
2671 } elseif (in_array($moduleobject, array(
'products',
'expensereports',
'users',
'tickets',
'boms',
'receptions'))) {
2672 $moduledirforclass = preg_replace(
'/s$/',
'', $moduleobject);
2675 return $moduledirforclass;
2687 return str_pad(dechex(mt_rand($min, $max)), 2,
'0', STR_PAD_LEFT);
2699 return randomColorPart($min, $max).randomColorPart($min, $max).randomColorPart($min, $max);
2703 if (!function_exists(
'dolEscapeXML')) {
2710 function dolEscapeXML($string)
2712 return strtr($string, array(
'\''=>
''',
'"'=>
'"',
'&'=>
'&',
'<'=>
'<',
'>'=>
'>'));
2725 global $dolibarr_main_url_root;
2727 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2728 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2730 $notetoshow = preg_replace(
'/src="[a-zA-Z0-9_\/\-\.]*(viewimage\.php\?modulepart=medias[^"]*)"/',
'src="'.$urlwithroot.
'/\1"', $notetoshow);
2747 if (empty($amount)) {
2750 $amount = (is_numeric($amount) ? $amount : 0);
2753 $nbdecimal = (empty($conf->global->ACCOUNTING_FEC_DECIMAL_LENGTH) ? 2 : $conf->global->ACCOUNTING_FEC_DECIMAL_LENGTH);
2756 $dec = (empty($conf->global->ACCOUNTING_FEC_DECIMAL_SEPARATOR) ?
',' : $conf->global->ACCOUNTING_FEC_DECIMAL_SEPARATOR);
2757 $thousand = (empty($conf->global->ACCOUNTING_FEC_THOUSAND_SEPARATOR) ?
'' : $conf->global->ACCOUNTING_FEC_THOUSAND_SEPARATOR);
2760 $output = number_format($amount, $nbdecimal, $dec, $thousand);
2773 if (!defined(
"CR")) {
2776 if (!defined(
"LF")) {
2779 if (!defined(
"CRLF")) {
2780 define(
"CRLF",
"\r\n");
2785 foreach (token_get_all(
'<?php '.$code) as $token) {
2786 if (is_array($token)) {
2787 switch ($token[0]) {
2789 case T_DOLLAR_OPEN_CURLY_BRACES:
2790 case T_START_HEREDOC:
2797 } elseif ($inString & 1) {
2828 $inString = @ini_set(
'log_errors',
false);
2829 $token = @ini_set(
'display_errors',
true);
2831 $code = substr($code, strlen(
'<?php '));
2832 $braces || $code =
"if(0){{$code}\n}";
2833 if (eval($code) ===
false) {
2835 $braces = PHP_INT_MAX;
2837 false !== strpos($code, CR) && $code = strtr(str_replace(CRLF, LF, $code), CR, LF);
2838 $braces = substr_count($code, LF);
2840 $code = ob_get_clean();
2841 $code = strip_tags($code);
2842 if (preg_match(
"'syntax error, (.+) in .+ on line (\d+)$'s", $code, $code)) {
2843 $code[2] = (int) $code[2];
2844 $code = $code[2] <= $braces
2845 ? array($code[1], $code[2])
2846 : array(
'unexpected $end'.substr($code[1], 14), $braces);
2848 $code = array(
'syntax error', 0);
2854 @ini_set(
'display_errors', $token);
2855 @ini_set(
'log_errors', $inString);
2873 $acceptlocallinktomedia =
getDolGlobalInt(
'MAIN_DISALLOW_MEDIAS_IN_EMAIL_TEMPLATES') ? 0 : 1;
2874 if ($acceptlocallinktomedia) {
2875 global $dolibarr_main_url_root;
2876 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2879 $newUrlArray = parse_url($urlwithouturlroot);
2880 $hosttocheck = $newUrlArray[
'host'];
2881 $hosttocheck = str_replace(array(
'[',
']'),
'', $hosttocheck);
2883 if (function_exists(
'gethostbyname')) {
2884 $iptocheck = gethostbyname($hosttocheck);
2886 $iptocheck = $hosttocheck;
2890 if (!filter_var($iptocheck, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
2892 $acceptlocallinktomedia = 0;
2896 if (preg_match(
'/http:/i', $urlwithouturlroot)) {
2898 $acceptlocallinktomedia = 0;
2902 if (!empty($user->socid)) {
2903 $acceptlocallinktomedia = 0;
2908 return $acceptlocallinktomedia;
Class to manage translations.
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
getServerTimeZoneInt($refgmtdate='now')
Return server timezone int.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
array2table($data, $tableMarkup=1, $tableoptions='', $troptions='', $tdoptions='')
Return an html table from an array.
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
colorHexToRgb($hex, $alpha=false, $returnArray=false)
get_string_between($string, $start, $end)
Get string between.
dolObfuscateEmail($mail, $replace="*", $nbreplace=8, $nbdisplaymail=4, $nbdisplaydomain=3, $displaytld=true)
Returns an email value with obfuscated parts.
version_webserver()
Return web server version.
getModuleDirForApiClass($moduleobject)
Get name of directory where the api_...class.php file is stored.
phpSyntaxError($code)
Check the syntax of some PHP code.
dolGetModulesDirs($subdir='')
Return list of modules directories.
array2tr($data, $troptions='', $tdoptions='')
Return lines of an html table from an array Used by array2table function only.
version_dolibarr()
Return Dolibarr version.
binhex($bin, $pad=false, $upper=false)
Convert a binary data to string that represent hexadecimal value.
colorAgressiveness($hex, $ratio=-50, $brightness=0)
Change color to make it less aggressive (ratio is negative) or more aggressive (ratio is positive)
cartesianArray(array $input)
Applies the Cartesian product algorithm to an array Source: http://stackoverflow.com/a/15973172.
getSoapParams()
Return array to use for SoapClient constructor.
colorAdjustBrightness($hex, $steps)
cleanCorruptedTree($db, $tabletocleantree, $fieldfkparent)
Clean corrupted tree (orphelins linked to a not existing parent), record linked to themself and child...
colorArrayToHex($arraycolor, $colorifnotfound='888888')
Convert an array with RGB value into hex RGB value.
dol_print_reduction($reduction, $langs)
Returns formated reduction.
dol_print_file($langs, $filename, $searchalt=0)
Output content of a file $filename in version of current language (otherwise may use an alternate lan...
colorStringToArray($stringcolor, $colorifnotfound=array(88, 88, 88))
Convert a string RGB value ('FFFFFF', '255,255,255') into an array RGB array(255,255,...
acceptLocalLinktoMedia()
Check the syntax of some PHP code.
randomColor($min=0, $max=255)
Return hexadecimal color randomly.
is_ip($ip)
This function evaluates a string that should be a valid IPv4 Note: For ip 169.254....
check_value($mask, $value)
Check value.
weight_convert($weight, &$from_unit, $to_unit)
Convertit une masse d'une unite vers une autre unite.
clean_url($url, $http=1)
Clean an url string.
version_php()
Return PHP version.
hexbin($hexa)
Convert an hexadecimal string into a binary string.
dol_set_user_param($db, $conf, &$user, $tab)
Save personnal parameter.
numero_semaine($time)
Retourne le numero de la semaine par rapport a une date.
randomColorPart($min=0, $max=255)
Return 2 hexa code randomly.
if(!function_exists('dolEscapeXML')) convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
colorDarker($hex, $percent)
dolGetElementUrl($objectid, $objecttype, $withpicto=0, $option='')
Return link url to an object.
getListOfModels($db, $type, $maxfilenamelength=0)
Return list of activated modules usable for document generation.
dol_print_object_info($object, $usetable=0)
Show informations on an object TODO Move this into html.formother.
get_next_value($db, $mask, $table, $field, $where='', $objsoc='', $date='', $mode='next', $bentityon=true, $objuser=null, $forceentity=null)
Return last or next value for a mask (according to area we should not reset)
isValidUrl($url, $http=0, $pass=0, $port=0, $path=0, $query=0, $anchor=0)
Url string validation <http[s]> :// [user[:pass]@] hostname [port] [/path] [?getquery] [anchor].
isValidMailDomain($mail)
Return true if email has a domain name that can be resolved to MX type.
dolAddEmailTrackId($email, $trackingid)
Return an email formatted to include a tracking id For example myemail@example.com becom myemail+trac...
colorLighten($hex, $percent)
isValidVATID($company)
Check if VAT numero is valid (check done on syntax only, no database or remote access)
version_os($option='')
Return OS version.
dol_getDefaultFormat(Translate $outputlangs=null)
Try to guess default paper format according to language into $langs.
price2fec($amount)
Function to format a value into a defined format for French administration (no thousand separator & d...
jsUnEscape($source)
Same function than javascript unescape() function but in PHP.
colorValidateHex($color, $allow_white=true)
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
isValidMXRecord($domain)
Return if the domain name has a valid MX record.
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='')
Clean a string from all punctuation characters to use it as a ref or login.
dol_substr($string, $start, $length, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
isModEnabled($module)
Is Dolibarr module enabled.
utf8_check($str)
Check if a string is in UTF8.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.