904function get_next_value($db, $mask, $table, $field, $where =
'', $objsoc =
'', $date =
'', $mode =
'next', $bentityon =
true, $objuser =
null, $forceentity =
null)
908 if (!is_object($objsoc)) {
909 $valueforccc = $objsoc;
910 } elseif ($table ==
"commande_fournisseur" || $table ==
"facture_fourn" || $table ==
"paiementfourn") {
916 $sharetable = $table;
917 if ($table ==
'facture' || $table ==
'invoice') {
918 $sharetable =
'invoicenumber';
934 $hasglobalcounter =
false;
937 if (preg_match(
'/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i', $mask, $reg)) {
938 $masktri = $reg[1].(!empty($reg[2]) ? $reg[2] :
'').(!empty($reg[3]) ? $reg[3] :
'');
939 $maskcounter = $reg[1];
940 $hasglobalcounter =
true;
944 $maskcounter =
'00000';
949 $resetEveryMonth =
false;
951 return 'ErrorCounterMustHaveMoreThan3Digits';
955 $regClientRef = array();
956 if (preg_match(
'/\{(c+)(0*)\}/i', $mask, $regClientRef)) {
957 $maskrefclient = $regClientRef[1].$regClientRef[2];
958 $maskrefclient_maskclientcode = $regClientRef[1];
959 $maskrefclient_maskcounter = $regClientRef[2];
960 $maskrefclient_maskoffset = 0;
961 $maskrefclient_clientcode = substr($valueforccc, 0,
dol_strlen($maskrefclient_maskclientcode));
962 $maskrefclient_clientcode = str_pad($maskrefclient_clientcode,
dol_strlen($maskrefclient_maskclientcode),
"#", STR_PAD_RIGHT);
965 return 'ErrorCounterMustHaveMoreThan3Digits';
972 if (!$hasglobalcounter && ($maskrefclient_maskcounter ==
'')) {
973 return 'ErrorBadMask';
978 if (preg_match(
'/\{(t+)\}/i', $mask, $regType)) {
979 $masktype = $regType[1];
980 $masktype_value =
dol_substr(preg_replace(
'/^TE_/',
'', $objsoc->typent_code), 0,
dol_strlen($regType[1]));
981 $masktype_value = str_pad($masktype_value,
dol_strlen($regType[1]),
"#", STR_PAD_RIGHT);
984 $masktype_value =
'';
989 if (preg_match(
'/\{(u+)\}/i', $mask, $regType)) {
990 $lastname =
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
991 if (is_object($objuser)) {
992 $lastname = $objuser->lastname;
995 $maskuser = $regType[1];
996 $maskuser_value = substr($lastname, 0,
dol_strlen($regType[1]));
997 $maskuser_value = str_pad($maskuser_value,
dol_strlen($regType[1]),
"#", STR_PAD_RIGHT);
1000 $maskuser_value =
'';
1004 $maskperso = array();
1005 $maskpersonew = array();
1008 while (preg_match(
'/\{([A-Z]+)\-([0-9]+)\}/', $tmpmask, $regKey)) {
1009 $maskperso[$regKey[1]] =
'{'.$regKey[1].
'-'.$regKey[2].
'}';
1011 $maskpersonew[$regKey[1]] = str_pad(
'', (
int) $regKey[2],
'_', STR_PAD_RIGHT);
1012 $tmpmask = preg_replace(
'/\{'.$regKey[1].
'\-'.$regKey[2].
'\}/i', $maskpersonew[$regKey[1]], $tmpmask);
1015 if (strstr($mask,
'user_extra_')) {
1016 $start =
"{user_extra_";
1019 if (!empty($user->array_options[
'options_'.$extra])) {
1020 $mask = preg_replace(
'#('.$start.
')(.*?)('.$end.
')#si', $user->array_options[
'options_'.$extra], $mask);
1023 $maskwithonlyymcode = $mask;
1024 $maskwithonlyymcode = preg_replace(
'/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i', $maskcounter, $maskwithonlyymcode);
1025 $maskwithonlyymcode = preg_replace(
'/\{dd\}/i',
'dd', $maskwithonlyymcode);
1026 $maskwithonlyymcode = preg_replace(
'/\{(c+)(0*)\}/i', $maskrefclient, $maskwithonlyymcode);
1027 $maskwithonlyymcode = preg_replace(
'/\{(t+)\}/i', $masktype_value, $maskwithonlyymcode);
1028 $maskwithonlyymcode = preg_replace(
'/\{(u+)\}/i', $maskuser_value, $maskwithonlyymcode);
1029 foreach ($maskperso as $key => $val) {
1030 $maskwithonlyymcode = preg_replace(
'/'.preg_quote($val,
'/').
'/i', $maskpersonew[$key], $maskwithonlyymcode);
1032 $maskwithnocode = $maskwithonlyymcode;
1033 $maskwithnocode = preg_replace(
'/\{yyyy\}/i',
'yyyy', $maskwithnocode);
1034 $maskwithnocode = preg_replace(
'/\{yy\}/i',
'yy', $maskwithnocode);
1035 $maskwithnocode = preg_replace(
'/\{y\}/i',
'y', $maskwithnocode);
1036 $maskwithnocode = preg_replace(
'/\{mm\}/i',
'mm', $maskwithnocode);
1043 if (!empty($reg[2]) && preg_match(
'/^\+/', $reg[2])) {
1044 $maskoffset = preg_replace(
'/^\+/',
'', $reg[2]);
1046 if (!empty($reg[3]) && preg_match(
'/^\+/', $reg[3])) {
1047 $maskoffset = preg_replace(
'/^\+/',
'', $reg[3]);
1053 $yearoffsettype =
false;
1056 if (!empty($reg[2]) && preg_match(
'/^@/', $reg[2])) {
1057 $yearoffsettype = preg_replace(
'/^@/',
'', $reg[2]);
1059 if (!empty($reg[3]) && preg_match(
'/^@/', $reg[3])) {
1060 $yearoffsettype = preg_replace(
'/^@/',
'', $reg[3]);
1064 if (is_numeric($yearoffsettype) && $yearoffsettype >= 1) {
1065 $maskraz = $yearoffsettype;
1066 } elseif ($yearoffsettype ===
'0' || (!empty($yearoffsettype) && !is_numeric($yearoffsettype) &&
getDolGlobalInt(
'SOCIETE_FISCAL_MONTH_START') > 1)) {
1072 if ($maskraz == 99) {
1073 $maskraz = (int) date(
'm', $date);
1074 $resetEveryMonth =
true;
1076 if ($maskraz > 12) {
1077 return 'ErrorBadMaskBadRazMonth';
1082 if (preg_match(
'/^(.*)\{(y+)\}\{(m+)\}/i', $maskwithonlyymcode, $reg)) {
1085 } elseif (preg_match(
'/^(.*)\{(m+)\}\{(y+)\}/i', $maskwithonlyymcode, $reg)) {
1089 return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
1093 return 'ErrorCantUseRazWithYearOnOneDigit';
1096 if (preg_match(
'/^(.*)\{(m+)\}\{(y+)\}/i', $maskwithonlyymcode, $reg)) {
1099 } elseif (preg_match(
'/^(.*)\{(y+)\}\{(m+)\}/i', $maskwithonlyymcode, $reg)) {
1102 } elseif (preg_match(
'/^(.*)\{(y+)\}/i', $maskwithonlyymcode, $reg)) {
1106 return 'ErrorCantUseRazIfNoYearInMask';
1110 $yearlen = $posy ?
dol_strlen($reg[$posy]) : 0;
1111 $monthlen = $posm ?
dol_strlen($reg[$posm]) : 0;
1114 $monthpos = ($yearpos + $yearlen);
1115 if ($posy == 3 && $posm == 2) {
1117 $yearpos = ($monthpos + $monthlen);
1122 $monthcomp = $maskraz;
1125 if (!empty($yearoffsettype) && !is_numeric($yearoffsettype) && $yearoffsettype !=
'=') {
1126 $currentyear = (int) date(
"Y", $date);
1127 $fiscaldate =
dol_mktime(
'0',
'0',
'0', $maskraz,
'1', $currentyear);
1128 $newyeardate =
dol_mktime(
'0',
'0',
'0',
'1',
'1', $currentyear);
1129 $nextnewyeardate =
dol_mktime(
'0',
'0',
'0',
'1',
'1', $currentyear + 1);
1133 if ($date >= $fiscaldate) {
1135 if ($date < $nextnewyeardate && $yearoffsettype ==
'+') {
1138 } elseif ($date >= $newyeardate && $yearoffsettype ==
'-') {
1142 } elseif ((
int) date(
"m", $date) < $maskraz && empty($resetEveryMonth)) {
1147 if ($yearlen == 4) {
1148 $yearcomp = sprintf(
"%04d", idate(
"Y", $date) + $yearoffset);
1149 } elseif ($yearlen == 2) {
1150 $yearcomp = sprintf(
"%02d", idate(
"y", $date) + $yearoffset);
1151 } elseif ($yearlen == 1) {
1152 $yearcomp = (int) substr(date(
'y', $date), 1, 1) + $yearoffset;
1154 if ($monthcomp > 1 && empty($resetEveryMonth)) {
1155 if ($yearlen == 4) {
1156 $yearcomp1 = sprintf(
"%04d", idate(
"Y", $date) + $yearoffset + 1);
1157 } elseif ($yearlen == 2) {
1158 $yearcomp1 = sprintf(
"%02d", idate(
"y", $date) + $yearoffset + 1);
1162 $sqlwhere .=
" (SUBSTRING(".$field.
", ".$yearpos.
", ".$yearlen.
") = '".$db->escape($yearcomp).
"'";
1163 $sqlwhere .=
" AND SUBSTRING(".$field.
", ".$monthpos.
", ".$monthlen.
") >= '".str_pad($monthcomp, $monthlen,
'0', STR_PAD_LEFT).
"')";
1165 $sqlwhere .=
" (SUBSTRING(".$field.
", ".$yearpos.
", ".$yearlen.
") = '".$db->escape($yearcomp1).
"'";
1166 $sqlwhere .=
" AND SUBSTRING(".$field.
", ".$monthpos.
", ".$monthlen.
") < '".str_pad($monthcomp, $monthlen,
'0', STR_PAD_LEFT).
"') ";
1168 } elseif ($resetEveryMonth) {
1169 $sqlwhere .=
"(SUBSTRING(".$field.
", ".$yearpos.
", ".$yearlen.
") = '".$db->escape($yearcomp).
"'";
1170 $sqlwhere .=
" AND SUBSTRING(".$field.
", ".$monthpos.
", ".$monthlen.
") = '".str_pad($monthcomp, $monthlen,
'0', STR_PAD_LEFT).
"')";
1172 $sqlwhere .=
"(SUBSTRING(".$field.
", ".$yearpos.
", ".$yearlen.
") = '".$db->escape($yearcomp).
"')";
1179 if (function_exists(
'mb_strrpos')) {
1180 $posnumstart = mb_strrpos($maskwithnocode, $maskcounter, 0,
'UTF-8');
1182 $posnumstart = strrpos($maskwithnocode, $maskcounter);
1184 if ($posnumstart < 0) {
1185 return 'ErrorBadMaskFailedToLocatePosOfSequence';
1187 $sqlstring =
"SUBSTRING(".$field.
", ".($posnumstart + 1).
", ".
dol_strlen($maskcounter).
")";
1191 $maskLike = str_replace(
"%",
"_", $maskLike);
1194 $maskLike = preg_replace(
'/\{yyyy\}/i',
'____', $maskLike);
1195 $maskLike = preg_replace(
'/\{yy\}/i',
'__', $maskLike);
1196 $maskLike = preg_replace(
'/\{y\}/i',
'_', $maskLike);
1197 $maskLike = preg_replace(
'/\{mm\}/i',
'__', $maskLike);
1198 $maskLike = preg_replace(
'/\{dd\}/i',
'__', $maskLike);
1201 if ($maskrefclient) {
1211 foreach ($maskperso as $key => $val) {
1212 $maskLike = str_replace(
dol_string_nospecial($maskperso[$key]), $maskpersonew[$key], $maskLike);
1217 $sql =
"SELECT MAX(".$sqlstring.
") as val";
1218 $sql .=
" FROM ".MAIN_DB_PREFIX.$table;
1219 $sql .=
" WHERE ".$field.
" LIKE '".$db->escape($maskLike) . (
getDolGlobalString(
'SEARCH_FOR_NEXT_VAL_ON_START_ONLY') ?
"%" :
"") .
"'";
1220 $sql .=
" AND ".$field.
" NOT LIKE '(PROV%)'";
1226 $sql .=
" AND ". $db->regexpsql($sqlstring,
'^[0-9]+$', 1);
1230 $sql .=
" AND entity IN (".getEntity($sharetable).
")";
1231 } elseif (!empty($forceentity)) {
1232 $sql .=
" AND entity IN (".$db->sanitize($forceentity).
")";
1238 $sql .=
" AND ".$sqlwhere;
1242 dol_syslog(
"functions2::get_next_value mode=".$mode, LOG_DEBUG);
1243 $resql = $db->query($sql);
1245 $obj = $db->fetch_object($resql);
1246 $counter = $obj->val;
1252 if (empty($counter)) {
1253 $counter = $maskoffset;
1254 } elseif (preg_match(
'/[^0-9]/i', $counter)) {
1255 dol_syslog(
"Error, the last counter found is '".$counter.
"' so is not a numeric value. We will restart to 1.", LOG_ERR);
1257 } elseif ($counter < $maskoffset && !
getDolGlobalString(
'MAIN_NUMBERING_OFFSET_ONLY_FOR_FIRST')) {
1258 $counter = $maskoffset;
1261 if ($mode ==
'last') {
1262 $counterpadded = str_pad($counter,
dol_strlen($maskcounter),
"0", STR_PAD_LEFT);
1266 $maskLike = str_replace(
"%",
"_", $maskLike);
1268 $maskLike = preg_replace(
'/\{yyyy\}/i',
'____', $maskLike);
1269 $maskLike = preg_replace(
'/\{yy\}/i',
'__', $maskLike);
1270 $maskLike = preg_replace(
'/\{y\}/i',
'_', $maskLike);
1271 $maskLike = preg_replace(
'/\{mm\}/i',
'__', $maskLike);
1272 $maskLike = preg_replace(
'/\{dd\}/i',
'__', $maskLike);
1274 if ($maskrefclient) {
1286 $sql =
"SELECT ".$field.
" as ref";
1287 $sql .=
" FROM ".MAIN_DB_PREFIX.$table;
1288 $sql .=
" WHERE ".$field.
" LIKE '".$db->escape($maskLike) . (
getDolGlobalString(
'SEARCH_FOR_NEXT_VAL_ON_START_ONLY') ?
"%" :
"") .
"'";
1289 $sql .=
" AND ".$field.
" NOT LIKE '%PROV%'";
1291 $sql .=
" AND entity IN (".getEntity($sharetable).
")";
1292 } elseif (!empty($forceentity)) {
1293 $sql .=
" AND entity IN (".$db->sanitize($forceentity).
")";
1299 $sql .=
" AND ".$sqlwhere;
1302 dol_syslog(
"functions2::get_next_value mode=".$mode, LOG_DEBUG);
1303 $resql = $db->query($sql);
1305 $obj = $db->fetch_object($resql);
1314 } elseif ($mode ==
'next') {
1316 $maskrefclient_counter = 0;
1319 if ($counter >= pow(10,
dol_strlen($maskcounter))) {
1320 $counter =
'ErrorMaxNumberReachForThisMask';
1323 if (!empty($maskrefclient_maskcounter)) {
1327 $maskrefclient_posnumstart = strpos($maskwithnocode, $maskrefclient_maskcounter, strpos($maskwithnocode, $maskrefclient));
1328 if ($maskrefclient_posnumstart <= 0) {
1329 return 'ErrorBadMask';
1331 $maskrefclient_sqlstring =
'SUBSTRING('.$field.
', '.($maskrefclient_posnumstart + 1).
', '.
dol_strlen($maskrefclient_maskcounter).
')';
1336 $maskrefclient_maskLike = str_replace(
"%",
"_", $maskrefclient_maskLike);
1338 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{yyyy}'),
'____', $maskrefclient_maskLike);
1339 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{yy}'),
'__', $maskrefclient_maskLike);
1340 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{y}'),
'_', $maskrefclient_maskLike);
1341 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{mm}'),
'__', $maskrefclient_maskLike);
1342 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{dd}'),
'__', $maskrefclient_maskLike);
1344 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{'.$masktri.
'}'), str_pad(
"",
dol_strlen($maskcounter),
"_"), $maskrefclient_maskLike);
1346 $maskrefclient_maskLike = str_replace(
dol_string_nospecial(
'{'.$maskrefclient.
'}'), $maskrefclient_clientcode.str_pad(
"",
dol_strlen($maskrefclient_maskcounter),
"_"), $maskrefclient_maskLike);
1349 $maskrefclient_sql =
"SELECT MAX(".$maskrefclient_sqlstring.
") as val";
1350 $maskrefclient_sql .=
" FROM ".MAIN_DB_PREFIX.$table;
1352 $maskrefclient_sql .=
" WHERE ".$field.
" LIKE '".$db->escape($maskrefclient_maskLike) . (
getDolGlobalString(
'SEARCH_FOR_NEXT_VAL_ON_START_ONLY') ?
"%" :
"") .
"'";
1354 $maskrefclient_sql .=
" AND entity IN (".getEntity($sharetable).
")";
1355 } elseif (!empty($forceentity)) {
1356 $sql .=
" AND entity IN (".$db->sanitize($forceentity).
")";
1359 $maskrefclient_sql .= $where;
1362 $maskrefclient_sql .=
' AND '.$sqlwhere;
1364 $maskrefclient_sql .=
" AND (SUBSTRING(".$field.
", ".(strpos($maskwithnocode, $maskrefclient) + 1).
", ".
dol_strlen($maskrefclient_maskclientcode).
") = '".$db->escape($maskrefclient_clientcode).
"')";
1366 dol_syslog(
"functions2::get_next_value maskrefclient", LOG_DEBUG);
1367 $maskrefclient_resql = $db->query($maskrefclient_sql);
1368 if ($maskrefclient_resql) {
1369 $maskrefclient_obj = $db->fetch_object($maskrefclient_resql);
1370 $maskrefclient_counter = $maskrefclient_obj->val;
1375 if (empty($maskrefclient_counter) || preg_match(
'/[^0-9]/i', $maskrefclient_counter)) {
1376 $maskrefclient_counter = $maskrefclient_maskoffset;
1378 $maskrefclient_counter++;
1385 if (!empty($yearoffsettype) && !is_numeric($yearoffsettype) && $yearoffsettype !=
'=') {
1386 $numFinal = preg_replace(
'/\{yyyy\}/i', (
string) ((
int) date(
"Y", $date) + $yearoffset), $numFinal);
1387 $numFinal = preg_replace(
'/\{yy\}/i', (
string) ((
int) date(
"y", $date) + $yearoffset), $numFinal);
1388 $numFinal = preg_replace(
'/\{y\}/i', (
string) ((
int) substr((
string) date(
"y", $date), 1, 1) + $yearoffset), $numFinal);
1390 $numFinal = preg_replace(
'/\{yyyy\}/i', date(
"Y", $date), $numFinal);
1391 $numFinal = preg_replace(
'/\{yy\}/i', date(
"y", $date), $numFinal);
1392 $numFinal = preg_replace(
'/\{y\}/i', substr(date(
"y", $date), 1, 1), $numFinal);
1394 $numFinal = preg_replace(
'/\{mm\}/i', date(
"m", $date), $numFinal);
1395 $numFinal = preg_replace(
'/\{dd\}/i', date(
"d", $date), $numFinal);
1398 $maskbefore =
'{'.$masktri.
'}';
1399 $maskafter = str_pad($counter,
dol_strlen($maskcounter),
"0", STR_PAD_LEFT);
1401 $numFinal = str_replace($maskbefore, $maskafter, $numFinal);
1404 if ($maskrefclient) {
1406 $maskrefclient_maskbefore =
'{'.$maskrefclient.
'}';
1407 $maskrefclient_maskafter = $maskrefclient_clientcode;
1408 if (
dol_strlen($maskrefclient_maskcounter) > 0) {
1409 $maskrefclient_maskafter .= str_pad($maskrefclient_counter,
dol_strlen($maskrefclient_maskcounter),
"0", STR_PAD_LEFT);
1411 $numFinal = str_replace($maskrefclient_maskbefore, $maskrefclient_maskafter, $numFinal);
1416 $masktype_maskbefore =
'{'.$masktype.
'}';
1417 $masktype_maskafter = $masktype_value;
1418 $numFinal = str_replace($masktype_maskbefore, $masktype_maskafter, $numFinal);
1423 $maskuser_maskbefore =
'{'.$maskuser.
'}';
1424 $maskuser_maskafter = $maskuser_value;
1425 $numFinal = str_replace($maskuser_maskbefore, $maskuser_maskafter, $numFinal);
1428 $numFinal =
"ErrorBadMode";
1429 dol_syslog(
"functions2::get_next_value ErrorBadMode '$mode'", LOG_ERR);
1432 dol_syslog(
"functions2::get_next_value return ".$numFinal, LOG_DEBUG);
1472 $hasglobalcounter =
false;
1475 if (preg_match(
'/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i', $mask, $reg)) {
1476 $masktri = $reg[1].(isset($reg[2]) ? $reg[2] :
'').(isset($reg[3]) ? $reg[3] :
'');
1477 $maskcounter = $reg[1];
1478 $hasglobalcounter =
true;
1482 $maskcounter =
'00000';
1487 return 'ErrorCounterMustHaveMoreThan3Digits';
1491 $regClientRef = array();
1492 if (preg_match(
'/\{(c+)(0*)\}/i', $mask, $regClientRef)) {
1493 $maskrefclient = $regClientRef[1].$regClientRef[2];
1494 $maskrefclient_maskclientcode = $regClientRef[1];
1495 $maskrefclient_maskcounter = $regClientRef[2];
1496 $maskrefclient_maskoffset = 0;
1497 $maskrefclient_clientcode = substr(
'', 0,
dol_strlen($maskrefclient_maskclientcode));
1498 $maskrefclient_clientcode = str_pad($maskrefclient_clientcode,
dol_strlen($maskrefclient_maskclientcode),
"#", STR_PAD_RIGHT);
1500 if (
dol_strlen($maskrefclient_maskcounter) > 0 &&
dol_strlen($maskrefclient_maskcounter) < 3) {
1501 return 'ErrorCounterMustHaveMoreThan3Digits';
1504 $maskrefclient =
'';
1508 if (!$hasglobalcounter && ($maskrefclient_maskcounter ==
'')) {
1509 return 'ErrorBadMask';
1512 $maskwithonlyymcode = $mask;
1513 $maskwithonlyymcode = preg_replace(
'/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i', $maskcounter, $maskwithonlyymcode);
1514 $maskwithonlyymcode = preg_replace(
'/\{dd\}/i',
'dd', $maskwithonlyymcode);
1515 $maskwithonlyymcode = preg_replace(
'/\{(c+)(0*)\}/i', $maskrefclient, $maskwithonlyymcode);
1516 $maskwithnocode = $maskwithonlyymcode;
1517 $maskwithnocode = preg_replace(
'/\{yyyy\}/i',
'yyyy', $maskwithnocode);
1518 $maskwithnocode = preg_replace(
'/\{yy\}/i',
'yy', $maskwithnocode);
1519 $maskwithnocode = preg_replace(
'/\{y\}/i',
'y', $maskwithnocode);
1520 $maskwithnocode = preg_replace(
'/\{mm\}/i',
'mm', $maskwithnocode);
1526 if (!empty($reg[2]) && preg_match(
'/^\+/', $reg[2])) {
1527 $maskoffset = preg_replace(
'/^\+/',
'', $reg[2]);
1529 if (!empty($reg[3]) && preg_match(
'/^\+/', $reg[3])) {
1530 $maskoffset = preg_replace(
'/^\+/',
'', $reg[3]);
1536 if (!empty($reg[2]) && preg_match(
'/^@/', $reg[2])) {
1537 $maskraz = preg_replace(
'/^@/',
'', $reg[2]);
1539 if (!empty($reg[3]) && preg_match(
'/^@/', $reg[3])) {
1540 $maskraz = preg_replace(
'/^@/',
'', $reg[3]);
1542 if ($maskraz >= 0) {
1543 if ($maskraz == 99) {
1544 $maskraz = (int) date(
'm');
1545 $resetEveryMonth =
true;
1547 if ($maskraz > 12) {
1548 return 'ErrorBadMaskBadRazMonth';
1552 if ($maskraz > 1 && !preg_match(
'/^(.*)\{(y+)\}\{(m+)\}/i', $maskwithonlyymcode, $reg)) {
1553 return 'ErrorCantUseRazInStartedYearIfNoYearMonthInMask';
1555 if ($maskraz <= 1 && !preg_match(
'/^(.*)\{(y+)\}/i', $maskwithonlyymcode, $reg)) {
1556 return 'ErrorCantUseRazIfNoYearInMask';
1562 if (function_exists(
'mb_strrpos')) {
1563 $posnumstart = mb_strrpos($maskwithnocode, $maskcounter, 0,
'UTF-8');
1565 $posnumstart = strrpos($maskwithnocode, $maskcounter);
1567 if ($posnumstart < 0) {
1568 return 'ErrorBadMaskFailedToLocatePosOfSequence';
1580 dol_syslog(
"functions2::check_value result=".$result, LOG_DEBUG);
1637 if (preg_match(
'/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/i', $stime, $reg)) {
1639 $annee = (int) $reg[1];
1640 $mois = (int) $reg[2];
1641 $jour = (int) $reg[3];
1652 if ((
int) date(
"w", mktime(12, 0, 0, $mois, $jour, $annee)) == 0) {
1653 $jeudiSemaine = mktime(12, 0, 0, $mois, $jour, $annee) - 3 * 24 * 60 * 60;
1654 } elseif (date(
"w", mktime(12, 0, 0, $mois, $jour, $annee)) < 4) {
1655 $jeudiSemaine = mktime(12, 0, 0, $mois, $jour, $annee) + (4 - (int) date(
"w", mktime(12, 0, 0, $mois, $jour, $annee))) * 24 * 60 * 60;
1656 } elseif ((
int) date(
"w", mktime(12, 0, 0, $mois, $jour, $annee)) > 4) {
1657 $jeudiSemaine = mktime(12, 0, 0, $mois, $jour, $annee) - ((int) date(
"w", mktime(12, 0, 0, $mois, $jour, $annee)) - 4) * 24 * 60 * 60;
1659 $jeudiSemaine = mktime(12, 0, 0, $mois, $jour, $annee);
1663 if ((
int) date(
"w", mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine))) == 0) {
1664 $premierJeudiAnnee = mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine)) + 4 * 24 * 60 * 60;
1665 } elseif ((
int) date(
"w", mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine))) < 4) {
1666 $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;
1667 } elseif ((
int) date(
"w", mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine))) > 4) {
1668 $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;
1670 $premierJeudiAnnee = mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine));
1676 (int) date(
"z", mktime(12, 0, 0, (
int) date(
"m", $jeudiSemaine), (
int) date(
"d", $jeudiSemaine), (
int) date(
"Y", $jeudiSemaine)))
1678 (
int) date(
"z", mktime(12, 0, 0, (
int) date(
"m", $premierJeudiAnnee), (
int) date(
"d", $premierJeudiAnnee), (
int) date(
"Y", $premierJeudiAnnee)))
1683 if ($numeroSemaine == 53) {
1686 ((
int) date(
"w", mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine))) == 4)
1688 ((
int) date(
"w", mktime(12, 0, 0, 1, 1, (
int) date(
"Y", $jeudiSemaine))) == 3)
1689 && ((int) date(
"z", mktime(12, 0, 0, 12, 31, (
int) date(
"Y", $jeudiSemaine))) == 365)
1692 $numeroSemaine = 53;
1700 return sprintf(
"%02d", $numeroSemaine);