914function get_next_value($db, $mask, $table, $field, $where =
'', $objsoc =
'', $date =
'', $mode =
'next', $bentityon =
true, $objuser =
null, $forceentity =
null)
918 if (!is_object($objsoc)) {
919 $valueforccc = (string) $objsoc;
920 } elseif ($table ==
"commande_fournisseur" || $table ==
"facture_fourn" || $table ==
"paiementfourn") {
926 $sharetable = $table;
927 if ($table ==
'facture' || $table ==
'invoice') {
928 $sharetable =
'invoicenumber';
943 $hasglobalcounter =
false;
944 $maskrefclient_maskcounter =
'';
945 $maskrefclient_clientcode =
'';
946 $maskrefclient_maskclientcode =
'';
947 $maskrefclient_maskoffset =
'';
951 if (preg_match(
'/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i', $mask, $reg)) {
952 $masktri = $reg[1].(!empty($reg[2]) ? $reg[2] :
'').(!empty($reg[3]) ? $reg[3] :
'');
953 $maskcounter = $reg[1];
954 $hasglobalcounter =
true;
958 $maskcounter =
'00000';
963 $resetEveryMonth =
false;
965 return 'ErrorCounterMustHaveMoreThan3Digits';
969 $regClientRef = array();
970 if (preg_match(
'/\{(c+)(0*)\}/i', $mask, $regClientRef)) {
971 $maskrefclient = $regClientRef[1].$regClientRef[2];
972 $maskrefclient_maskclientcode = $regClientRef[1];
973 $maskrefclient_maskcounter = $regClientRef[2];
974 $maskrefclient_maskoffset = 0;
975 $maskrefclient_clientcode = substr($valueforccc, 0,
dol_strlen($maskrefclient_maskclientcode));
976 $maskrefclient_clientcode = str_pad($maskrefclient_clientcode,
dol_strlen($maskrefclient_maskclientcode),
"#", STR_PAD_RIGHT);
979 return 'ErrorCounterMustHaveMoreThan3Digits';
986 if (!$hasglobalcounter && ($maskrefclient_maskcounter ==
'')) {
987 return 'ErrorBadMask';
992 if (preg_match(
'/\{(t+)\}/i', $mask, $regType)) {
993 $masktype = $regType[1];
994 $masktype_value =
dol_substr(preg_replace(
'/^TE_/',
'', $objsoc->typent_code), 0,
dol_strlen($regType[1]));
995 $masktype_value = str_pad($masktype_value,
dol_strlen($regType[1]),
"#", STR_PAD_RIGHT);
998 $masktype_value =
'';
1003 if (preg_match(
'/\{(u+)\}/i', $mask, $regType)) {
1004 $lastname =
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
1005 if (is_object($objuser)) {
1006 $lastname = $objuser->lastname;
1009 $maskuser = $regType[1];
1010 $maskuser_value = substr($lastname, 0,
dol_strlen($regType[1]));
1011 $maskuser_value = str_pad($maskuser_value,
dol_strlen($regType[1]),
"#", STR_PAD_RIGHT);
1014 $maskuser_value =
'';
1018 $maskperso = array();
1019 $maskpersonew = array();
1022 while (preg_match(
'/\{([A-Z]+)\-([0-9]+)\}/', $tmpmask, $regKey)) {
1023 $maskperso[$regKey[1]] =
'{'.$regKey[1].
'-'.$regKey[2].
'}';
1025 $maskpersonew[$regKey[1]] = str_pad(
'', (
int) $regKey[2],
'_', STR_PAD_RIGHT);
1026 $tmpmask = preg_replace(
'/\{'.$regKey[1].
'\-'.$regKey[2].
'\}/i', $maskpersonew[$regKey[1]], $tmpmask);
1029 if (strstr($mask,
'user_extra_')) {
1030 $start =
"{user_extra_";
1033 if (!empty($user->array_options[
'options_'.$extra])) {
1034 $mask = preg_replace(
'#('.$start.
')(.*?)('.$end.
')#si', $user->array_options[
'options_'.$extra], $mask);
1037 $maskwithonlyymcode = $mask;
1038 $maskwithonlyymcode = preg_replace(
'/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i', $maskcounter, $maskwithonlyymcode);
1039 $maskwithonlyymcode = preg_replace(
'/\{dd\}/i',
'dd', $maskwithonlyymcode);
1040 $maskwithonlyymcode = preg_replace(
'/\{(c+)(0*)\}/i', $maskrefclient, $maskwithonlyymcode);
1041 $maskwithonlyymcode = preg_replace(
'/\{(t+)\}/i', $masktype_value, $maskwithonlyymcode);
1042 $maskwithonlyymcode = preg_replace(
'/\{(u+)\}/i', $maskuser_value, $maskwithonlyymcode);
1043 foreach ($maskperso as $key => $val) {
1044 $maskwithonlyymcode = preg_replace(
'/'.preg_quote($val,
'/').
'/i', $maskpersonew[$key], $maskwithonlyymcode);
1046 $maskwithnocode = $maskwithonlyymcode;
1047 $maskwithnocode = preg_replace(
'/\{yyyy\}/i',
'yyyy', $maskwithnocode);
1048 $maskwithnocode = preg_replace(
'/\{yy\}/i',
'yy', $maskwithnocode);
1049 $maskwithnocode = preg_replace(
'/\{y\}/i',
'y', $maskwithnocode);
1050 $maskwithnocode = preg_replace(
'/\{mm\}/i',
'mm', $maskwithnocode);
1057 if (!empty($reg[2]) && preg_match(
'/^\+/', $reg[2])) {
1058 $maskoffset = preg_replace(
'/^\+/',
'', $reg[2]);
1060 if (!empty($reg[3]) && preg_match(
'/^\+/', $reg[3])) {
1061 $maskoffset = preg_replace(
'/^\+/',
'', $reg[3]);
1067 $yearoffsettype =
false;
1070 if (!empty($reg[2]) && preg_match(
'/^@/', $reg[2])) {
1071 $yearoffsettype = preg_replace(
'/^@/',
'', $reg[2]);
1073 if (!empty($reg[3]) && preg_match(
'/^@/', $reg[3])) {
1074 $yearoffsettype = preg_replace(
'/^@/',
'', $reg[3]);
1078 if (is_numeric($yearoffsettype) && $yearoffsettype >= 1) {
1079 $maskraz = $yearoffsettype;
1080 } elseif ($yearoffsettype ===
'0' || (!empty($yearoffsettype) && !is_numeric($yearoffsettype) &&
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1)) {
1086 if ($maskraz == 99) {
1087 $maskraz = (int) date(
'm', $date);
1088 $resetEveryMonth =
true;
1090 if ($maskraz > 12) {
1091 return 'ErrorBadMaskBadRazMonth';
1096 if (preg_match(
'/^(.*)\{(y+)\}\{(m+)\}/i', $maskwithonlyymcode, $reg)) {
1099 } elseif (preg_match(
'/^(.*)\{(m+)\}\{(y+)\}/i', $maskwithonlyymcode, $reg)) {
1103 return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
1107 return 'ErrorCantUseRazWithYearOnOneDigit';
1110 if (preg_match(
'/^(.*)\{(m+)\}\{(y+)\}/i', $maskwithonlyymcode, $reg)) {
1113 } elseif (preg_match(
'/^(.*)\{(y+)\}\{(m+)\}/i', $maskwithonlyymcode, $reg)) {
1116 } elseif (preg_match(
'/^(.*)\{(y+)\}/i', $maskwithonlyymcode, $reg)) {
1120 return 'ErrorCantUseRazIfNoYearInMask';
1124 $yearlen = $posy ?
dol_strlen($reg[$posy]) : 0;
1125 $monthlen = $posm ?
dol_strlen($reg[$posm]) : 0;
1128 $monthpos = ($yearpos + $yearlen);
1129 if ($posy == 3 && $posm == 2) {
1131 $yearpos = ($monthpos + $monthlen);
1136 $monthcomp = $maskraz;
1139 if (!empty($yearoffsettype) && !is_numeric($yearoffsettype) && $yearoffsettype !=
'=') {
1140 $currentyear = (int) date(
"Y", $date);
1141 $fiscaldate =
dol_mktime(0, 0, 0, $maskraz, 1, $currentyear);
1142 $newyeardate =
dol_mktime(0, 0, 0, 1, 1, $currentyear);
1143 $nextnewyeardate =
dol_mktime(0, 0, 0, 1, 1, $currentyear + 1);
1147 if ($date >= $fiscaldate) {
1149 if ($date < $nextnewyeardate && $yearoffsettype ==
'+') {
1152 } elseif ($date >= $newyeardate && $yearoffsettype ==
'-') {
1156 } elseif ((
int) date(
"m", $date) < $maskraz && empty($resetEveryMonth)) {
1161 if ($yearlen == 4) {
1162 $yearcomp = sprintf(
"%04d", idate(
"Y", $date) + $yearoffset);
1163 } elseif ($yearlen == 2) {
1164 $yearcomp = sprintf(
"%02d", idate(
"y", $date) + $yearoffset);
1165 } elseif ($yearlen == 1) {
1166 $yearcomp = (int) substr(date(
'y', $date), 1, 1) + $yearoffset;
1168 if ($monthcomp > 1 && empty($resetEveryMonth)) {
1169 if ($yearlen == 4) {
1170 $yearcomp1 = sprintf(
"%04d", idate(
"Y", $date) + $yearoffset + 1);
1171 } elseif ($yearlen == 2) {
1172 $yearcomp1 = sprintf(
"%02d", idate(
"y", $date) + $yearoffset + 1);
1178 $sqlwhere .=
" (SUBSTRING(".$field.
", ".$yearpos.
", ".$yearlen.
") = '".$db->escape($yearcomp).
"'";
1179 $sqlwhere .=
" AND SUBSTRING(".$field.
", ".$monthpos.
", ".$monthlen.
") >= '".str_pad($monthcomp, $monthlen,
'0', STR_PAD_LEFT).
"')";
1181 $sqlwhere .=
" (SUBSTRING(".$field.
", ".$yearpos.
", ".$yearlen.
") = '".$db->escape($yearcomp1).
"'";
1182 $sqlwhere .=
" AND SUBSTRING(".$field.
", ".$monthpos.
", ".$monthlen.
") < '".str_pad($monthcomp, $monthlen,
'0', STR_PAD_LEFT).
"') ";
1184 } elseif ($resetEveryMonth) {
1185 $sqlwhere .=
"(SUBSTRING(".$field.
", ".$yearpos.
", ".$yearlen.
") = '".$db->escape($yearcomp).
"'";
1186 $sqlwhere .=
" AND SUBSTRING(".$field.
", ".$monthpos.
", ".$monthlen.
") = '".str_pad($monthcomp, $monthlen,
'0', STR_PAD_LEFT).
"')";
1188 $sqlwhere .=
"(SUBSTRING(".$field.
", ".$yearpos.
", ".$yearlen.
") = '".$db->escape($yearcomp).
"')";
1195 if (function_exists(
'mb_strrpos')) {
1196 $posnumstart = mb_strrpos($maskwithnocode, $maskcounter, 0,
'UTF-8');
1198 $posnumstart = strrpos($maskwithnocode, $maskcounter);
1200 if ($posnumstart < 0) {
1201 return 'ErrorBadMaskFailedToLocatePosOfSequence';
1203 $sqlstring =
"SUBSTRING(".$field.
", ".($posnumstart + 1).
", ".
dol_strlen($maskcounter).
")";
1207 $maskLike = str_replace(
"%",
"_", $maskLike);
1210 $maskLike = preg_replace(
'/\{yyyy\}/i',
'____', $maskLike);
1211 $maskLike = preg_replace(
'/\{yy\}/i',
'__', $maskLike);
1212 $maskLike = preg_replace(
'/\{y\}/i',
'_', $maskLike);
1213 $maskLike = preg_replace(
'/\{mm\}/i',
'__', $maskLike);
1214 $maskLike = preg_replace(
'/\{dd\}/i',
'__', $maskLike);
1217 if ($maskrefclient) {
1227 foreach ($maskperso as $key => $val) {
1228 $maskLike = str_replace(
dol_string_nospecial($maskperso[$key]), $maskpersonew[$key], $maskLike);
1233 $sql =
"SELECT MAX(".$sqlstring.
") as val";
1234 $sql .=
" FROM ".MAIN_DB_PREFIX.$table;
1235 $sql .=
" WHERE ".$field.
" LIKE '".$db->escape($maskLike) . (
getDolGlobalString(
'SEARCH_FOR_NEXT_VAL_ON_START_ONLY') ?
"%" :
"") .
"'";
1236 $sql .=
" AND ".$field.
" NOT LIKE '(PROV%)'";
1242 $sql .=
" AND ". $db->regexpsql($sqlstring,
'^[0-9]+$', 1);
1246 $sql .=
" AND entity IN (".getEntity($sharetable).
")";
1247 } elseif (!empty($forceentity)) {
1248 $sql .=
" AND entity IN (".$db->sanitize($forceentity).
")";
1254 $sql .=
" AND ".$sqlwhere;
1258 dol_syslog(
"functions2::get_next_value mode=".$mode, LOG_DEBUG);
1259 $resql = $db->query($sql);
1261 $obj = $db->fetch_object($resql);
1262 $counter = $obj->val;
1268 if (empty($counter)) {
1269 $counter = $maskoffset;
1270 } elseif (preg_match(
'/[^0-9]/i', $counter)) {
1271 dol_syslog(
"Error, the last counter found is '".$counter.
"' so is not a numeric value. We will restart to 1.", LOG_ERR);
1273 } elseif ($counter < $maskoffset && !
getDolGlobalString(
'MAIN_NUMBERING_OFFSET_ONLY_FOR_FIRST')) {
1274 $counter = $maskoffset;
1277 if ($mode ==
'last') {
1278 $counterpadded = str_pad($counter,
dol_strlen($maskcounter),
"0", STR_PAD_LEFT);
1282 $maskLike = str_replace(
"%",
"_", $maskLike);
1284 $maskLike = preg_replace(
'/\{yyyy\}/i',
'____', $maskLike);
1285 $maskLike = preg_replace(
'/\{yy\}/i',
'__', $maskLike);
1286 $maskLike = preg_replace(
'/\{y\}/i',
'_', $maskLike);
1287 $maskLike = preg_replace(
'/\{mm\}/i',
'__', $maskLike);
1288 $maskLike = preg_replace(
'/\{dd\}/i',
'__', $maskLike);
1290 if ($maskrefclient) {
1302 $sql =
"SELECT ".$field.
" as ref";
1303 $sql .=
" FROM ".MAIN_DB_PREFIX.$table;
1304 $sql .=
" WHERE ".$field.
" LIKE '".$db->escape($maskLike) . (
getDolGlobalString(
'SEARCH_FOR_NEXT_VAL_ON_START_ONLY') ?
"%" :
"") .
"'";
1305 $sql .=
" AND ".$field.
" NOT LIKE '%PROV%'";
1307 $sql .=
" AND entity IN (".getEntity($sharetable).
")";
1308 } elseif (!empty($forceentity)) {
1309 $sql .=
" AND entity IN (".$db->sanitize($forceentity).
")";
1315 $sql .=
" AND ".$sqlwhere;
1318 dol_syslog(
"functions2::get_next_value mode=".$mode, LOG_DEBUG);
1319 $resql = $db->query($sql);
1321 $obj = $db->fetch_object($resql);
1330 } elseif ($mode ==
'next') {
1332 $maskrefclient_counter = 0;
1335 if ($counter >= pow(10,
dol_strlen($maskcounter))) {
1336 $counter =
'ErrorMaxNumberReachForThisMask';
1339 if (!empty($maskrefclient_maskcounter)) {
1343 $maskrefclient_posnumstart = strpos($maskwithnocode, $maskrefclient_maskcounter, strpos($maskwithnocode, $maskrefclient));
1344 if ($maskrefclient_posnumstart <= 0) {
1345 return 'ErrorBadMask';
1347 $maskrefclient_sqlstring =
'SUBSTRING('.$field.
', '.($maskrefclient_posnumstart + 1).
', '.
dol_strlen($maskrefclient_maskcounter).
')';
1352 $maskrefclient_maskLike = str_replace(
"%",
"_", $maskrefclient_maskLike);
1354 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{yyyy}'),
'____', $maskrefclient_maskLike);
1355 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{yy}'),
'__', $maskrefclient_maskLike);
1356 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{y}'),
'_', $maskrefclient_maskLike);
1357 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{mm}'),
'__', $maskrefclient_maskLike);
1358 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{dd}'),
'__', $maskrefclient_maskLike);
1360 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{'.$masktri.
'}'), str_pad(
"",
dol_strlen($maskcounter),
"_"), $maskrefclient_maskLike);
1362 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{'.$maskrefclient.
'}'), $maskrefclient_clientcode.str_pad(
"",
dol_strlen($maskrefclient_maskcounter),
"_"), $maskrefclient_maskLike);
1365 $maskrefclient_sql =
"SELECT MAX(".$maskrefclient_sqlstring.
") as val";
1366 $maskrefclient_sql .=
" FROM ".MAIN_DB_PREFIX.$table;
1368 $maskrefclient_sql .=
" WHERE ".$field.
" LIKE '".$db->escape($maskrefclient_maskLike) . (
getDolGlobalString(
'SEARCH_FOR_NEXT_VAL_ON_START_ONLY') ?
"%" :
"") .
"'";
1370 $maskrefclient_sql .=
" AND entity IN (".getEntity($sharetable).
")";
1371 } elseif (!empty($forceentity)) {
1372 $maskrefclient_sql .=
" AND entity IN (".$db->sanitize($forceentity).
")";
1375 $maskrefclient_sql .= $where;
1378 $maskrefclient_sql .=
' AND '.$sqlwhere;
1380 $maskrefclient_sql .=
" AND (SUBSTRING(".$field.
", ".(strpos($maskwithnocode, $maskrefclient) + 1).
", ".
dol_strlen($maskrefclient_maskclientcode).
") = '".$db->escape($maskrefclient_clientcode).
"')";
1382 dol_syslog(
"functions2::get_next_value maskrefclient", LOG_DEBUG);
1383 $maskrefclient_resql = $db->query($maskrefclient_sql);
1384 if ($maskrefclient_resql) {
1385 $maskrefclient_obj = $db->fetch_object($maskrefclient_resql);
1386 $maskrefclient_counter = $maskrefclient_obj->val;
1391 if (empty($maskrefclient_counter) || preg_match(
'/[^0-9]/i', $maskrefclient_counter)) {
1392 $maskrefclient_counter = $maskrefclient_maskoffset;
1394 $maskrefclient_counter++;
1401 if (!empty($yearoffsettype) && !is_numeric($yearoffsettype) && $yearoffsettype !=
'=') {
1402 $numFinal = preg_replace(
'/\{yyyy\}/i', (
string) ((
int) date(
"Y", $date) + $yearoffset), $numFinal);
1403 $numFinal = preg_replace(
'/\{yy\}/i', (
string) ((
int) date(
"y", $date) + $yearoffset), $numFinal);
1404 $numFinal = preg_replace(
'/\{y\}/i', (
string) ((
int) substr((
string) date(
"y", $date), 1, 1) + $yearoffset), $numFinal);
1406 $numFinal = preg_replace(
'/\{yyyy\}/i', date(
"Y", $date), $numFinal);
1407 $numFinal = preg_replace(
'/\{yy\}/i', date(
"y", $date), $numFinal);
1408 $numFinal = preg_replace(
'/\{y\}/i', substr(date(
"y", $date), 1, 1), $numFinal);
1410 $numFinal = preg_replace(
'/\{mm\}/i', date(
"m", $date), $numFinal);
1411 $numFinal = preg_replace(
'/\{dd\}/i', date(
"d", $date), $numFinal);
1414 $maskbefore =
'{'.$masktri.
'}';
1415 $maskafter = str_pad($counter,
dol_strlen($maskcounter),
"0", STR_PAD_LEFT);
1417 $numFinal = str_replace($maskbefore, $maskafter, $numFinal);
1420 if ($maskrefclient) {
1422 $maskrefclient_maskbefore =
'{'.$maskrefclient.
'}';
1423 $maskrefclient_maskafter = $maskrefclient_clientcode;
1424 if (
dol_strlen($maskrefclient_maskcounter) > 0) {
1425 $maskrefclient_maskafter .= str_pad((
string) $maskrefclient_counter,
dol_strlen($maskrefclient_maskcounter),
"0", STR_PAD_LEFT);
1427 $numFinal = str_replace($maskrefclient_maskbefore, (
string) $maskrefclient_maskafter, $numFinal);
1432 $masktype_maskbefore =
'{'.$masktype.
'}';
1433 $masktype_maskafter = $masktype_value;
1434 $numFinal = str_replace($masktype_maskbefore, $masktype_maskafter, $numFinal);
1439 $maskuser_maskbefore =
'{'.$maskuser.
'}';
1440 $maskuser_maskafter = $maskuser_value;
1441 $numFinal = str_replace($maskuser_maskbefore, $maskuser_maskafter, $numFinal);
1444 $numFinal =
"ErrorBadMode";
1445 dol_syslog(
"functions2::get_next_value ErrorBadMode '$mode'", LOG_ERR);
1448 dol_syslog(
"functions2::get_next_value return ".$numFinal, LOG_DEBUG);
1488 $hasglobalcounter =
false;
1489 $maskrefclient_maskcounter =
'';
1493 if (preg_match(
'/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i', $mask, $reg)) {
1494 $masktri = $reg[1].(isset($reg[2]) ? $reg[2] :
'').(isset($reg[3]) ? $reg[3] :
'');
1495 $maskcounter = $reg[1];
1496 $hasglobalcounter =
true;
1500 $maskcounter =
'00000';
1505 return 'ErrorCounterMustHaveMoreThan3Digits';
1509 $regClientRef = array();
1510 if (preg_match(
'/\{(c+)(0*)\}/i', $mask, $regClientRef)) {
1511 $maskrefclient = $regClientRef[1].$regClientRef[2];
1512 $maskrefclient_maskclientcode = $regClientRef[1];
1513 $maskrefclient_maskcounter = $regClientRef[2];
1514 $maskrefclient_maskoffset = 0;
1515 $maskrefclient_clientcode = substr(
'', 0,
dol_strlen($maskrefclient_maskclientcode));
1516 $maskrefclient_clientcode = str_pad($maskrefclient_clientcode,
dol_strlen($maskrefclient_maskclientcode),
"#", STR_PAD_RIGHT);
1518 if (
dol_strlen($maskrefclient_maskcounter) > 0 &&
dol_strlen($maskrefclient_maskcounter) < 3) {
1519 return 'ErrorCounterMustHaveMoreThan3Digits';
1522 $maskrefclient =
'';
1526 if (!$hasglobalcounter && ($maskrefclient_maskcounter ==
'')) {
1527 return 'ErrorBadMask';
1530 $maskwithonlyymcode = $mask;
1531 $maskwithonlyymcode = preg_replace(
'/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i', $maskcounter, $maskwithonlyymcode);
1532 $maskwithonlyymcode = preg_replace(
'/\{dd\}/i',
'dd', $maskwithonlyymcode);
1533 $maskwithonlyymcode = preg_replace(
'/\{(c+)(0*)\}/i', $maskrefclient, $maskwithonlyymcode);
1534 $maskwithnocode = $maskwithonlyymcode;
1535 $maskwithnocode = preg_replace(
'/\{yyyy\}/i',
'yyyy', $maskwithnocode);
1536 $maskwithnocode = preg_replace(
'/\{yy\}/i',
'yy', $maskwithnocode);
1537 $maskwithnocode = preg_replace(
'/\{y\}/i',
'y', $maskwithnocode);
1538 $maskwithnocode = preg_replace(
'/\{mm\}/i',
'mm', $maskwithnocode);
1544 if (!empty($reg[2]) && preg_match(
'/^\+/', $reg[2])) {
1545 $maskoffset = preg_replace(
'/^\+/',
'', $reg[2]);
1547 if (!empty($reg[3]) && preg_match(
'/^\+/', $reg[3])) {
1548 $maskoffset = preg_replace(
'/^\+/',
'', $reg[3]);
1554 if (!empty($reg[2]) && preg_match(
'/^@/', $reg[2])) {
1555 $maskraz = preg_replace(
'/^@/',
'', $reg[2]);
1557 if (!empty($reg[3]) && preg_match(
'/^@/', $reg[3])) {
1558 $maskraz = preg_replace(
'/^@/',
'', $reg[3]);
1560 if ($maskraz >= 0) {
1561 if ($maskraz == 99) {
1562 $maskraz = (int) date(
'm');
1563 $resetEveryMonth =
true;
1565 if ($maskraz > 12) {
1566 return 'ErrorBadMaskBadRazMonth';
1570 if ($maskraz > 1 && !preg_match(
'/^(.*)\{(y+)\}\{(m+)\}/i', $maskwithonlyymcode, $reg)) {
1571 return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
1573 if ($maskraz <= 1 && !preg_match(
'/^(.*)\{(y+)\}/i', $maskwithonlyymcode, $reg)) {
1574 return 'ErrorCantUseRazIfNoYearInMask';
1580 if (function_exists(
'mb_strrpos')) {
1581 $posnumstart = mb_strrpos($maskwithnocode, $maskcounter, 0,
'UTF-8');
1583 $posnumstart = strrpos($maskwithnocode, $maskcounter);
1585 if ($posnumstart < 0) {
1586 return 'ErrorBadMaskFailedToLocatePosOfSequence';
1598 dol_syslog(
"functions2::check_value result=".$result, LOG_DEBUG);
1655 if (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/i', $stime, $reg)) {
1657 $annee = (int) $reg[1];
1658 $mois = (int) $reg[2];
1659 $jour = (int) $reg[3];
1674 if ((
int) date(
"w", mktime(12, 0, 0, $mois, $jour, $annee)) == 0) {
1675 $jeudiSemaine = mktime(12, 0, 0, $mois, $jour, $annee) - 3 * 24 * 60 * 60;
1676 } elseif (date(
"w", mktime(12, 0, 0, $mois, $jour, $annee)) < 4) {
1677 $jeudiSemaine = mktime(12, 0, 0, $mois, $jour, $annee) + (4 - (int) date(
"w", mktime(12, 0, 0, $mois, $jour, $annee))) * 24 * 60 * 60;
1678 } elseif ((
int) date(
"w", mktime(12, 0, 0, $mois, $jour, $annee)) > 4) {
1679 $jeudiSemaine = mktime(12, 0, 0, $mois, $jour, $annee) - ((int) date(
"w", mktime(12, 0, 0, $mois, $jour, $annee)) - 4) * 24 * 60 * 60;
1681 $jeudiSemaine = mktime(12, 0, 0, $mois, $jour, $annee);
1685 if ((
int) date(
"w", mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine))) == 0) {
1686 $premierJeudiAnnee = mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine)) + 4 * 24 * 60 * 60;
1687 } elseif ((
int) date(
"w", mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine))) < 4) {
1688 $premierJeudiAnnee = mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine)) + (4 - (int) date(
"w", mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine)))) * 24 * 60 * 60;
1689 } elseif ((
int) date(
"w", mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine))) > 4) {
1690 $premierJeudiAnnee = mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine)) + (7 - ((int) date(
"w", mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine))) - 4)) * 24 * 60 * 60;
1692 $premierJeudiAnnee = mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine));
1698 (int) date(
"z", mktime(12, 0, 0, (
int) date(
"m", $jeudiSemaine), (
int) date(
"d", $jeudiSemaine), (
int) date(
"Y", $jeudiSemaine)))
1700 (
int) date(
"z", mktime(12, 0, 0, (
int) date(
"m", $premierJeudiAnnee), (
int) date(
"d", $premierJeudiAnnee), (
int) date(
"Y", $premierJeudiAnnee)))
1705 if ($numeroSemaine == 53) {
1708 ((
int) date(
"w", mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine))) == 4)
1710 ((
int) date(
"w", mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine))) == 3)
1711 && ((int) date(
"z", mktime(12, 0, 0, 12, 31, (
int) date(
"Y", $jeudiSemaine))) == 365)
1714 $numeroSemaine = 53;
1722 return sprintf(
"%02d", $numeroSemaine);