diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 52859d2ea81..2b67b680615 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9894,6 +9894,21 @@ function complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $reg = array(); if ($mode == 'add' && !preg_match('/^\-/', $values[1])) { + $newtab = array(); + $postab = $h; + // detect if position set in $values[1] ie : +(2)mytab@mymodule (first tab is 0, second is one, ...) + $str = $values[1]; + $posstart = strpos($str, '('); + if ($posstart > 0) { + $posend = strpos($str, ')'); + if ($posstart > 0) { + $res1 = substr($str, $posstart + 1, $posend - $posstart -1); + if (is_numeric($res1)) { + $postab = (int) $res1; + $values[1] = '+' . substr($str, $posend + 1); + } + } + } if (count($values) == 6) { // new declaration with permissions: // $value='objecttype:+tabname1:Title1:langfile@mymodule:$user->rights->mymodule->read:/mymodule/mynewtab1.php?id=__ID__' @@ -9943,9 +9958,9 @@ function complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, } } - $head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[5]), 1); - $head[$h][1] = $label; - $head[$h][2] = str_replace('+', '', $values[1]); + $newtab[0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[5]), 1); + $newtab[1] = $label; + $newtab[2] = str_replace('+', '', $values[1]); $h++; } } elseif (count($values) == 5) { // case deprecated @@ -9976,11 +9991,13 @@ function complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $label = $langs->trans($values[2]); } - $head[$h][0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[4]), 1); - $head[$h][1] = $label; - $head[$h][2] = str_replace('+', '', $values[1]); + $newtab[0] = dol_buildpath(preg_replace('/__ID__/i', ((is_object($object) && !empty($object->id)) ? $object->id : ''), $values[4]), 1); + $newtab[1] = $label; + $newtab[2] = str_replace('+', '', $values[1]); $h++; } + // set tab at its position + $head = array_merge(array_slice($head, 0, $postab), array($newtab), array_slice($head, $postab)); } elseif ($mode == 'remove' && preg_match('/^\-/', $values[1])) { if ($values[0] != $type) { continue;