View Issue Details

IDProjectCategoryView StatusLast Update
0011002mantisbtadministrationpublic2009-10-05 15:55
Reporterwatergad Assigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status newResolutionopen 
Summary0011002: Project hierarchy support in the user administration page
Description

If you manage many projects within one mantis instance, assigning projects to users will become quite difficult. Especially with similar subproject names.

Definitely usefull feature is to support project hierarchy here.

TagsNo tags attached.
Attached Files
mantis_user_prj_hierarchy.png (11,957 bytes)   
mantis_user_prj_hierarchy.png (11,957 bytes)   
print_project_user_list_option_list2.txt (1,658 bytes)   
function print_project_user_list_option_list2( $p_user_id ) {
	$t_mantis_project_user_list_table = db_get_table( 'mantis_project_user_list_table' );
	$t_mantis_project_table = db_get_table( 'mantis_project_table' );
	$t_mantis_project_hierarchy_table = db_get_table( 'mantis_project_hierarchy_table' );

	$c_user_id = db_prepare_int( $p_user_id );
	$res_p = Array();

	$query = "SELECT DISTINCT p.id, p.name, IF(h.parent_id IS NULL, 0,h.parent_id) as parent_id, u.user_id
				FROM $t_mantis_project_table p
				LEFT JOIN $t_mantis_project_user_list_table u
				ON p.id=u.project_id AND u.user_id=" . db_param() . "
				LEFT JOIN $t_mantis_project_hierarchy_table h
				ON p.id=h.child_id
				WHERE p.enabled = " . db_param() . "
				ORDER BY p.name";
// 					 AND u.user_id IS NULL

	$result = db_query_bound( $query, Array( $c_user_id, true ) );
	$category_count = db_num_rows( $result );
	for( $i = 0;$i < $category_count;$i++ ) {
		$row = db_fetch_array( $result );
		$t_project_name = string_attribute( $row['name'] );
		$t_user_id = $row['id'];
		$t_tmp = string_attribute( $row['parent_id']);
		$res_p[$i] = Array( 'id' => $t_user_id, 'name' => $t_project_name, 'parent_id' => $t_tmp, 'user_id' => string_attribute( $row['user_id']) );
	}
recprj( $res_p, 0, 0 );
}

function recprj( $prj, $id, $lev = 0 )
{
	foreach($prj as $pr)
	{
		if( $pr['parent_id'] == $id ){
			if (strlen($pr['user_id'])==0) $dis = ''; else $dis = ' disabled';
			echo "<option".$dis." value=\"".$pr['id']."\">".str_repeat("&nbsp;",$lev).str_repeat("&raquo;",$lev).$pr['name']."</option>";
			recprj( $prj, $pr['id'], $lev+1 );
		}		
	}
}
print_project_user_list.txt (3,290 bytes)   
function print_project_user_list( $p_user_id, $p_include_remove_link = true ) {
	$t_mantis_project_user_list_table = db_get_table( 'mantis_project_user_list_table' );
	$t_mantis_project_table = db_get_table( 'mantis_project_table' );
	$t_mantis_project_hierarchy_table = db_get_table( 'mantis_project_hierarchy_table' );

	$res_p = Array();

	$c_user_id = db_prepare_int( $p_user_id );
/*
	$query = "SELECT DISTINCT p.id, p.name, p.view_state, u.access_level
				FROM $t_mantis_project_table p
				LEFT JOIN $t_mantis_project_user_list_table u
				ON p.id=u.project_id
				WHERE p.enabled = '1' AND
					u.user_id=" . db_param() . "
				ORDER BY p.name";

*/
	$query = "SELECT DISTINCT p.id, p.name, p.view_state, u.access_level, 
	IF(h.parent_id IS NULL, 0,h.parent_id) as parent_id, u.user_id
				FROM $t_mantis_project_table p
				LEFT JOIN $t_mantis_project_user_list_table u
				ON p.id=u.project_id AND u.user_id=" . db_param() . "
				LEFT JOIN $t_mantis_project_hierarchy_table h
				ON p.id=h.child_id
				WHERE p.enabled = '1'
				ORDER BY p.name";
	
//	$result = db_query_bound( $query, Array( $c_user_id ) );
	$result = db_query_bound( $query, Array( $c_user_id,$c_user_id ) );
	$category_count = db_num_rows( $result );
	for( $i = 0;$i < $category_count;$i++ ) {
		$row = db_fetch_array( $result );
		$t_project_id = $row['id'];
		$t_project_name = $row['name'];
		$t_view_state = $row['view_state'];
		$t_access_level = $row['access_level'];

		if(is_null($t_access_level))
			$t_access_level = '-';
		else
			$t_access_level = get_enum_element( 'access_levels', $t_access_level );

//		$t_access_level = get_enum_element( 'access_levels', $t_access_level );
		
		$t_view_state = get_enum_element( 'project_view_state', $t_view_state );
		
		$t_hierarchy = $row['parent_id'];
		$t_userid = $row['user_id'];

		$res_p[$i] = Array('id'=>$t_project_id,'name'=>$t_project_name,'view_state'=>$t_view_state,
			'access_level'=>$t_access_level,'project_view_state'=>$t_view_state,'parent_id'=>$t_hierarchy,'user_id'=>$t_userid);
/*
		echo $t_project_name . ' [' . $t_access_level . '] (' . $t_view_state . ')';
		if( $p_include_remove_link && access_has_project_level( config_get( 'project_user_threshold' ), $t_project_id ) ) {
			html_button( 'manage_user_proj_delete.php', lang_get( 'remove_link' ), array( 'project_id' => $t_project_id, 'user_id' => $p_user_id ) );
		}
		echo '<br />';
*/
	}
recprj2( $res_p, 0, 0, $p_user_id, $p_include_remove_link );
}
function recprj2( $prj, $id, $lev = 0, $user, $p_include_remove_link )
{
	foreach($prj as $pr)
	{
		if( $pr['parent_id'] == $id ){
            if( $lev == 0 ) echo "<strong><u>";
			echo str_repeat("&nbsp;",$lev).str_repeat("&raquo;",$lev).$pr['name']. ' [' . $pr['access_level'] . '] (' . $pr['view_state'] . ')';
			if( !is_null($pr['user_id']) && $p_include_remove_link && access_has_project_level( config_get( 'project_user_threshold' ), $pr['id'] ) ) {
				html_button( 'manage_user_proj_delete.php', lang_get( 'remove_link' ), array( 'project_id' => $pr['id'], 'user_id' => $user ) );
			}
            if( $lev == 0 ) echo "</u></strong>";
			echo '<br />';
			recprj2( $prj, $pr['id'], $lev+1, $user, $p_include_remove_link );
		}		
	}
}
print_project_user_list.txt (3,290 bytes)   
mantis_user_prj_hierarchy2.png (38,701 bytes)   
mantis_user_prj_hierarchy2.png (38,701 bytes)   

Activities

watergad

watergad

2009-10-05 13:21

reporter   ~0023065

Last edited: 2009-10-05 13:25

I forgot to say: I'm talking about manage_user_edit_page.php page.

PNG attachment: I suppose something like that is acceptable
TXT attachment: That's how I outraged print_project_user_list_option_list2 function to achieve these goals. Yes, I feel very shame for such code (: Its just a quick edit to launch Mantis for me soon. Hope you'll do it anew right way (:

The same will be useful for the "Assigned projects" enumeration (the previous block).

watergad

watergad

2009-10-05 15:47

reporter   ~0023069

Last edited: 2009-10-06 06:48

Because I'm stained with this code anyway, attaching the same "temporary solution" for the print_project_user_list function of the print_api.php (assigned projects output) - also some horrible recursive code (:

Of course, both function edits got security hits (whole projects list is visible when assigning to user).

P.S. And print_project_user_list() modified this way misleading when just viewing user's projects.