diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php
index c2d07d177a4..d2118a55558 100644
--- a/htdocs/core/lib/company.lib.php
+++ b/htdocs/core/lib/company.lib.php
@@ -1574,7 +1574,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '', $showuserl
// Role
if (!empty($arrayfields['sc.role']['checked'])) {
- print '
';
+ print ' | ';
print $formcompany->showRoles("roles", $contactstatic, 'view');
print ' | ';
}
diff --git a/htdocs/core/lib/treeview.lib.php b/htdocs/core/lib/treeview.lib.php
index 5166fb849db..3b8a31e4f5f 100644
--- a/htdocs/core/lib/treeview.lib.php
+++ b/htdocs/core/lib/treeview.lib.php
@@ -109,7 +109,7 @@ function tree_showpad(&$fulltree, $key, $silent = 0)
* TODO Replace with jstree plugin instead of treeview plugin.
*
* @param array $tab Array of all elements
- * @param array $pere Array with parent ids ('rowid'=>,'mainmenu'=>,'leftmenu'=>,'fk_mainmenu=>,'fk_leftmenu=>)
+ * @param array $pere Array with parent ids ('rowid'=>,'mainmenu'=>,'leftmenu'=>,'fk_mainmenu'=>,'fk_leftmenu'=>)
* @param int $rang Level of element
* @param string $iddivjstree Id to use for parent ul element
* @param int $donoresetalreadyloaded Do not reset global array $donoresetalreadyloaded used to avoid to go down on an already processed record
@@ -148,13 +148,14 @@ function tree_recur($tab, $pere, $rang, $iddivjstree = 'iddivjstree', $donoreset
return; // Protect against infinite loop. Max 50 depth
}
- //ballayage du tableau
- $sizeoftab = count($tab);
+ // Loop on each element of tree
$ulprinted = 0;
- for ($x = 0; $x < $sizeoftab; $x++) {
+ foreach ($tab as $tmpkey => $tmpval) {
+ $x = $tmpkey;
+
//var_dump($tab[$x]);exit;
// If an element has $pere for parent
- if ($tab[$x]['fk_menu'] != -1 && $tab[$x]['fk_menu'] == $pere['rowid']) {
+ if ($tab[$x]['fk_menu'] != -1 && ((int) $tab[$x]['fk_menu']) == $pere['rowid']) {
//print 'rang='.$rang.'-x='.$x." rowid=".$tab[$x]['rowid']." tab[x]['fk_leftmenu'] = ".$tab[$x]['fk_leftmenu']." leftmenu pere = ".$pere['leftmenu']."
\n";
if (empty($ulprinted) && !empty($pere['rowid'])) {
if (!empty($tree_recur_alreadyadded[$tab[$x]['rowid']])) {
@@ -184,7 +185,7 @@ function tree_recur($tab, $pere, $rang, $iddivjstree = 'iddivjstree', $donoreset
// And now we search all its sons of lower level
tree_recur($tab, $tab[$x], $rang + 1, 'iddivjstree', 0, $showfk);
print '';
- } elseif (!empty($tab[$x]['rowid']) && $tab[$x]['fk_menu'] == -1 && $tab[$x]['fk_mainmenu'] == $pere['mainmenu'] && $tab[$x]['fk_leftmenu'] == $pere['leftmenu']) {
+ } elseif (!empty($tab[$x]['rowid']) && ((int) $tab[$x]['fk_menu']) == -1 && $tab[$x]['fk_mainmenu'] == $pere['mainmenu'] && $tab[$x]['fk_leftmenu'] == $pere['leftmenu']) {
//print 'rang='.$rang.'-x='.$x." rowid=".$tab[$x]['rowid']." tab[x]['fk_leftmenu'] = ".$tab[$x]['fk_leftmenu']." leftmenu pere = ".$pere['leftmenu']."
\n";
if (empty($ulprinted) && !empty($pere['rowid'])) {
if (!empty($tree_recur_alreadyadded[$tab[$x]['rowid']])) {
diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php
index 4809c7993c5..e873930bf55 100644
--- a/htdocs/fourn/facture/list.php
+++ b/htdocs/fourn/facture/list.php
@@ -1916,6 +1916,9 @@ while ($i < $imaxinloop) {
$totalarray['nbfield']++;
$totalarray['pos'][$totalarray['nbfield']] = 'totalam';
}
+ if (empty($totalarray['val']['totalam'])) {
+ $totalarray['val']['totalam'] = 0; // avoid PHP Warning: Undefined array key "totalam" on line 1891
+ }
$totalarray['val']['totalam'] += $totalpay;
}
diff --git a/htdocs/langs/en_US/users.lang b/htdocs/langs/en_US/users.lang
index e7d0395e661..e954f11f3a1 100644
--- a/htdocs/langs/en_US/users.lang
+++ b/htdocs/langs/en_US/users.lang
@@ -132,6 +132,7 @@ ShowAllPerms=Show all permission rows
HideAllPerms=Hide all permission rows
UserPublicPageDesc=You can enable a virtual card for this user. An url with the user profile and a barcode will be available to allow anybody with a smartphone to scan it and add your contact to its address book.
EnablePublicVirtualCard=Enable the user's virtual business card
+ExcludedByFilter=Non qualified by filters but shown to see its hierarchy
UserEnabledDisabled=User status changed: %s
AlternativeEmailForOAuth2=Alternative Email for OAuth2 login
ErrorUpdateCanceledDueToDuplicatedUniqueValue=Error, The update was canceled because one of the pieces of data, that should be unique, already exists
diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php
index 68279242c2d..bacbcd28f76 100644
--- a/htdocs/user/class/user.class.php
+++ b/htdocs/user/class/user.class.php
@@ -3810,7 +3810,7 @@ class User extends CommonObject
}
dol_syslog(get_class($this)."::get_full_tree dol_sort_array", LOG_DEBUG);
- $this->users = dol_sort_array($this->users, 'fullname', 'asc', true, false);
+ $this->users = dol_sort_array($this->users, 'fullname', 'asc', true, false, 1);
//var_dump($this->users);
diff --git a/htdocs/user/hierarchy.php b/htdocs/user/hierarchy.php
index 64d9436545b..5b8f5f29846 100644
--- a/htdocs/user/hierarchy.php
+++ b/htdocs/user/hierarchy.php
@@ -52,7 +52,7 @@ $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTI
$search_status = GETPOST('search_status', 'intcomma');
-if ($search_status == '' || $search_status == '0') {
+if ($search_status == '') {
$search_status = '1';
}
@@ -60,6 +60,7 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter',
$search_status = "";
}
+$search_employee = -1;
if ($contextpage == 'employeelist') {
$search_employee = 1;
}
@@ -104,10 +105,24 @@ $arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css
llxHeader('', $title, $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', 'bodyforlist');
-
+$filters = [];
+if (($search_status != '' && $search_status >= 0)) {
+ $filters[] = "statut = ".((int) $search_status);
+}
+if (($search_employee != '' && $search_employee >= 0)) {
+ $filters[] = "employee = ".((int) $search_employee);
+}
+$sqlfilter= '';
+if (!empty($filters)) {
+ $sqlfilter = join(' AND ', $filters);
+}
// Load hierarchy of users
-$user_arbo = $userstatic->get_full_tree(0, ($search_status != '' && $search_status >= 0) ? "statut = ".$search_status : '');
-
+$user_arbo_all = $userstatic->get_full_tree(0, '');
+if ($sqlfilter) {
+ $user_arbo = $userstatic->get_full_tree(0, $sqlfilter);
+} else {
+ $user_arbo = $user_arbo_all;
+}
// Count total nb of records
$nbtotalofrecords = count($user_arbo);
@@ -121,7 +136,8 @@ if (!is_array($user_arbo) && $user_arbo < 0) {
//var_dump($fulltree);
// Define data (format for treeview)
$data = array();
- $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
+ $data[0] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
+
foreach ($fulltree as $key => $val) {
$userstatic->id = $val['id'];
$userstatic->ref = (string) $val['id'];
@@ -159,15 +175,86 @@ if (!is_array($user_arbo) && $user_arbo < 0) {
$entry = '| '.$li.' | '.$userstatic->getLibStatut(2).' |
';
- $data[] = array(
+ $data[$val['rowid']] = array(
'rowid'=>$val['rowid'],
- 'fk_menu'=>$val['fk_user'],
+ 'fk_menu'=>$val['fk_user'], // TODO Replace fk_menu with fk_parent
'statut'=>$val['statut'],
'entry'=>$entry
);
}
- //var_dump($data);
+ // Loop on $data to link user linked to a parent that was excluded by the filter
+ foreach ($data as $key => $tmpdata) {
+ $idparent = $tmpdata['fk_menu'];
+ // Loop to check if parent exists
+ if ($idparent > 0) {
+ $parentfound = array_key_exists($idparent, $data) ? 1 : 0;
+
+ $i = 0;
+ while (!$parentfound && $i < 50) {
+ // Parent was not found but we need it to show the child, so we reintroduce the parent
+ if (!empty($user_arbo_all[$idparent])) {
+ $val = $user_arbo_all[$idparent];
+ $userstatic->id = $val['id'];
+ $userstatic->ref = $val['id'];
+ $userstatic->login = $val['login'];
+ $userstatic->firstname = $val['firstname'];
+ $userstatic->lastname = $val['lastname'];
+ $userstatic->statut = $val['statut'];
+ $userstatic->email = $val['email'];
+ $userstatic->gender = $val['gender'];
+ $userstatic->socid = $val['fk_soc'];
+ $userstatic->admin = $val['admin'];
+ $userstatic->entity = $val['entity'];
+ $userstatic->photo = $val['photo'];
+
+ $li = '';
+ $li .= $userstatic->getNomUrl(-1, '', 0, 1);
+ if (isModEnabled('multicompany') && $userstatic->admin && !$userstatic->entity) {
+ $li .= img_picto($langs->trans("SuperAdministrator"), 'redstar');
+ } elseif ($userstatic->admin) {
+ $li .= img_picto($langs->trans("Administrator"), 'star');
+ }
+ $li .= ' ('.$val['login'].($entitystring ? ' - '.$entitystring : '').')';
+ $li .= ' - '.$langs->trans("ExcludedByFilter").'';
+ $li .= '';
+
+ $entry = '| '.$li.' | '.$userstatic->getLibStatut(2).' |
';
+
+ $data[$idparent] = array(
+ 'rowid' => $idparent,
+ 'fk_menu' => $user_arbo_all[$idparent]['fk_user'],
+ 'statut' => $user_arbo_all[$idparent]['statut'],
+ 'entry' => $entry
+ );
+ $idparent = $user_arbo_all[$idparent]['fk_user'];
+ if ($idparent > 0) {
+ $parentfound = array_key_exists($idparent, $data) ? 1 : 0;
+ } else {
+ $parentfound = 1;
+ }
+ //var_dump($data[$idparent]);
+ } else {
+ // We should not be here. If a record has a parent id, parent id should be into $user_arbo_all
+ $data[$key]['fk_menu'] = -2;
+ if (empty($data[-2])) {
+ $li = ''.$langs->trans("ParentIDDoesNotExistAnymore").'';
+ $entry = '';
+ $data[-2] = array(
+ 'rowid'=>'-2',
+ 'fk_menu'=>null,
+ 'statut'=>'1',
+ 'entry'=>$entry
+ );
+ }
+ $parentfound = 1;
+ }
+
+ $i++;
+ }
+ }
+ }
+ //var_dump($data);exit;
$param = "&search_status=".urlencode($search_status);
$param = "&contextpage=".urlencode($contextpage);
@@ -211,8 +298,8 @@ if (!is_array($user_arbo) && $user_arbo < 0) {
print ' | ';
print ' | ';
// Status
- print '';
- print $form->selectarray('search_status', array('-1'=>'', '1'=>$langs->trans('Enabled')), $search_status, 0, 0, 0, '', 0, 0, 0, '', 'minwidth75imp');
+ print ' | ';
+ print $form->selectarray('search_status', array('-1'=>'', '0'=>$langs->trans('Disabled'), '1'=>$langs->trans('Enabled')), $search_status, 0, 0, 0, '', 0, 0, 0, '', 'minwidth75imp onrightofpage width100');
print ' | ';
// Action column
if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
@@ -230,7 +317,7 @@ if (!is_array($user_arbo) && $user_arbo < 0) {
}
print_liste_field_titre("HierarchicView");
print_liste_field_titre('', $_SERVER['PHP_SELF'], "", '', "", 'align="center"');
- print_liste_field_titre("Status", $_SERVER['PHP_SELF'], "", '', "", '', '', '', 'right ');
+ print_liste_field_titre("Status", $_SERVER['PHP_SELF'], "", '', "", '', '', '', 'right onrightofpage');
// Action column
if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', '', '', 'maxwidthsearch ');