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)
89 if ($type ===
'main') {
90 $modulesdir[$dirroot.
'/core/modules'.$subdir.
'/'] = $dirroot.
'/core/modules'.$subdir.
'/';
94 $handle = @opendir($dirroot);
95 if (is_resource($handle))
97 while (($file = readdir($handle)) !==
false)
99 if (preg_match(
'/disabled/', $file))
continue;
101 if (is_dir($dirroot.
'/'.$file) && substr($file, 0, 1) <>
'.' && substr($file, 0, 3) <>
'CVS' && $file !=
'includes')
103 if (is_dir($dirroot.
'/'.$file.
'/core/modules'.$subdir.
'/'))
105 $modulesdir[$dirroot.
'/'.$file.
'/core/modules'.$subdir.
'/'] = $dirroot.
'/'.$file.
'/core/modules'.$subdir.
'/';
128 $outputlangs = $langs;
131 if ($outputlangs->defaultlang ==
'ca_CA') $selected =
'CAP4';
132 if ($outputlangs->defaultlang ==
'en_US') $selected =
'USLetter';
149 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))
155 $content = file_get_contents($formfile);
157 if (!$isutf8 && $conf->file->character_set_client ==
'UTF-8')
print utf8_encode($content);
158 elseif ($isutf8 && $conf->file->character_set_client ==
'ISO-8859-1')
print utf8_decode($content);
161 }
else dol_syslog(
'functions2::dol_print_file not found', LOG_DEBUG);
165 if ($langs->defaultlang !=
"en_US") $formfilealt = $searchdir.
"/langs/en_US/".$filename;
166 else $formfilealt = $searchdir.
"/langs/fr_FR/".$filename;
167 dol_syslog(
'functions2::dol_print_file search alt file '.$formfilealt, LOG_DEBUG);
169 if (is_readable($formfilealt))
171 $content = file_get_contents($formfilealt);
173 if (!$isutf8 && $conf->file->character_set_client ==
'UTF-8')
print utf8_encode($content);
174 elseif ($isutf8 && $conf->file->character_set_client ==
'ISO-8859-1')
print utf8_decode($content);
177 }
else dol_syslog(
'functions2::dol_print_file not found', LOG_DEBUG);
197 $langs->loadLangs(array(
'other',
'admin'));
199 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
202 $deltadateforclient = ((int) $_SESSION[
'dol_tz'] + (
int) $_SESSION[
'dol_dst']);
204 $deltadateforuser = round($deltadateforclient - $deltadateforserver);
207 if ($usetable)
print '<table class="border tableforfield centpercent">';
210 if (!empty($object->import_key))
212 if ($usetable)
print '<tr><td class="titlefield">';
213 print $langs->trans(
"ImportedWithSet");
214 if ($usetable)
print '</td><td>';
216 print $object->import_key;
217 if ($usetable)
print '</td></tr>';
222 if (!empty($object->user_creation) || !empty($object->user_creation_id))
224 if ($usetable)
print '<tr><td class="titlefield">';
225 print $langs->trans(
"CreatedBy");
226 if ($usetable)
print '</td><td>';
228 if (is_object($object->user_creation))
230 if ($object->user_creation->id)
print $object->user_creation->getNomUrl(-1,
'', 0, 0, 0);
231 else print $langs->trans(
"Unknown");
233 $userstatic =
new User($db);
234 $userstatic->fetch($object->user_creation_id ? $object->user_creation_id : $object->user_creation);
235 if ($userstatic->id)
print $userstatic->getNomUrl(-1,
'', 0, 0, 0);
236 else print $langs->trans(
"Unknown");
238 if ($usetable)
print '</td></tr>';
243 if (!empty($object->date_creation))
245 if ($usetable)
print '<tr><td class="titlefield">';
246 print $langs->trans(
"DateCreation");
247 if ($usetable)
print '</td><td>';
250 if ($deltadateforuser)
print ' '.$langs->trans(
"CurrentHour").
' / '.
dol_print_date($object->date_creation,
"dayhour",
"tzuserrel").
' '.$langs->trans(
"ClientHour");
251 if ($usetable)
print '</td></tr>';
256 if (!empty($object->user_modification) || !empty($object->user_modification_id))
258 if ($usetable)
print '<tr><td class="titlefield">';
259 print $langs->trans(
"ModifiedBy");
260 if ($usetable)
print '</td><td>';
262 if (is_object($object->user_modification))
264 if ($object->user_modification->id)
print $object->user_modification->getNomUrl(-1,
'', 0, 0, 0);
265 else print $langs->trans(
"Unknown");
267 $userstatic =
new User($db);
268 $userstatic->fetch($object->user_modification_id ? $object->user_modification_id : $object->user_modification);
269 if ($userstatic->id)
print $userstatic->getNomUrl(-1,
'', 0, 0, 0);
270 else print $langs->trans(
"Unknown");
272 if ($usetable)
print '</td></tr>';
277 if (!empty($object->date_modification))
279 if ($usetable)
print '<tr><td class="titlefield">';
280 print $langs->trans(
"DateLastModification");
281 if ($usetable)
print '</td><td>';
284 if ($deltadateforuser)
print ' '.$langs->trans(
"CurrentHour").
' / '.
dol_print_date($object->date_modification,
"dayhour",
"tzuserrel").
' '.$langs->trans(
"ClientHour");
285 if ($usetable)
print '</td></tr>';
290 if (!empty($object->user_validation) || !empty($object->user_validation_id))
292 if ($usetable)
print '<tr><td class="titlefield">';
293 print $langs->trans(
"ValidatedBy");
294 if ($usetable)
print '</td><td>';
296 if (is_object($object->user_validation))
298 if ($object->user_validation->id)
print $object->user_validation->getNomUrl(-1,
'', 0, 0, 0);
299 else print $langs->trans(
"Unknown");
301 $userstatic =
new User($db);
302 $userstatic->fetch($object->user_validation_id ? $object->user_validation_id : $object->user_validation);
303 if ($userstatic->id)
print $userstatic->getNomUrl(-1,
'', 0, 0, 0);
304 else print $langs->trans(
"Unknown");
306 if ($usetable)
print '</td></tr>';
311 if (!empty($object->date_validation))
313 if ($usetable)
print '<tr><td class="titlefield">';
314 print $langs->trans(
"DateValidation");
315 if ($usetable)
print '</td><td>';
318 if ($deltadateforuser)
print ' '.$langs->trans(
"CurrentHour").
' / '.
dol_print_date($object->date_validation,
"dayhour",
'tzuserrel').
' '.$langs->trans(
"ClientHour");
319 if ($usetable)
print '</td></tr>';
324 if (!empty($object->user_approve) || !empty($object->user_approve_id))
326 if ($usetable)
print '<tr><td class="titlefield">';
327 print $langs->trans(
"ApprovedBy");
328 if ($usetable)
print '</td><td>';
330 if (is_object($object->user_approve))
332 if ($object->user_approve->id)
print $object->user_approve->getNomUrl(-1,
'', 0, 0, 0);
333 else print $langs->trans(
"Unknown");
335 $userstatic =
new User($db);
336 $userstatic->fetch($object->user_approve_id ? $object->user_approve_id : $object->user_approve);
337 if ($userstatic->id)
print $userstatic->getNomUrl(-1,
'', 0, 0, 0);
338 else print $langs->trans(
"Unknown");
340 if ($usetable)
print '</td></tr>';
345 if (!empty($object->date_approve))
347 if ($usetable)
print '<tr><td class="titlefield">';
348 print $langs->trans(
"DateApprove");
349 if ($usetable)
print '</td><td>';
352 if ($deltadateforuser)
print ' '.$langs->trans(
"CurrentHour").
' / '.
dol_print_date($object->date_approve,
"dayhour",
'tzuserrel').
' '.$langs->trans(
"ClientHour");
353 if ($usetable)
print '</td></tr>';
358 if (!empty($object->user_approve_id2))
360 if ($usetable)
print '<tr><td class="titlefield">';
361 print $langs->trans(
"ApprovedBy");
362 if ($usetable)
print '</td><td>';
364 $userstatic =
new User($db);
365 $userstatic->fetch($object->user_approve_id2);
366 if ($userstatic->id)
print $userstatic->getNomUrl(-1,
'', 0, 0, 0);
367 else print $langs->trans(
"Unknown");
368 if ($usetable)
print '</td></tr>';
373 if (!empty($object->date_approve2))
375 if ($usetable)
print '<tr><td class="titlefield">';
376 print $langs->trans(
"DateApprove2");
377 if ($usetable)
print '</td><td>';
380 if ($deltadateforuser)
print ' '.$langs->trans(
"CurrentHour").
' / '.
dol_print_date($object->date_approve2,
"dayhour",
'tzuserrel').
' '.$langs->trans(
"ClientHour");
381 if ($usetable)
print '</td></tr>';
386 if (!empty($object->user_cloture) || !empty($object->user_closing))
388 if (isset($object->user_cloture) && !empty($object->user_cloture)) $object->user_closing = $object->user_cloture;
389 if ($usetable)
print '<tr><td class="titlefield">';
390 print $langs->trans(
"ClosedBy");
391 if ($usetable)
print '</td><td>';
393 if (is_object($object->user_closing))
395 if ($object->user_closing->id)
print $object->user_closing->getNomUrl(-1,
'', 0, 0, 0);
396 else print $langs->trans(
"Unknown");
398 $userstatic =
new User($db);
399 $userstatic->fetch($object->user_closing);
400 if ($userstatic->id)
print $userstatic->getNomUrl(-1,
'', 0, 0, 0);
401 else print $langs->trans(
"Unknown");
403 if ($usetable)
print '</td></tr>';
408 if (!empty($object->date_cloture) || !empty($object->date_closing))
410 if (isset($object->date_cloture) && !empty($object->date_cloture)) $object->date_closing = $object->date_cloture;
411 if ($usetable)
print '<tr><td class="titlefield">';
412 print $langs->trans(
"DateClosing");
413 if ($usetable)
print '</td><td>';
416 if ($deltadateforuser)
print ' '.$langs->trans(
"CurrentHour").
' / '.
dol_print_date($object->date_closing,
"dayhour",
'tzuserrel').
' '.$langs->trans(
"ClientHour");
417 if ($usetable)
print '</td></tr>';
422 if (!empty($object->user_rappro))
424 if ($usetable)
print '<tr><td class="titlefield">';
425 print $langs->trans(
"ConciliatedBy");
426 if ($usetable)
print '</td><td>';
428 if (is_object($object->user_rappro))
430 if ($object->user_rappro->id)
print $object->user_rappro->getNomUrl(-1,
'', 0, 0, 0);
431 else print $langs->trans(
"Unknown");
433 $userstatic =
new User($db);
434 $userstatic->fetch($object->user_rappro);
435 if ($userstatic->id)
print $userstatic->getNomUrl(1,
'', 0, 0, 0);
436 else print $langs->trans(
"Unknown");
438 if ($usetable)
print '</td></tr>';
443 if (!empty($object->date_rappro))
445 if ($usetable)
print '<tr><td class="titlefield">';
446 print $langs->trans(
"DateConciliating");
447 if ($usetable)
print '</td><td>';
450 if ($deltadateforuser)
print ' '.$langs->trans(
"CurrentHour").
' / '.
dol_print_date($object->date_rappro,
"dayhour",
'tzuserrel').
' '.$langs->trans(
"ClientHour");
451 if ($usetable)
print '</td></tr>';
456 if (!empty($object->date_envoi))
458 if ($usetable)
print '<tr><td class="titlefield">';
459 print $langs->trans(
"DateLastSend");
460 if ($usetable)
print '</td><td>';
463 if ($deltadateforuser)
print ' '.$langs->trans(
"CurrentHour").
' / '.
dol_print_date($object->date_envoi,
"dayhour",
'tzuserrel').
' '.$langs->trans(
"ClientHour");
464 if ($usetable)
print '</td></tr>';
468 if ($usetable)
print '</table>';
482 $tmp = explode(
'@', $email);
483 return $tmp[0].
'+'.$trackingid.
'@'.(isset($tmp[1]) ? $tmp[1] :
'');
494 list($user, $domain) = explode(
"@", $mail, 2);
511 function isValidUrl($url, $http = 0, $pass = 0, $port = 0, $path = 0, $query = 0, $anchor = 0)
517 if ($http) $urlregex .=
"^(http:\/\/|https:\/\/)";
520 if ($pass) $urlregex .=
"([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)";
525 $urlregex .=
"([a-z0-9+\$_\\\:-])+(\.[a-z0-9+\$_-][a-z0-9+\$_-]+)*";
529 if ($port) $urlregex .=
"(\:[0-9]{2,5})";
531 if ($path) $urlregex .=
"(\/([a-z0-9+\$_-]\.?)+)*\/";
533 if ($query) $urlregex .=
"(\?[a-z+&\$_.-][a-z0-9;:@\/&%=+\$_.-]*)";
535 if ($anchor) $urlregex .=
"(#[a-z_.-][a-z0-9+\$_.-]*)$";
538 if (preg_match(
'/'.$urlregex.
'/i', $url))
555 if ($company->isInEEC())
562 $vatprefix =
'[a-zA-Z][a-zA-Z]';
563 if (!preg_match(
'/^'.$vatprefix.
'[a-zA-Z0-9\-\.]{5,14}$/i', str_replace(
' ',
'', $company->tva_intra)))
585 if (preg_match(
'/^(https?:[\\/]+)?([0-9A-Z.-]+\.[A-Z]{2,4})(:[0-9]+)?/i', $url, $regs))
589 $port = isset($regs[3]) ? $regs[3] :
'';
598 if (preg_match(
'/^http:[\\/]+/i', $url))
600 $url = preg_replace(
'/^http:[\\/]+/i',
'', $url);
606 $CleanUrl = preg_replace(
'/^'.preg_quote($proto.$domain,
'/').
'/i', $newproto.strtolower($domain), $url);
625 function dolObfuscateEmail($mail, $replace =
"*", $nbreplace = 8, $nbdisplaymail = 4, $nbdisplaydomain = 3, $displaytld =
true)
628 $tab = explode(
'@', $mail);
629 $tab2 = explode(
'.', $tab[1]);
630 $string_replace =
'';
631 $mail_name = $tab[0];
632 $mail_domaine = $tab2[0];
635 $nbofelem = count($tab2);
636 for ($i = 1; $i < $nbofelem && $displaytld; $i++)
638 $mail_tld .=
'.'.$tab2[$i];
641 for ($i = 0; $i < $nbreplace; $i++) {
642 $string_replace .= $replace;
645 if (strlen($mail_name) > $nbdisplaymail) {
646 $mail_name = substr($mail_name, 0, $nbdisplaymail);
649 if (strlen($mail_domaine) > $nbdisplaydomain) {
650 $mail_domaine = substr($mail_domaine, strlen($mail_domaine) - $nbdisplaydomain);
653 return $mail_name.$string_replace.$mail_domaine.$mail_tld;
666 function array2tr($data, $troptions =
'', $tdoptions =
'')
668 $text =
'<tr '.$troptions.
'>';
669 foreach ($data as $key => $item) {
670 $text .=
'<td '.$tdoptions.
'>'.$item.
'</td>';
686 function array2table($data, $tableMarkup = 1, $tableoptions =
'', $troptions =
'', $tdoptions =
'')
689 if ($tableMarkup) $text =
'<table '.$tableoptions.
'>';
690 foreach ($data as $key => $item) {
691 if (is_array($item)) {
692 $text .=
array2tr($item, $troptions, $tdoptions);
694 $text .=
'<tr '.$troptions.
'>';
695 $text .=
'<td '.$tdoptions.
'>'.$key.
'</td>';
696 $text .=
'<td '.$tdoptions.
'>'.$item.
'</td>';
700 if ($tableMarkup) $text .=
'</table>';
720 function get_next_value($db, $mask, $table, $field, $where =
'', $objsoc =
'', $date =
'', $mode =
'next', $bentityon =
true, $objuser = null, $forceentity = null)
724 if (!is_object($objsoc)) $valueforccc = $objsoc;
725 elseif ($table ==
"commande_fournisseur" || $table ==
"facture_fourn") $valueforccc =
dol_string_unaccent($objsoc->code_fournisseur);
728 $sharetable = $table;
729 if ($table ==
'facture' || $table ==
'invoice') $sharetable =
'invoicenumber';
732 if ($date ==
'') $date =
dol_now();
742 $hasglobalcounter =
false;
745 if (preg_match(
'/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i', $mask, $reg))
747 $masktri = $reg[1].(!empty($reg[2]) ? $reg[2] :
'').(!empty($reg[3]) ? $reg[3] :
'');
748 $maskcounter = $reg[1];
749 $hasglobalcounter =
true;
753 $maskcounter =
'00000';
758 $resetEveryMonth =
false;
759 if (
dol_strlen($maskcounter) < 3 && empty($conf->global->MAIN_COUNTER_WITH_LESS_3_DIGITS))
return 'ErrorCounterMustHaveMoreThan3Digits';
762 $regClientRef = array();
763 if (preg_match(
'/\{(c+)(0*)\}/i', $mask, $regClientRef))
765 $maskrefclient = $regClientRef[1].$regClientRef[2];
766 $maskrefclient_maskclientcode = $regClientRef[1];
767 $maskrefclient_maskcounter = $regClientRef[2];
768 $maskrefclient_maskoffset = 0;
769 $maskrefclient_clientcode = substr($valueforccc, 0,
dol_strlen($maskrefclient_maskclientcode));
770 $maskrefclient_clientcode = str_pad($maskrefclient_clientcode,
dol_strlen($maskrefclient_maskclientcode),
"#", STR_PAD_RIGHT);
772 if (
dol_strlen($maskrefclient_maskcounter) > 0 &&
dol_strlen($maskrefclient_maskcounter) < 3)
return 'ErrorCounterMustHaveMoreThan3Digits';
773 }
else $maskrefclient =
'';
776 if (!$hasglobalcounter && ($maskrefclient_maskcounter ==
''))
778 return 'ErrorBadMask';
783 if (preg_match(
'/\{(t+)\}/i', $mask, $regType))
785 $masktype = $regType[1];
786 $masktype_value = substr(preg_replace(
'/^TE_/',
'', $objsoc->typent_code), 0,
dol_strlen($regType[1]));
787 $masktype_value = str_pad($masktype_value,
dol_strlen($regType[1]),
"#", STR_PAD_RIGHT);
790 $masktype_value =
'';
795 if (preg_match(
'/\{(u+)\}/i', $mask, $regType)) {
796 $lastname =
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
797 if (is_object($objuser)) $lastname = $objuser->lastname;
799 $maskuser = $regType[1];
800 $maskuser_value = substr($lastname, 0,
dol_strlen($regType[1]));
801 $maskuser_value = str_pad($maskuser_value,
dol_strlen($regType[1]),
"#", STR_PAD_RIGHT);
804 $maskuser_value =
'';
808 $maskperso = array();
809 $maskpersonew = array();
812 while (preg_match(
'/\{([A-Z]+)\-([1-9])\}/', $tmpmask, $regKey))
814 $maskperso[$regKey[1]] =
'{'.$regKey[1].
'-'.$regKey[2].
'}';
815 $maskpersonew[$regKey[1]] = str_pad(
'', $regKey[2],
'_', STR_PAD_RIGHT);
816 $tmpmask = preg_replace(
'/\{'.$regKey[1].
'\-'.$regKey[2].
'\}/i', $maskpersonew[$regKey[1]], $tmpmask);
819 if (strstr($mask,
'user_extra_'))
821 $start =
"{user_extra_";
824 if (!empty($user->array_options[
'options_'.$extra])) {
825 $mask = preg_replace(
'#('.$start.
')(.*?)('.$end.
')#si', $user->array_options[
'options_'.$extra], $mask);
828 $maskwithonlyymcode = $mask;
829 $maskwithonlyymcode = preg_replace(
'/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i', $maskcounter, $maskwithonlyymcode);
830 $maskwithonlyymcode = preg_replace(
'/\{dd\}/i',
'dd', $maskwithonlyymcode);
831 $maskwithonlyymcode = preg_replace(
'/\{(c+)(0*)\}/i', $maskrefclient, $maskwithonlyymcode);
832 $maskwithonlyymcode = preg_replace(
'/\{(t+)\}/i', $masktype_value, $maskwithonlyymcode);
833 $maskwithonlyymcode = preg_replace(
'/\{(u+)\}/i', $maskuser_value, $maskwithonlyymcode);
834 foreach ($maskperso as $key => $val)
836 $maskwithonlyymcode = preg_replace(
'/'.preg_quote($val,
'/').
'/i', $maskpersonew[$key], $maskwithonlyymcode);
838 $maskwithnocode = $maskwithonlyymcode;
839 $maskwithnocode = preg_replace(
'/\{yyyy\}/i',
'yyyy', $maskwithnocode);
840 $maskwithnocode = preg_replace(
'/\{yy\}/i',
'yy', $maskwithnocode);
841 $maskwithnocode = preg_replace(
'/\{y\}/i',
'y', $maskwithnocode);
842 $maskwithnocode = preg_replace(
'/\{mm\}/i',
'mm', $maskwithnocode);
849 if (!empty($reg[2]) && preg_match(
'/^\+/', $reg[2])) $maskoffset = preg_replace(
'/^\+/',
'', $reg[2]);
850 if (!empty($reg[3]) && preg_match(
'/^\+/', $reg[3])) $maskoffset = preg_replace(
'/^\+/',
'', $reg[3]);
855 $yearoffsettype =
false;
858 if (!empty($reg[2]) && preg_match(
'/^@/', $reg[2])) $yearoffsettype = preg_replace(
'/^@/',
'', $reg[2]);
859 if (!empty($reg[3]) && preg_match(
'/^@/', $reg[3])) $yearoffsettype = preg_replace(
'/^@/',
'', $reg[3]);
862 if (is_numeric($yearoffsettype) && $yearoffsettype >= 1)
863 $maskraz = $yearoffsettype;
864 elseif ($yearoffsettype ===
'0' || (!empty($yearoffsettype) && !is_numeric($yearoffsettype) && $conf->global->SOCIETE_FISCAL_MONTH_START > 1))
865 $maskraz = $conf->global->SOCIETE_FISCAL_MONTH_START;
869 if ($maskraz == 99) {
870 $maskraz = date(
'm', $date);
871 $resetEveryMonth =
true;
873 if ($maskraz > 12)
return 'ErrorBadMaskBadRazMonth';
878 if (preg_match(
'/^(.*)\{(y+)\}\{(m+)\}/i', $maskwithonlyymcode, $reg)) { $posy = 2; $posm = 3; } elseif (preg_match(
'/^(.*)\{(m+)\}\{(y+)\}/i', $maskwithonlyymcode, $reg)) { $posy = 3; $posm = 2; }
else return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
880 if (
dol_strlen($reg[$posy]) < 2)
return 'ErrorCantUseRazWithYearOnOneDigit';
883 if (preg_match(
'/^(.*)\{(m+)\}\{(y+)\}/i', $maskwithonlyymcode, $reg)) { $posy = 3; $posm = 2; } elseif (preg_match(
'/^(.*)\{(y+)\}\{(m+)\}/i', $maskwithonlyymcode, $reg)) { $posy = 2; $posm = 3; } elseif (preg_match(
'/^(.*)\{(y+)\}/i', $maskwithonlyymcode, $reg)) { $posy = 2; $posm = 0; }
else return 'ErrorCantUseRazIfNoYearInMask';
886 $yearlen = $posy ?
dol_strlen($reg[$posy]) : 0;
887 $monthlen = $posm ?
dol_strlen($reg[$posm]) : 0;
890 $monthpos = ($yearpos + $yearlen);
891 if ($posy == 3 && $posm == 2) {
893 $yearpos = ($monthpos + $monthlen);
898 $monthcomp = $maskraz;
901 if (!empty($yearoffsettype) && !is_numeric($yearoffsettype) && $yearoffsettype !=
'=')
903 $currentyear = date(
"Y", $date);
904 $fiscaldate =
dol_mktime(
'0',
'0',
'0', $maskraz,
'1', $currentyear);
905 $newyeardate =
dol_mktime(
'0',
'0',
'0',
'1',
'1', $currentyear);
906 $nextnewyeardate =
dol_mktime(
'0',
'0',
'0',
'1',
'1', $currentyear + 1);
910 if ($date >= $fiscaldate)
913 if ($date < $nextnewyeardate && $yearoffsettype ==
'+') $yearoffset = 1;
915 elseif ($date >= $newyeardate && $yearoffsettype ==
'-') $yearoffset = -1;
917 elseif (date(
"m", $date) < $maskraz && empty($resetEveryMonth)) { $yearoffset = -1; }
919 if ($yearlen == 4) $yearcomp = sprintf(
"%04d", date(
"Y", $date) + $yearoffset);
920 elseif ($yearlen == 2) $yearcomp = sprintf(
"%02d", date(
"y", $date) + $yearoffset);
921 elseif ($yearlen == 1) $yearcomp = substr(date(
"y", $date), 2, 1) + $yearoffset;
922 if ($monthcomp > 1 && empty($resetEveryMonth))
924 if ($yearlen == 4) $yearcomp1 = sprintf(
"%04d", date(
"Y", $date) + $yearoffset + 1);
925 elseif ($yearlen == 2) $yearcomp1 = sprintf(
"%02d", date(
"y", $date) + $yearoffset + 1);
928 $sqlwhere .=
" (SUBSTRING(".$field.
", ".$yearpos.
", ".$yearlen.
") = '".$db->escape($yearcomp).
"'";
929 $sqlwhere .=
" AND SUBSTRING(".$field.
", ".$monthpos.
", ".$monthlen.
") >= '".str_pad($monthcomp, $monthlen,
'0', STR_PAD_LEFT).
"')";
931 $sqlwhere .=
" (SUBSTRING(".$field.
", ".$yearpos.
", ".$yearlen.
") = '".$db->escape($yearcomp1).
"'";
932 $sqlwhere .=
" AND SUBSTRING(".$field.
", ".$monthpos.
", ".$monthlen.
") < '".str_pad($monthcomp, $monthlen,
'0', STR_PAD_LEFT).
"') ";
934 } elseif ($resetEveryMonth) {
935 $sqlwhere .=
"(SUBSTRING(".$field.
", ".$yearpos.
", ".$yearlen.
") = '".$db->escape($yearcomp).
"'";
936 $sqlwhere .=
" AND SUBSTRING(".$field.
", ".$monthpos.
", ".$monthlen.
") = '".str_pad($monthcomp, $monthlen,
'0', STR_PAD_LEFT).
"')";
938 $sqlwhere .=
'(SUBSTRING('.$field.
', '.$yearpos.
', '.$yearlen.
") = '".$db->escape($yearcomp).
"')";
945 if (function_exists(
'mb_strrpos')) {
946 $posnumstart = mb_strrpos($maskwithnocode, $maskcounter, 0,
'UTF-8');
948 $posnumstart = strrpos($maskwithnocode, $maskcounter);
950 if ($posnumstart < 0)
return 'ErrorBadMaskFailedToLocatePosOfSequence';
951 $sqlstring =
'SUBSTRING('.$field.
', '.($posnumstart + 1).
', '.
dol_strlen($maskcounter).
')';
955 $maskLike = str_replace(
"%",
"_", $maskLike);
958 $maskLike = preg_replace(
'/\{yyyy\}/i',
'____', $maskLike);
959 $maskLike = preg_replace(
'/\{yy\}/i',
'__', $maskLike);
960 $maskLike = preg_replace(
'/\{y\}/i',
'_', $maskLike);
961 $maskLike = preg_replace(
'/\{mm\}/i',
'__', $maskLike);
962 $maskLike = preg_replace(
'/\{dd\}/i',
'__', $maskLike);
964 if ($maskrefclient) $maskLike = str_replace(
dol_string_nospecial(
'{'.$maskrefclient.
'}'), str_pad(
"",
dol_strlen($maskrefclient),
"_"), $maskLike);
965 if ($masktype) $maskLike = str_replace(
dol_string_nospecial(
'{'.$masktype.
'}'), $masktype_value, $maskLike);
966 if ($maskuser) $maskLike = str_replace(
dol_string_nospecial(
'{'.$maskuser.
'}'), $maskuser_value, $maskLike);
967 foreach ($maskperso as $key => $val)
969 $maskLike = str_replace(
dol_string_nospecial($maskperso[$key]), $maskpersonew[$key], $maskLike);
974 $sql =
"SELECT MAX(".$sqlstring.
") as val";
975 $sql .=
" FROM ".MAIN_DB_PREFIX.$table;
976 $sql .=
" WHERE ".$field.
" LIKE '".$db->escape($maskLike).
"'";
977 $sql .=
" AND ".$field.
" NOT LIKE '(PROV%)'";
979 $sql .=
" AND entity IN (".getEntity($sharetable).
")";
980 elseif (!empty($forceentity))
981 $sql .=
" AND entity IN (".$forceentity.
")";
982 if ($where) $sql .= $where;
983 if ($sqlwhere) $sql .=
' AND '.$sqlwhere;
986 dol_syslog(
"functions2::get_next_value mode=".$mode.
"", LOG_DEBUG);
987 $resql = $db->query($sql);
990 $obj = $db->fetch_object(
$resql);
991 $counter = $obj->val;
995 if (empty($counter)) $counter = $maskoffset;
996 elseif (preg_match(
'/[^0-9]/i', $counter))
999 dol_syslog(
"Error, the last counter found is '".$counter.
"' so is not a numeric value. We will restart to 1.", LOG_ERR);
1000 } elseif ($counter < $maskoffset && empty($conf->global->MAIN_NUMBERING_OFFSET_ONLY_FOR_FIRST)) $counter = $maskoffset;
1002 if ($mode ==
'last')
1004 $counterpadded = str_pad($counter,
dol_strlen($maskcounter),
"0", STR_PAD_LEFT);
1008 $maskLike = str_replace(
"%",
"_", $maskLike);
1010 $maskLike = preg_replace(
'/\{yyyy\}/i',
'____', $maskLike);
1011 $maskLike = preg_replace(
'/\{yy\}/i',
'__', $maskLike);
1012 $maskLike = preg_replace(
'/\{y\}/i',
'_', $maskLike);
1013 $maskLike = preg_replace(
'/\{mm\}/i',
'__', $maskLike);
1014 $maskLike = preg_replace(
'/\{dd\}/i',
'__', $maskLike);
1016 if ($maskrefclient) $maskLike = str_replace(
dol_string_nospecial(
'{'.$maskrefclient.
'}'), str_pad(
"",
dol_strlen($maskrefclient),
"_"), $maskLike);
1017 if ($masktype) $maskLike = str_replace(
dol_string_nospecial(
'{'.$masktype.
'}'), $masktype_value, $maskLike);
1018 if ($maskuser) $maskLike = str_replace(
dol_string_nospecial(
'{'.$maskuser.
'}'), $maskuser_value, $maskLike);
1021 $sql =
"SELECT ".$field.
" as ref";
1022 $sql .=
" FROM ".MAIN_DB_PREFIX.$table;
1023 $sql .=
" WHERE ".$field.
" LIKE '".$db->escape($maskLike).
"'";
1024 $sql .=
" AND ".$field.
" NOT LIKE '%PROV%'";
1026 $sql .=
" AND entity IN (".getEntity($sharetable).
")";
1027 elseif (!empty($forceentity))
1028 $sql .=
" AND entity IN (".$forceentity.
")";
1029 if ($where) $sql .= $where;
1030 if ($sqlwhere) $sql .=
' AND '.$sqlwhere;
1032 dol_syslog(
"functions2::get_next_value mode=".$mode.
"", LOG_DEBUG);
1033 $resql = $db->query($sql);
1036 $obj = $db->fetch_object(
$resql);
1037 if ($obj) $ref = $obj->ref;
1041 } elseif ($mode ==
'next') {
1045 if ($counter >= pow(10,
dol_strlen($maskcounter)))
1047 $counter =
'ErrorMaxNumberReachForThisMask';
1050 if (!empty($maskrefclient_maskcounter))
1055 $maskrefclient_posnumstart = strpos($maskwithnocode, $maskrefclient_maskcounter, strpos($maskwithnocode, $maskrefclient));
1056 if ($maskrefclient_posnumstart <= 0)
return 'ErrorBadMask';
1057 $maskrefclient_sqlstring =
'SUBSTRING('.$field.
', '.($maskrefclient_posnumstart + 1).
', '.
dol_strlen($maskrefclient_maskcounter).
')';
1062 $maskrefclient_maskLike = str_replace(
"%",
"_", $maskrefclient_maskLike);
1064 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{yyyy}'),
'____', $maskrefclient_maskLike);
1065 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{yy}'),
'__', $maskrefclient_maskLike);
1066 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{y}'),
'_', $maskrefclient_maskLike);
1067 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{mm}'),
'__', $maskrefclient_maskLike);
1068 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{dd}'),
'__', $maskrefclient_maskLike);
1069 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{'.$masktri.
'}'), str_pad(
"",
dol_strlen($maskcounter),
"_"), $maskrefclient_maskLike);
1070 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{'.$maskrefclient.
'}'), $maskrefclient_clientcode.str_pad(
"",
dol_strlen($maskrefclient_maskcounter),
"_"), $maskrefclient_maskLike);
1073 $maskrefclient_counter = 0;
1074 $maskrefclient_sql =
"SELECT MAX(".$maskrefclient_sqlstring.
") as val";
1075 $maskrefclient_sql .=
" FROM ".MAIN_DB_PREFIX.$table;
1077 $maskrefclient_sql .=
" WHERE ".$field.
" LIKE '".$db->escape($maskrefclient_maskLike).
"'";
1079 $maskrefclient_sql .=
" AND entity IN (".getEntity($sharetable).
")";
1080 elseif (!empty($forceentity))
1081 $sql .=
" AND entity IN (".$forceentity.
")";
1082 if ($where) $maskrefclient_sql .= $where;
1083 if ($sqlwhere) $maskrefclient_sql .=
' AND '.$sqlwhere;
1084 $maskrefclient_sql .=
' AND (SUBSTRING('.$field.
', '.(strpos($maskwithnocode, $maskrefclient) + 1).
', '.
dol_strlen($maskrefclient_maskclientcode).
")='".$db->escape($maskrefclient_clientcode).
"')";
1086 dol_syslog(
"functions2::get_next_value maskrefclient", LOG_DEBUG);
1087 $maskrefclient_resql = $db->query($maskrefclient_sql);
1088 if ($maskrefclient_resql)
1090 $maskrefclient_obj = $db->fetch_object($maskrefclient_resql);
1091 $maskrefclient_counter = $maskrefclient_obj->val;
1094 if (empty($maskrefclient_counter) || preg_match(
'/[^0-9]/i', $maskrefclient_counter)) $maskrefclient_counter = $maskrefclient_maskoffset;
1095 $maskrefclient_counter++;
1102 if (!empty($yearoffsettype) && !is_numeric($yearoffsettype) && $yearoffsettype !=
'=')
1104 $numFinal = preg_replace(
'/\{yyyy\}/i', date(
"Y", $date) + $yearoffset, $numFinal);
1105 $numFinal = preg_replace(
'/\{yy\}/i', date(
"y", $date) + $yearoffset, $numFinal);
1106 $numFinal = preg_replace(
'/\{y\}/i', substr(date(
"y", $date), 1, 1) + $yearoffset, $numFinal);
1109 $numFinal = preg_replace(
'/\{yyyy\}/i', date(
"Y", $date), $numFinal);
1110 $numFinal = preg_replace(
'/\{yy\}/i', date(
"y", $date), $numFinal);
1111 $numFinal = preg_replace(
'/\{y\}/i', substr(date(
"y", $date), 1, 1), $numFinal);
1113 $numFinal = preg_replace(
'/\{mm\}/i', date(
"m", $date), $numFinal);
1114 $numFinal = preg_replace(
'/\{dd\}/i', date(
"d", $date), $numFinal);
1117 $maskbefore =
'{'.$masktri.
'}';
1118 $maskafter = str_pad($counter,
dol_strlen($maskcounter),
"0", STR_PAD_LEFT);
1120 $numFinal = str_replace($maskbefore, $maskafter, $numFinal);
1126 $maskrefclient_maskbefore =
'{'.$maskrefclient.
'}';
1127 $maskrefclient_maskafter = $maskrefclient_clientcode.str_pad($maskrefclient_counter,
dol_strlen($maskrefclient_maskcounter),
"0", STR_PAD_LEFT);
1128 $numFinal = str_replace($maskrefclient_maskbefore, $maskrefclient_maskafter, $numFinal);
1134 $masktype_maskbefore =
'{'.$masktype.
'}';
1135 $masktype_maskafter = $masktype_value;
1136 $numFinal = str_replace($masktype_maskbefore, $masktype_maskafter, $numFinal);
1142 $maskuser_maskbefore =
'{'.$maskuser.
'}';
1143 $maskuser_maskafter = $maskuser_value;
1144 $numFinal = str_replace($maskuser_maskbefore, $maskuser_maskafter, $numFinal);
1148 dol_syslog(
"functions2::get_next_value return ".$numFinal, LOG_DEBUG);
1162 $string =
" ".$string;
1163 $ini = strpos($string, $start);
1164 if ($ini == 0)
return "";
1165 $ini += strlen($start);
1166 $len = strpos($string, $end, $ini) - $ini;
1167 return substr($string, $ini, $len);
1181 $hasglobalcounter =
false;
1184 if (preg_match(
'/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i', $mask, $reg)) {
1185 $masktri = $reg[1].(isset($reg[2]) ? $reg[2] :
'').(isset($reg[3]) ? $reg[3] :
'');
1186 $maskcounter = $reg[1];
1187 $hasglobalcounter =
true;
1191 $maskcounter =
'00000';
1195 if (
dol_strlen($maskcounter) < 3)
return 'ErrorCounterMustHaveMoreThan3Digits';
1198 $regClientRef = array();
1199 if (preg_match(
'/\{(c+)(0*)\}/i', $mask, $regClientRef))
1201 $maskrefclient = $regClientRef[1].$regClientRef[2];
1202 $maskrefclient_maskclientcode = $regClientRef[1];
1203 $maskrefclient_maskcounter = $regClientRef[2];
1204 $maskrefclient_maskoffset = 0;
1205 $maskrefclient_clientcode = substr(
'', 0,
dol_strlen($maskrefclient_maskclientcode));
1206 $maskrefclient_clientcode = str_pad($maskrefclient_clientcode,
dol_strlen($maskrefclient_maskclientcode),
"#", STR_PAD_RIGHT);
1208 if (
dol_strlen($maskrefclient_maskcounter) > 0 &&
dol_strlen($maskrefclient_maskcounter) < 3)
return 'ErrorCounterMustHaveMoreThan3Digits';
1209 }
else $maskrefclient =
'';
1212 if (!$hasglobalcounter && ($maskrefclient_maskcounter ==
''))
1214 return 'ErrorBadMask';
1217 $maskwithonlyymcode = $mask;
1218 $maskwithonlyymcode = preg_replace(
'/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i', $maskcounter, $maskwithonlyymcode);
1219 $maskwithonlyymcode = preg_replace(
'/\{dd\}/i',
'dd', $maskwithonlyymcode);
1220 $maskwithonlyymcode = preg_replace(
'/\{(c+)(0*)\}/i', $maskrefclient, $maskwithonlyymcode);
1221 $maskwithnocode = $maskwithonlyymcode;
1222 $maskwithnocode = preg_replace(
'/\{yyyy\}/i',
'yyyy', $maskwithnocode);
1223 $maskwithnocode = preg_replace(
'/\{yy\}/i',
'yy', $maskwithnocode);
1224 $maskwithnocode = preg_replace(
'/\{y\}/i',
'y', $maskwithnocode);
1225 $maskwithnocode = preg_replace(
'/\{mm\}/i',
'mm', $maskwithnocode);
1231 if (!empty($reg[2]) && preg_match(
'/^\+/', $reg[2])) $maskoffset = preg_replace(
'/^\+/',
'', $reg[2]);
1232 if (!empty($reg[3]) && preg_match(
'/^\+/', $reg[3])) $maskoffset = preg_replace(
'/^\+/',
'', $reg[3]);
1237 if (!empty($reg[2]) && preg_match(
'/^@/', $reg[2])) $maskraz = preg_replace(
'/^@/',
'', $reg[2]);
1238 if (!empty($reg[3]) && preg_match(
'/^@/', $reg[3])) $maskraz = preg_replace(
'/^@/',
'', $reg[3]);
1241 if ($maskraz == 99) {
1242 $maskraz = date(
'm');
1243 $resetEveryMonth =
true;
1245 if ($maskraz > 12)
return 'ErrorBadMaskBadRazMonth';
1248 if ($maskraz > 1 && !preg_match(
'/^(.*)\{(y+)\}\{(m+)\}/i', $maskwithonlyymcode, $reg))
return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
1249 if ($maskraz <= 1 && !preg_match(
'/^(.*)\{(y+)\}/i', $maskwithonlyymcode, $reg))
return 'ErrorCantUseRazIfNoYearInMask';
1254 if (function_exists(
'mb_strrpos')) {
1255 $posnumstart = mb_strrpos($maskwithnocode, $maskcounter, 0,
'UTF-8');
1258 $posnumstart = strrpos($maskwithnocode, $maskcounter);
1260 if ($posnumstart < 0)
return 'ErrorBadMaskFailedToLocatePosOfSequence';
1267 if (
dol_strlen($value) != $len) $result = -1;
1269 dol_syslog(
"functions2::check_value result=".$result, LOG_DEBUG);
1281 function binhex($bin, $pad =
false, $upper =
false)
1284 for ($i = 0; $i <= $last; $i++) { $x += $bin[$last - $i] * pow(2, $i); }
1287 if ($upper) { $x = strtoupper($x); }
1301 for ($i = 0; $i < $strLength; $i++)
1303 $bin .= str_pad(decbin(hexdec($hexa[$i])), 4,
'0', STR_PAD_LEFT);
1316 $stime = strftime(
'%Y-%m-%d', $time);
1318 if (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/i', $stime, $reg))
1334 if (date(
"w", mktime(12, 0, 0, $mois, $jour, $annee)) == 0)
1335 $jeudiSemaine = mktime(12, 0, 0, $mois, $jour, $annee) - 3 * 24 * 60 * 60;
1336 elseif (date(
"w", mktime(12, 0, 0, $mois, $jour, $annee)) < 4)
1337 $jeudiSemaine = mktime(12, 0, 0, $mois, $jour, $annee) + (4 - date(
"w", mktime(12, 0, 0, $mois, $jour, $annee))) * 24 * 60 * 60;
1338 elseif (date(
"w", mktime(12, 0, 0, $mois, $jour, $annee)) > 4)
1339 $jeudiSemaine = mktime(12, 0, 0, $mois, $jour, $annee) - (date(
"w", mktime(12, 0, 0, $mois, $jour, $annee)) - 4) * 24 * 60 * 60;
1341 $jeudiSemaine = mktime(12, 0, 0, $mois, $jour, $annee);
1344 if (date(
"w", mktime(12, 0, 0, 1, 1, date(
"Y", $jeudiSemaine))) == 0)
1346 $premierJeudiAnnee = mktime(12, 0, 0, 1, 1, date(
"Y", $jeudiSemaine)) + 4 * 24 * 60 * 60;
1347 } elseif (date(
"w", mktime(12, 0, 0, 1, 1, date(
"Y", $jeudiSemaine))) < 4)
1349 $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;
1350 } elseif (date(
"w", mktime(12, 0, 0, 1, 1, date(
"Y", $jeudiSemaine))) > 4)
1352 $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;
1355 $premierJeudiAnnee = mktime(12, 0, 0, 1, 1, date(
"Y", $jeudiSemaine));
1361 date(
"z", mktime(12, 0, 0, date(
"m", $jeudiSemaine), date(
"d", $jeudiSemaine), date(
"Y", $jeudiSemaine)))
1363 date(
"z", mktime(12, 0, 0, date(
"m", $premierJeudiAnnee), date(
"d", $premierJeudiAnnee), date(
"Y", $premierJeudiAnnee)))
1368 if ($numeroSemaine == 53)
1371 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))
1373 $numeroSemaine = 53;
1381 return sprintf(
"%02d", $numeroSemaine);
1399 while ($from_unit <> $to_unit)
1401 if ($from_unit > $to_unit)
1403 $weight = $weight * 10;
1404 $from_unit = $from_unit - 1;
1407 if ($from_unit < $to_unit)
1409 $weight = $weight / 10;
1410 $from_unit = $from_unit + 1;
1432 if (count($tab) < 1)
return -1;
1437 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"user_param";
1438 $sql .=
" WHERE fk_user = ".$user->id;
1439 $sql .=
" AND entity = ".$conf->entity;
1440 $sql .=
" AND param in (";
1442 foreach ($tab as $key => $value)
1444 if ($i > 0) $sql .=
',';
1445 $sql .=
"'".$db->escape($key).
"'";
1449 dol_syslog(
"functions2.lib::dol_set_user_param", LOG_DEBUG);
1451 $resql = $db->query($sql);
1459 foreach ($tab as $key => $value)
1464 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"user_param(fk_user,entity,param,value)";
1465 $sql .=
" VALUES (".$user->id.
",".$conf->entity.
",";
1466 $sql .=
" '".$db->escape($key).
"','".$db->escape($value).
"')";
1468 dol_syslog(
"functions2.lib::dol_set_user_param", LOG_DEBUG);
1469 $result = $db->query($sql);
1476 $user->conf->$key = $value;
1479 unset($user->conf->$key);
1497 if ($reduction == 100)
1499 $string = $langs->transnoentities(
"Offered");
1501 $string =
vatrate($reduction,
true);
1516 if ($option ==
'smr') $osversion = php_uname(
's').
' '.php_uname(
'm').
' '.php_uname(
'r');
1517 else $osversion = php_uname();
1529 return phpversion();
1550 return $_SERVER[
"SERVER_SOFTWARE"];
1563 global $conf, $langs;
1568 $sql =
"SELECT nom as id, nom as doc_template_name, libelle as label, description as description";
1569 $sql .=
" FROM ".MAIN_DB_PREFIX.
"document_model";
1570 $sql .=
" WHERE type = '".$db->escape($type).
"'";
1571 $sql .=
" AND entity IN (0,".$conf->entity.
")";
1572 $sql .=
" ORDER BY description DESC";
1574 dol_syslog(
'/core/lib/function2.lib.php::getListOfModels', LOG_DEBUG);
1575 $resql = $db->query($sql);
1578 $num = $db->num_rows(
$resql);
1584 $obj = $db->fetch_object(
$resql);
1588 if (!empty($obj->description))
1590 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1592 $const = $obj->description;
1594 $dirtoscan = preg_replace(
'/[\r\n]+/',
',', trim($conf->global->$const));
1596 $listoffiles = array();
1599 $listofdir = explode(
',', $dirtoscan);
1600 foreach ($listofdir as $key=>$tmpdir)
1602 $tmpdir = trim($tmpdir);
1603 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
1604 if (!$tmpdir) { unset($listofdir[$key]);
continue; }
1605 if (is_dir($tmpdir))
1608 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'',
'',
'name', SORT_ASC, 0);
1609 if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles);
1613 if (count($listoffiles))
1615 foreach ($listoffiles as $record)
1617 $max = ($maxfilenamelength ? $maxfilenamelength : 28);
1618 $liste[$obj->id.
':'.$record[
'fullname']] =
dol_trunc($record[
'name'], $max,
'middle');
1621 $liste[0] = $obj->label.
': '.$langs->trans(
"None");
1624 if ($type ==
'member' && $obj->doc_template_name ==
'standard')
1626 global $_Avery_Labels;
1627 include_once DOL_DOCUMENT_ROOT.
'/core/lib/format_cards.lib.php';
1628 foreach ($_Avery_Labels as $key => $val)
1630 $liste[$obj->id.
':'.$key] = ($obj->label ? $obj->label : $obj->doc_template_name).
' '.$val[
'name'];
1634 $liste[$obj->id] = $obj->label ? $obj->label : $obj->doc_template_name;
1644 if ($found)
return $liste;
1658 if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
1660 if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE))
return 2;
1663 if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE))
return 0;
1683 if (!empty($conf->global->MAIN_BUILD_LOGIN_RULE) && $conf->global->MAIN_BUILD_LOGIN_RULE ==
'f.lastname') {
1685 $login .= ($login ?
'.' :
'');
1690 $login .= ($login ?
'.' :
'');
1710 $proxyuse = (empty($conf->global->MAIN_PROXY_USE) ?
false:
true);
1711 $proxyhost = (empty($conf->global->MAIN_PROXY_USE) ?
false:$conf->global->MAIN_PROXY_HOST);
1712 $proxyport = (empty($conf->global->MAIN_PROXY_USE) ?
false:$conf->global->MAIN_PROXY_PORT);
1713 $proxyuser = (empty($conf->global->MAIN_PROXY_USE) ?
false:$conf->global->MAIN_PROXY_USER);
1714 $proxypass = (empty($conf->global->MAIN_PROXY_USE) ?
false:$conf->global->MAIN_PROXY_PASS);
1715 $timeout = (empty($conf->global->MAIN_USE_CONNECT_TIMEOUT) ? 10 : $conf->global->MAIN_USE_CONNECT_TIMEOUT);
1716 $response_timeout = (empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT) ? 30 : $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
1720 $params = array(
'connection_timeout'=>$timeout,
1721 'response_timeout'=>$response_timeout,
1723 'proxy_host' => $proxyhost,
1724 'proxy_port' => $proxyport,
1725 'proxy_login' => $proxyuser,
1726 'proxy_password' => $proxypass,
1730 $params = array(
'connection_timeout'=>$timeout,
1731 'response_timeout'=>$response_timeout,
1733 'proxy_host' =>
false,
1734 'proxy_port' =>
false,
1735 'proxy_login' =>
false,
1736 'proxy_password' =>
false,
1755 global $db, $conf, $langs;
1761 if (preg_match(
'/^([^@]+)@([^@]+)$/i', $objecttype, $regs)) {
1762 $myobject = $regs[1];
1767 $module = $myobject = $objecttype;
1768 if (preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs))
1771 $myobject = $regs[2];
1776 $classpath = $module.
'/class';
1779 if ($objecttype ==
'facture' || $objecttype ==
'invoice') {
1780 $classpath =
'compta/facture/class';
1781 $module =
'facture';
1782 $myobject =
'facture';
1783 } elseif ($objecttype ==
'commande' || $objecttype ==
'order') {
1784 $classpath =
'commande/class';
1785 $module =
'commande';
1786 $myobject =
'commande';
1787 } elseif ($objecttype ==
'propal') {
1788 $classpath =
'comm/propal/class';
1789 } elseif ($objecttype ==
'supplier_proposal') {
1790 $classpath =
'supplier_proposal/class';
1791 } elseif ($objecttype ==
'shipping') {
1792 $classpath =
'expedition/class';
1793 $myobject =
'expedition';
1794 $module =
'expedition_bon';
1795 } elseif ($objecttype ==
'delivery') {
1796 $classpath =
'delivery/class';
1797 $myobject =
'delivery';
1798 $module =
'delivery_note';
1799 } elseif ($objecttype ==
'contract') {
1800 $classpath =
'contrat/class';
1801 $module =
'contrat';
1802 $myobject =
'contrat';
1803 } elseif ($objecttype ==
'member') {
1804 $classpath =
'adherents/class';
1805 $module =
'adherent';
1806 $myobject =
'adherent';
1807 } elseif ($objecttype ==
'cabinetmed_cons') {
1808 $classpath =
'cabinetmed/class';
1809 $module =
'cabinetmed';
1810 $myobject =
'cabinetmedcons';
1811 } elseif ($objecttype ==
'fichinter') {
1812 $classpath =
'fichinter/class';
1813 $module =
'ficheinter';
1814 $myobject =
'fichinter';
1815 } elseif ($objecttype ==
'task') {
1816 $classpath =
'projet/class';
1819 } elseif ($objecttype ==
'stock') {
1820 $classpath =
'product/stock/class';
1822 $myobject =
'stock';
1823 } elseif ($objecttype ==
'inventory') {
1824 $classpath =
'product/inventory/class';
1826 $myobject =
'inventory';
1827 } elseif ($objecttype ==
'mo') {
1828 $classpath =
'mrp/class';
1834 $classfile = strtolower($myobject); $classname = ucfirst($myobject);
1837 if ($objecttype ==
'invoice_supplier') {
1838 $classfile =
'fournisseur.facture';
1839 $classname =
'FactureFournisseur';
1840 $classpath =
'fourn/class';
1841 $module =
'fournisseur';
1842 } elseif ($objecttype ==
'order_supplier') {
1843 $classfile =
'fournisseur.commande';
1844 $classname =
'CommandeFournisseur';
1845 $classpath =
'fourn/class';
1846 $module =
'fournisseur';
1848 elseif ($objecttype ==
'supplier_proposal') {
1849 $classfile =
'supplier_proposal';
1850 $classname =
'SupplierProposal';
1851 $classpath =
'supplier_proposal/class';
1852 $module =
'supplier_proposal';
1854 elseif ($objecttype ==
'stock') {
1855 $classpath =
'product/stock/class';
1856 $classfile =
'entrepot';
1857 $classname =
'Entrepot';
1860 if (!empty($conf->$module->enabled))
1865 if (class_exists($classname))
1867 $object =
new $classname($db);
1868 $res = $object->fetch($objectid);
1870 $ret = $object->getNomUrl($withpicto, $option);
1871 } elseif ($res == 0) {
1872 $ret = $langs->trans(
'Deleted');
1875 }
else dol_syslog(
"Class with classname ".$classname.
" is unknown even after the include", LOG_ERR);
1893 $listofid = array();
1894 $listofparentid = array();
1897 $sql =
'SELECT rowid, '.$fieldfkparent.
' as parent_id FROM '.MAIN_DB_PREFIX.$tabletocleantree;
1898 $resql = $db->query($sql);
1901 $num = $db->num_rows(
$resql);
1905 $obj = $db->fetch_object(
$resql);
1906 $listofid[] = $obj->rowid;
1907 if ($obj->parent_id > 0) $listofparentid[$obj->rowid] = $obj->parent_id;
1914 if (count($listofid))
1916 print 'Code requested to clean tree (may be to solve data corruption), so we check/clean orphelins and loops.'.
"<br>\n";
1919 $sql =
"UPDATE ".MAIN_DB_PREFIX.$tabletocleantree.
" SET ".$fieldfkparent.
" = 0 WHERE ".$fieldfkparent.
" = rowid";
1920 $resql = $db->query($sql);
1923 $nb = $db->affected_rows($sql);
1926 print '<br>Some record that were parent of themself were cleaned.';
1934 $listofidtoclean = array();
1935 foreach ($listofparentid as $id => $pid)
1940 $cursor = $id; $arrayidparsed = array();
1943 $arrayidparsed[$cursor] = 1;
1944 if ($arrayidparsed[$listofparentid[$cursor]])
1946 print 'Found a loop between id '.$id.
' - '.$cursor.
'<br>';
1947 unset($arrayidparsed);
1948 $listofidtoclean[$cursor] = $id;
1951 $cursor = $listofparentid[$cursor];
1954 if (count($listofidtoclean))
break;
1957 $sql =
"UPDATE ".MAIN_DB_PREFIX.$tabletocleantree;
1958 $sql .=
" SET ".$fieldfkparent.
" = 0";
1959 $sql .=
" WHERE rowid IN (".join(
',', $listofidtoclean).
")";
1960 $resql = $db->query($sql);
1963 $nb = $db->affected_rows($sql);
1967 print '<br>Some records were detected to have parent that is a child, we set them as root record for id: ';
1968 print join(
',', $listofidtoclean);
1976 $sql =
"UPDATE ".MAIN_DB_PREFIX.$tabletocleantree;
1977 $sql .=
" SET ".$fieldfkparent.
" = 0";
1978 $sql .=
" WHERE ".$fieldfkparent.
" NOT IN (".join(
',', $listofid).
")";
1979 $resql = $db->query($sql);
1982 $nb = $db->affected_rows($sql);
1986 print '<br>Some orphelins were found and modified to be parent so records are visible again for id: ';
1987 print join(
',', $listofid);
1994 print '<br>We fixed '.$totalnb.
' record(s). Some records may still be corrupted. New check may be required.';
2011 if (!is_array($arraycolor))
return $colorifnotfound;
2012 if (empty($arraycolor))
return $colorifnotfound;
2013 return sprintf(
"%02s", dechex($arraycolor[0])).sprintf(
"%02s", dechex($arraycolor[1])).sprintf(
"%02s", dechex($arraycolor[2]));
2028 if (is_array($stringcolor))
return $stringcolor;
2030 $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);
2033 $tmp = explode(
',', $stringcolor);
2034 if (count($tmp) < 3)
return $colorifnotfound;
2037 return array(hexdec($reg[1]), hexdec($reg[2]), hexdec($reg[3]));
2047 if (!$allow_white && ($color ===
'#fff' || $color ===
'#ffffff'))
return false;
2049 if (preg_match(
'/^#[a-f0-9]{6}$/i', $color))
2067 if (empty($ratio)) $ratio = 0;
2070 $ratio = max(-100, min(100, $ratio));
2073 $hex = str_replace(
'#',
'', $hex);
2074 if (strlen($hex) == 3) {
2075 $hex = str_repeat(substr($hex, 0, 1), 2).str_repeat(substr($hex, 1, 1), 2).str_repeat(substr($hex, 2, 1), 2);
2079 $color_parts = str_split($hex, 2);
2082 foreach ($color_parts as $color) {
2083 $color = hexdec($color);
2086 if ($color > 127) $color += ((255 - $color) * ($ratio / 100));
2087 if ($color < 128) $color -= ($color * ($ratio / 100));
2090 if ($color > 128) $color -= (($color - 128) * (abs($ratio) / 100));
2091 if ($color < 127) $color += ((128 - $color) * (abs($ratio) / 100));
2093 if ($brightness > 0)
2095 $color = ($color * (100 + abs($brightness)) / 100);
2097 $color = ($color * (100 - abs($brightness)) / 100);
2100 $color = max(0, min(255, $color));
2101 $return .= str_pad(dechex($color), 2,
'0', STR_PAD_LEFT);
2117 $steps = max(-255, min(255, $steps));
2120 $hex = str_replace(
'#',
'', $hex);
2121 if (strlen($hex) == 3) {
2122 $hex = str_repeat(substr($hex, 0, 1), 2).str_repeat(substr($hex, 1, 1), 2).str_repeat(substr($hex, 2, 1), 2);
2126 $color_parts = str_split($hex, 2);
2129 foreach ($color_parts as $color) {
2130 $color = hexdec($color);
2131 $color = max(0, min(255, $color + $steps));
2132 $return .= str_pad(dechex($color), 2,
'0', STR_PAD_LEFT);
2145 $steps = intval(255 * $percent / 100) * -1;
2156 $steps = intval(255 * $percent / 100);
2170 $hex = str_replace(
'#',
'', $hex);
2171 $length = strlen($hex);
2173 $rgb[
'r'] = hexdec($length == 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0));
2174 $rgb[
'g'] = hexdec($length == 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0));
2175 $rgb[
'b'] = hexdec($length == 6 ? substr($hex, 4, 2) : ($length == 3 ? str_repeat(substr($hex, 2, 1), 2) : 0));
2176 if ($alpha !==
false) {
2177 $rgb[
'a'] = floatval($alpha);
2178 $string =
'rgba('.implode(
',', $rgb).
')';
2180 $string =
'rgb('.implode(
',', $rgb).
')';
2201 $input = array_filter($input);
2203 $result = array(array());
2205 foreach ($input as $key => $values) {
2208 foreach ($result as $product) {
2209 foreach ($values as $item) {
2210 $product[$key] = $item;
2211 $append[] = $product;
2230 $moduledirforclass = $moduleobject;
2231 if ($moduledirforclass !=
'api') $moduledirforclass = preg_replace(
'/api$/i',
'', $moduledirforclass);
2233 if ($moduleobject ==
'contracts') {
2234 $moduledirforclass =
'contrat';
2235 } elseif (in_array($moduleobject, array(
'admin',
'login',
'setup',
'access',
'status',
'tools',
'documents'))) {
2236 $moduledirforclass =
'api';
2237 } elseif ($moduleobject ==
'contact' || $moduleobject ==
'contacts' || $moduleobject ==
'customer' || $moduleobject ==
'thirdparty' || $moduleobject ==
'thirdparties') {
2238 $moduledirforclass =
'societe';
2239 } elseif ($moduleobject ==
'propale' || $moduleobject ==
'proposals') {
2240 $moduledirforclass =
'comm/propal';
2241 } elseif ($moduleobject ==
'agenda' || $moduleobject ==
'agendaevents') {
2242 $moduledirforclass =
'comm/action';
2243 } elseif ($moduleobject ==
'adherent' || $moduleobject ==
'members' || $moduleobject ==
'memberstypes' || $moduleobject ==
'subscriptions') {
2244 $moduledirforclass =
'adherents';
2245 } elseif ($moduleobject ==
'don' || $moduleobject ==
'donations') {
2246 $moduledirforclass =
'don';
2247 } elseif ($moduleobject ==
'banque' || $moduleobject ==
'bankaccounts') {
2248 $moduledirforclass =
'compta/bank';
2249 } elseif ($moduleobject ==
'category' || $moduleobject ==
'categorie') {
2250 $moduledirforclass =
'categories';
2251 } elseif ($moduleobject ==
'order' || $moduleobject ==
'orders') {
2252 $moduledirforclass =
'commande';
2253 } elseif ($moduleobject ==
'shipments') {
2254 $moduledirforclass =
'expedition';
2255 } elseif ($moduleobject ==
'facture' || $moduleobject ==
'invoice' || $moduleobject ==
'invoices') {
2256 $moduledirforclass =
'compta/facture';
2257 } elseif ($moduleobject ==
'project' || $moduleobject ==
'projects' || $moduleobject ==
'task' || $moduleobject ==
'tasks') {
2258 $moduledirforclass =
'projet';
2259 } elseif ($moduleobject ==
'stock' || $moduleobject ==
'stockmovements' || $moduleobject ==
'warehouses') {
2260 $moduledirforclass =
'product/stock';
2261 } elseif ($moduleobject ==
'supplierproposals' || $moduleobject ==
'supplierproposal' || $moduleobject ==
'supplier_proposal') {
2262 $moduledirforclass =
'supplier_proposal';
2263 } elseif ($moduleobject ==
'fournisseur' || $moduleobject ==
'supplierinvoices' || $moduleobject ==
'supplierorders') {
2264 $moduledirforclass =
'fourn';
2265 } elseif ($moduleobject ==
'ficheinter' || $moduleobject ==
'interventions') {
2266 $moduledirforclass =
'fichinter';
2267 } elseif ($moduleobject ==
'mos') {
2268 $moduledirforclass =
'mrp';
2269 } elseif (in_array($moduleobject, array(
'products',
'expensereports',
'users',
'tickets',
'boms'))) {
2270 $moduledirforclass = preg_replace(
'/s$/',
'', $moduleobject);
2273 return $moduledirforclass;
2285 return str_pad(dechex(mt_rand($min, $max)), 2,
'0', STR_PAD_LEFT);
2297 return randomColorPart($min, $max).randomColorPart($min, $max).randomColorPart($min, $max);
2301 if (!function_exists(
'dolEscapeXML'))
2309 function dolEscapeXML($string)
2311 return strtr($string, array(
'\''=>
''',
'"'=>
'"',
'&'=>
'&',
'<'=>
'<',
'>'=>
'>'));
2327 $result =
'unknown'; $classname =
'';
2328 if ($automaticmanual == 1 || strtolower($automaticmanual) ==
'automatic' || strtolower($automaticmanual) ==
'true')
2330 $result = $langs->trans(
'automatic');
2331 if ($case == 1 || $case == 3) $result = $langs->trans(
"Automatic");
2332 if ($case == 2) $result =
'<input type="checkbox" value="1" checked disabled>';
2333 if ($case == 3) $result =
'<input type="checkbox" value="1" checked disabled> '.$result;
2336 } elseif ($automaticmanual == 0 || strtolower($automaticmanual) ==
'manual' || strtolower($automaticmanual) ==
'false')
2338 $result = $langs->trans(
"manual");
2339 if ($case == 1 || $case == 3) $result = $langs->trans(
"Manual");
2340 if ($case == 2) $result =
'<input type="checkbox" value="0" disabled>';
2341 if ($case == 3) $result =
'<input type="checkbox" value="0" disabled> '.$result;
2343 if ($color == 2) $classname =
'ok';
2344 else $classname =
'error';
2346 if ($color)
return '<font class="'.$classname.
'">'.$result.
'</font>';
2359 global $dolibarr_main_url_root;
2361 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2362 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2364 $notetoshow = preg_replace(
'/src="[a-zA-Z0-9_\/\-\.]*(viewimage\.php\?modulepart=medias[^"]*)"/',
'src="'.$urlwithroot.
'/\1"', $notetoshow);
2381 if (empty($amount)) $amount = 0;
2382 $amount = (is_numeric($amount) ? $amount : 0);
2385 $nbdecimal = (empty($conf->global->ACCOUNTING_FEC_DECIMAL_LENGTH) ? 2 : $conf->global->ACCOUNTING_FEC_DECIMAL_LENGTH);
2388 $dec = (empty($conf->global->ACCOUNTING_FEC_DECIMAL_SEPARATOR) ?
',' : $conf->global->ACCOUNTING_FEC_DECIMAL_SEPARATOR);
2389 $thousand = (empty($conf->global->ACCOUNTING_FEC_THOUSAND_SEPARATOR) ?
'' : $conf->global->ACCOUNTING_FEC_THOUSAND_SEPARATOR);
2392 $output = number_format($amount, $nbdecimal, $dec, $thousand);
2405 if (!defined(
"CR")) define(
"CR",
"\r");
2406 if (!defined(
"LF")) define(
"LF",
"\n");
2407 if (!defined(
"CRLF")) define(
"CRLF",
"\r\n");
2411 foreach (token_get_all(
'<?php '.$code) as $token) {
2412 if (is_array($token)) {
2413 switch ($token[0]) {
2415 case T_DOLLAR_OPEN_CURLY_BRACES:
2416 case T_START_HEREDOC: ++$inString;
break;
2417 case T_END_HEREDOC: --$inString;
break;
2419 } elseif ($inString & 1) {
2423 case '"': --$inString;
break;
2429 case '"': ++$inString;
break;
2430 case '{': ++$braces;
break;
2436 if ($braces < 0)
break 2;
2442 $inString = @ini_set(
'log_errors',
false);
2443 $token = @ini_set(
'display_errors',
true);
2445 $code = substr($code, strlen(
'<?php '));
2446 $braces || $code =
"if(0){{$code}\n}";
2447 if (eval($code) ===
false) {
2449 $braces = PHP_INT_MAX;
2451 false !== strpos($code, CR) && $code = strtr(str_replace(CRLF, LF, $code), CR, LF);
2452 $braces = substr_count($code, LF);
2454 $code = ob_get_clean();
2455 $code = strip_tags($code);
2456 if (preg_match(
"'syntax error, (.+) in .+ on line (\d+)$'s", $code, $code)) {
2457 $code[2] = (int) $code[2];
2458 $code = $code[2] <= $braces
2459 ? array($code[1], $code[2])
2460 : array(
'unexpected $end'.substr($code[1], 14), $braces);
2461 }
else $code = array(
'syntax error', 0);
2466 @ini_set(
'display_errors', $token);
2467 @ini_set(
'log_errors', $inString);
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname= '')
Make an include_once using default root and alternate root if it fails.
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...
weight_convert($weight, &$from_unit, $to_unit)
Convertit une masse d'une unite vers une autre unite.
getModuleDirForApiClass($moduleobject)
Get name of directory where the api_...class.php file is stored.
cartesianArray(array $input)
Applies the Cartesian product algorithm to an array Source: http://stackoverflow.com/a/15973172.
dol_print_reduction($reduction, $langs)
Returns formated reduction.
version_webserver()
Return web server version.
dolGetModulesDirs($subdir= '')
Return list of modules directories.
dol_html_entity_decode($a, $b, $c= 'UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
dol_now($mode= 'auto')
Return date for now.
colorDarker($hex, $percent)
dol_print_object_info($object, $usetable=0)
Show informations on an object TODO Move this into html.formother.
Class to manage Dolibarr users.
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)
colorLighten($hex, $percent)
cleanCorruptedTree($db, $tabletocleantree, $fieldfkparent)
Clean corrupted tree (orphelins linked to a not existing parent), record linked to themself and child...
clean_url($url, $http=1)
Clean an url string.
version_os($option= '')
Return OS version.
price2fec($amount)
Function to format a value into a defined format for French administration (no thousand separator & d...
colorAdjustBrightness($hex, $steps)
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
check_value($mask, $value)
Check value.
colorStringToArray($stringcolor, $colorifnotfound=array(88, 88, 88))
Convert a string RGB value ('FFFFFF', '255,255,255') into an array RGB array(255,255,255).
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]...
dolAddEmailTrackId($email, $trackingid)
Return an email formatted to include a tracking id For example myemail@example.com becom myemail+trac...
colorHexToRgb($hex, $alpha=false, $returnArray=false)
hexbin($hexa)
Convert an hexadecimal string into a binary string.
dol_string_nospecial($str, $newstr= '_', $badcharstoreplace= '')
Clean a string from all punctuation characters to use it as a ref or login.
isValidMXRecord($domain)
Return if the domain name has a valid MX record.
getServerTimeZoneInt($refgmtdate= 'now')
Return server timezone int.
phpSyntaxError($code)
Check the syntax of some PHP code.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
jsUnEscape($source)
Same function than javascript unescape() function but in PHP.
dol_getDefaultFormat(Translate $outputlangs=null)
Try to guess default paper format according to language into $langs.
Class to manage translations.
version_dolibarr()
Return Dolibarr version.
dol_print_file($langs, $filename, $searchalt=0)
Output content of a file $filename in version of current language (otherwise may use an alternate lan...
is_ip($ip)
This function evaluates a string that should be a valid IPv4 Note: For ip 169.254.0.0, it returns 0 with some PHP (5.6.24) and 2 with some minor patchs of PHP (5.6.25).
isValidVATID($company)
Check if VAT numero is valid (check done on syntax only, no database or remote access) ...
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
randomColorPart($min=0, $max=255)
Return 2 hexa code randomly.
colorValidateHex($color, $allow_white=true)
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
utf8_check($str)
Check if a string is in UTF8.
convertBackOfficeMediasLinksToPublicLinks($notetoshow)
Convert links to local wrapper to medias files into a string into a public external URL readable on i...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages...
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.
version_php()
Return PHP version.
print $_SERVER["PHP_SELF"]
Edit parameters.
isValidMailDomain($mail)
Return true if email has a domain name that can be resolved to MX type.
print
Draft customers invoices.
randomColor($min=0, $max=255)
Return hexadecimal color randomly.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
array2table($data, $tableMarkup=1, $tableoptions= '', $troptions= '', $tdoptions= '')
Return an html table from an array.
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.
array2tr($data, $troptions= '', $tdoptions= '')
Return lines of an html table from an array Used by array2table function only.
getListOfModels($db, $type, $maxfilenamelength=0)
Return list of activated modules usable for document generation.
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.
binhex($bin, $pad=false, $upper=false)
Convert a binary data to string that represent hexadecimal value.
getSoapParams()
Return array to use for SoapClient constructor.
isValidEmail($address, $acceptsupervisorkey=0)
Return true if email syntax is ok.
colorAgressiveness($hex, $ratio=-50, $brightness=0)
Change color to make it less aggressive (ratio is negative) or more aggressive (ratio is positive) ...
if(!function_exists('dolEscapeXML')) autoOrManual($automaticmanual, $case=1, $color=0)
Return automatic or manual in current language.
dolGetElementUrl($objectid, $objecttype, $withpicto=0, $option= '')
Return link url to an object.
colorArrayToHex($arraycolor, $colorifnotfound= '888888')
Convert an array with RGB value into hex RGB value.