瀏覽代碼

Merge branch '18.0' of git@github.com:Dolibarr/dolibarr.git into 19.0

Laurent Destailleur 1 年之前
父節點
當前提交
50833e00d0
共有 4 個文件被更改,包括 103 次插入14 次删除
  1. 7 6
      htdocs/core/lib/treeview.lib.php
  2. 1 0
      htdocs/langs/en_US/users.lang
  3. 1 1
      htdocs/user/class/user.class.php
  4. 94 7
      htdocs/user/hierarchy.php

+ 7 - 6
htdocs/core/lib/treeview.lib.php

@@ -103,7 +103,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 aleady processed record
@@ -142,13 +142,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']."<br>\n";
 			if (empty($ulprinted) && !empty($pere['rowid'])) {
 				if (!empty($tree_recur_alreadyadded[$tab[$x]['rowid']])) {
@@ -178,7 +179,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 '</li>';
-		} 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']."<br>\n";
 			if (empty($ulprinted) && !empty($pere['rowid'])) {
 				if (!empty($tree_recur_alreadyadded[$tab[$x]['rowid']])) {

+ 1 - 0
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

+ 1 - 1
htdocs/user/class/user.class.php

@@ -3765,7 +3765,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);
 

+ 94 - 7
htdocs/user/hierarchy.php

@@ -60,6 +60,7 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter',
 	$search_statut = "";
 }
 
+$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_statut != '' && $search_statut >= 0)) {
+	$filters[] = "statut = ".((int) $search_statut);
+}
+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_statut != '' && $search_statut >= 0) ? "statut = ".$search_statut : '');
-
+$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 = $val['id'];
@@ -159,15 +175,86 @@ if (!is_array($user_arbo) && $user_arbo < 0) {
 
 		$entry = '<table class="nobordernopadding centpercent"><tr class="trtree"><td class="'.($val['statut'] ? 'usertdenabled' : 'usertddisabled').'">'.$li.'</td><td align="right" class="'.($val['statut'] ? 'usertdenabled' : 'usertddisabled').'">'.$userstatic->getLibStatut(2).'</td></tr></table>';
 
-		$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 = '<span class="opacitymedium">';
+					$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 .= ' <span class="opacitymedium">('.$val['login'].($entitystring ? ' - '.$entitystring : '').')</span>';
+					$li .= ' - <span class="opacitymedium">'.$langs->trans("ExcludedByFilter").'</span>';
+					$li .= '</span>';
+
+					$entry = '<table class="nobordernopadding centpercent"><tr class="trtree"><td class="'.($val['statut'] ? 'usertdenabled' : 'usertddisabled').'">'.$li.'</td><td align="right" class="'.($val['statut'] ? 'usertdenabled' : 'usertddisabled').'">'.$userstatic->getLibStatut(2).'</td></tr></table>';
+
+					$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 = '<span class="opacitymedium">'.$langs->trans("ParentIDDoesNotExistAnymore").'</span>';
+						$entry = '<table class="nobordernopadding centpercent"><tr class="trtree"><td class="usertddisabled">'.$li.'</td><td align="right" class="usertddisabled"></td></tr></table>';
+						$data[-2] = array(
+							'rowid'=>'-2',
+							'fk_menu'=>null,
+							'statut'=>'1',
+							'entry'=>$entry
+						);
+					}
+					$parentfound = 1;
+				}
+
+				$i++;
+			}
+		}
+	}
+	//var_dump($data);exit;
 
 	$param = "&search_statut=".urlencode($search_statut);
 	$param = "&contextpage=".urlencode($contextpage);