logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

mantisbt/core project_hierarchy_api.php,NONE,1.1 constant_inc.php,1.37,1.38: msg#00038

Subject: mantisbt/core project_hierarchy_api.php,NONE,1.1 constant_inc.php,1.37,1.38 current_user_api.php,1.26,1.27 filter_api.php,1.83,1.84 helper_api.php,1.53,1.54 html_api.php,1.147,1.148 news_api.php,1.18,1.19 print_api.php,1.113,1.114 project_api.php,1.64,1.65 summary_api.php,1.35,1.36 user_api.php,1.83,1.84
Update of /cvsroot/mantisbt/mantisbt/core
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3554/core

Modified Files:
        constant_inc.php current_user_api.php filter_api.php 
        helper_api.php html_api.php news_api.php print_api.php 
        project_api.php summary_api.php user_api.php 
Added Files:
        project_hierarchy_api.php 
Log Message:
Enh #5237: Support for subprojects that can be linked to several parent projects

Index: summary_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/summary_api.php,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- summary_api.php     12 Feb 2005 20:01:18 -0000      1.35
+++ summary_api.php     13 Feb 2005 21:36:38 -0000      1.36
@@ -35,17 +35,9 @@
                $t_project_id = helper_get_current_project();
                $t_user_id = auth_get_current_user_id();
 
-               #checking if it's a per project statistic or all projects
-               if ( ALL_PROJECTS == $t_project_id ) {
-                       # Only projects to which the user have access
-                       $t_accessible_projects_array = 
user_get_accessible_projects( $t_user_id );
-                       if ( count( $t_accessible_projects_array ) > 0 ) {
-                               $t_project_filter = ' (project_id='. implode( ' 
OR project_id=', $t_accessible_projects_array ).')';
-                       } else {
-                               $t_project_filter = '1=1';
-                       }
-               } else {
-                       $t_project_filter = " project_id='$t_project_id'";
+               $t_project_filter = helper_project_specific_where( 
$t_project_id );
+               if ( ' 1<>1' == $t_project_filter ) {
+                       return;
                }
 
                $query = "SELECT status, $p_enum
@@ -188,17 +180,9 @@
                $t_project_id = helper_get_current_project();
                $t_user_id = auth_get_current_user_id();
 
-               #checking if it's a per project statistic or all projects
-               if ( ALL_PROJECTS == $t_project_id ) {
-                       # Only projects to which the user have access
-                       $t_accessible_projects_array = 
user_get_accessible_projects( $t_user_id );
-                       if ( count( $t_accessible_projects_array ) > 0 ) {
-                               $specific_where = ' (project_id='. implode( ' 
OR project_id=', $t_accessible_projects_array ).')';
-                       } else {
-                               $specific_where = '1=1';
-                       }
-               } else {
-                       $specific_where = " project_id='$t_project_id'";
+               $specific_where = helper_project_specific_where( $t_project_id 
);
+               if ( ' 1<>1' == $specific_where ) {
+                       return;
                }
 
                $query = "SELECT COUNT(*)
@@ -233,19 +217,13 @@
        function summary_print_by_developer() {
                $t_mantis_bug_table = config_get( 'mantis_bug_table' );
                $t_mantis_user_table = config_get( 'mantis_user_table' );
+
                $t_project_id = helper_get_current_project();
                $t_user_id = auth_get_current_user_id();
 
-               if ( ALL_PROJECTS == $t_project_id ) {
-                       # Only projects to which the user have access
-                       $t_accessible_projects_array = 
user_get_accessible_projects( $t_user_id );
-                       if ( count( $t_accessible_projects_array ) > 0 ) {
-                               $specific_where = ' (project_id='. implode( ' 
OR project_id=', $t_accessible_projects_array ).')';
-                       } else {
-                               $specific_where = '1=1';
-                       }
-               } else {
-                       $specific_where = " project_id='$t_project_id'";
+               $specific_where = helper_project_specific_where( $t_project_id 
);
+               if ( ' 1<>1' == $specific_where ) {
+                       return;
                }
 
                $query = "SELECT handler_id, status
@@ -335,16 +313,9 @@
                $t_project_id = helper_get_current_project();
                $t_user_id = auth_get_current_user_id();
 
-               if ( ALL_PROJECTS == $t_project_id ) {
-                       # Only projects to which the user have access
-                       $t_accessible_projects_array = 
user_get_accessible_projects( $t_user_id );
-                       if ( count( $t_accessible_projects_array ) > 0 ) {
-                               $specific_where = ' (project_id='. implode( ' 
OR project_id=', $t_accessible_projects_array ).')';
-                       } else {
-                               $specific_where = '1=1';
-                       }
-               } else {
-                       $specific_where = " project_id='$t_project_id'";
+               $specific_where = helper_project_specific_where( $t_project_id 
);
+               if ( ' 1<>1' == $specific_where ) {
+                       return;
                }
 
                $query = "SELECT reporter_id, COUNT(*) as num
@@ -417,16 +388,9 @@
                $t_project_id = helper_get_current_project();
                $t_user_id = auth_get_current_user_id();
 
-               if ( ALL_PROJECTS == $t_project_id ) {
-                       # Only projects to which the user have access
-                       $t_accessible_projects_array = 
user_get_accessible_projects( $t_user_id );
-                       if ( count( $t_accessible_projects_array ) > 0 ) {
-                               $specific_where = ' (project_id='. implode( ' 
OR project_id=', $t_accessible_projects_array ).')';
-                       } else {
-                               $specific_where = '1=1';
-                       }
-               } else {
-                       $specific_where = " project_id='$t_project_id'";
+               $specific_where = helper_project_specific_where( $t_project_id 
);
+               if ( ' 1<>1' == $specific_where ) {
+                       return;
                }
 
                $query = "SELECT project_id, category, status
@@ -534,82 +498,66 @@
        }
        # --------------------
        # print bug counts by project
-       function summary_print_by_project() {
-               $t_mantis_bug_table = config_get( 'mantis_bug_table' );
+       function summary_print_by_project( $p_projects = null, $p_level = 0, 
$p_cache = null ) {
+               $t_mantis_bug_table     = config_get( 'mantis_bug_table' );
                $t_mantis_project_table = config_get( 'mantis_project_table' );
 
                $t_project_id = helper_get_current_project();
-               $t_user_id = auth_get_current_user_id();
 
-               # This function only works when "all projects" is selected
-               if ( ALL_PROJECTS != $t_project_id ) {
-                       return;
-               }
-
-               # Only projects to which the user have access
-               $t_accessible_projects_array = user_get_accessible_projects( 
$t_user_id );
-               if ( count( $t_accessible_projects_array ) > 0 ) {
-                       $specific_where = ' (project_id='. implode( ' OR 
project_id=', $t_accessible_projects_array ).')';
-               } else {
-                       $specific_where = '1=1';
+               if ( null == $p_projects ) {
+                       if ( ALL_PROJECTS == $t_project_id ) {
+                               $p_projects = 
current_user_get_accessible_projects();
+                       } else {
+                               $p_projects = Array( $t_project_id );
+                       }
                }
 
-               $query = "SELECT project_id, status
-                               FROM $t_mantis_bug_table
-                               WHERE $specific_where
-                               ORDER BY project_id";
-               $result = db_query( $query );
-
-               $t_last_project = -1;
-               $t_bugs_open = 0;
-               $t_bugs_resolved = 0;
-               $t_bugs_closed = 0;
-               $t_bugs_total = 0;
-
-               $t_resolved_val = RESOLVED;
-               $t_closed_val = CLOSED;
-
-               while ( $row = db_fetch_array( $result ) ) {
-                       extract( $row, EXTR_PREFIX_ALL, 'v' );
+               # Retrieve statistics one time to improve performance.
+               if ( null == $p_cache ) {
+                       $query = "SELECT project_id, status, COUNT( status ) AS 
count
+                                       FROM $t_mantis_bug_table
+                                       GROUP BY project_id, status";
 
-                       if ( ( $v_project_id != $t_last_project ) && ( -1 != 
$t_last_project ) ) {
-                               $query = "SELECT name
-                                               FROM $t_mantis_project_table
-                                               WHERE id=$t_last_project";
-                               $result2 = db_query( $query );
-                               $row2 = db_fetch_array( $result2 );
-                               summary_helper_print_row( $row2['name'], 
$t_bugs_open, $t_bugs_resolved, $t_bugs_closed, $t_bugs_total );
+                       $result = db_query( $query );
+                       $p_cache = Array();
 
-                               $t_bugs_open = 0;
-                               $t_bugs_resolved = 0;
-                               $t_bugs_closed = 0;
-                               $t_bugs_total = 0;
-                       }
+                       $t_resolved_val = RESOLVED;
+                       $t_closed_val = CLOSED;
 
-                       $t_bugs_total++;
+                       while ( $row = db_fetch_array( $result ) ) {
+                               extract( $row, EXTR_PREFIX_ALL, 'v' );
 
-                       switch( $v_status ) {
-                               case $t_resolved_val:
-                                                                               
$t_bugs_resolved++;
+                               switch( $v_status ) {
+                                       case $t_resolved_val:
+                                                                               
$p_cache[ $v_project_id ][ 'resolved' ]  = $v_count;
                                                                                
break;
-                               case $t_closed_val:
-                                                                               
$t_bugs_closed++;
+                                       case $t_closed_val:
+                                                                               
$p_cache[ $v_project_id ][ 'closed'   ]  = $v_count;
                                                                                
break;
-                               default:
-                                                                               
$t_bugs_open++;
+                                       default:
+                                                                               
$p_cache[ $v_project_id ][ 'open'     ] += $v_count;
                                                                                
break;
+                               }
                        }
-
-                       $t_last_project = $v_project_id;
                }
 
-               if ( 0 < $t_bugs_total ) {
-                       $query = "SELECT name
-                                       FROM $t_mantis_project_table
-                                       WHERE id=$t_last_project";
-                       $result2 = db_query( $query );
-                       $row2 = db_fetch_array( $result2 );
-                       summary_helper_print_row( $row2['name'], $t_bugs_open, 
$t_bugs_resolved, $t_bugs_closed, $t_bugs_total );
+               foreach ( $p_projects as $t_project ) {
+                       $t_name = str_repeat( "» ", $p_level ) . 
project_get_name( $t_project );
+
+                       $t_pdata = $p_cache[ $t_project ];
+
+                       $t_bugs_open     = $t_pdata['open'];
+                       $t_bugs_resolved = $t_pdata['resolved'];
+                       $t_bugs_closed   = $t_pdata['closed'];
+                       $t_bugs_total    = $t_bugs_open + $t_bugs_resolved + 
$t_bugs_closed;
+
+                       summary_helper_print_row( $t_name, $t_bugs_open, 
$t_bugs_resolved, $t_bugs_closed, $t_bugs_total );
+
+                       $t_subprojects = 
current_user_get_accessible_subprojects( $t_project );
+
+                       if ( count( $t_subprojects ) > 0 ) {
+                               summary_print_by_project( $t_subprojects, 
$p_level + 1, $p_cache );
+                       }
                }
        }
        # --------------------
@@ -630,17 +578,9 @@
                        $c_res_s[$i] = db_prepare_string( $t_res_s[0] );
                }
 
-               # Checking if it's a per project statistic or all projects
-               if ( 0 == $t_project_id ) {
-                       # Only projects to which the user have access
-                       $t_accessible_projects_array = 
user_get_accessible_projects( $t_user_id );
-                       if ( count( $t_accessible_projects_array ) > 0 ) {
-                               $specific_where = ' (project_id='. implode( ' 
OR project_id=', $t_accessible_projects_array ).')';
-                       } else {
-                               $specific_where = '1=1';
-                       }
-               } else {
-                       $specific_where = " project_id='$t_project_id'";
+               $specific_where = helper_project_specific_where( $t_project_id 
);
+               if ( ' 1<>1' == $specific_where ) {
+                       return;
                }
 
                $specific_where .= ' AND handler_id > 0';
@@ -744,16 +684,9 @@
                }
 
                # Checking if it's a per project statistic or all projects
-               if ( 0 == $t_project_id ) {
-                       # Only projects to which the user have access
-                       $t_accessible_projects_array = 
user_get_accessible_projects( $t_user_id );
-                       if ( count( $t_accessible_projects_array ) > 0 ) {
-                               $specific_where = ' (project_id='. implode( ' 
OR project_id=', $t_accessible_projects_array ).')';
-                       } else {
-                               $specific_where = '1=1';
-                       }
-               } else {
-                       $specific_where = " project_id='$t_project_id'";
+               $specific_where = helper_project_specific_where( $t_project_id 
);
+               if ( ' 1<>1' == $specific_where ) {
+                       return;
                }
 
                # Get all of the bugs and split them up into an array
@@ -886,16 +819,9 @@
                }
 
                # Checking if it's a per project statistic or all projects
-               if ( 0 == $t_project_id ) {
-                       # Only projects to which the user have access
-                       $t_accessible_projects_array = 
user_get_accessible_projects( $t_user_id );
-                       if ( count( $t_accessible_projects_array ) > 0 ) {
-                               $specific_where = ' (project_id='. implode( ' 
OR project_id=', $t_accessible_projects_array ).')';
-                       } else {
-                               $specific_where = '1=1';
-                       }
-               } else {
-                       $specific_where = " project_id='$t_project_id'";
+               $specific_where = helper_project_specific_where( $t_project_id 
);
+               if ( ' 1<>1' == $specific_where ) {
+                       return;
                }
 
                # Get all of the bugs and split them up into an array

Index: filter_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/filter_api.php,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -d -r1.83 -r1.84
--- filter_api.php      12 Feb 2005 20:01:11 -0000      1.83
+++ filter_api.php      13 Feb 2005 21:36:37 -0000      1.84
@@ -99,7 +99,12 @@
 
                if ( ALL_PROJECTS == $t_project_id ) {
                        if ( !user_is_administrator( $t_user_id ) ) {
-                               $t_projects = user_get_accessible_projects( 
$t_user_id );
+                               $t_topprojects = $t_projects = 
user_get_accessible_projects( $t_user_id );
+                               foreach ( $t_topprojects as $t_project ) {
+                                       $t_projects = array_merge( $t_projects, 
user_get_all_accessible_subprojects( $t_user_id, $t_project ) );
+                               }
+
+                               $t_projects = array_unique( $t_projects );
 
                                if ( 0 == count( $t_projects ) ) {
                                        return array();  # no accessible 
projects, return an empty array
@@ -113,7 +118,17 @@
                } else {
                        access_ensure_project_level( VIEWER, $t_project_id, 
$t_user_id );
 
-                       array_push( $t_where_clauses, 
"($t_bug_table.project_id='$t_project_id')" );
+                       $t_projects = user_get_all_accessible_subprojects( 
$t_user_id, $t_project_id );
+                       $t_projects[] = $t_project_id;
+
+                       $t_projects = array_unique( $t_projects );
+
+                       if ( 1 == count( $t_projects ) ) {
+                               $t_project = $t_projects[0];
+                               array_push( $t_where_clauses, "( 
$t_bug_table.project_id=$t_project )" );
+                       } else {
+                               array_push( $t_where_clauses, "( 
$t_bug_table.project_id in (". implode( ', ', $t_projects ) . ") )" );
+                       }
                }
 
                # private bug selection

Index: print_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/print_api.php,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -d -r1.113 -r1.114
--- print_api.php       11 Feb 2005 15:38:16 -0000      1.113
+++ print_api.php       13 Feb 2005 21:36:38 -0000      1.114
@@ -287,7 +287,7 @@
        }
        # --------------------
        # List projects that the current user has access to
-       function print_project_option_list( $p_project_id = null, 
$p_include_all_projects = true ) {
+       function print_project_option_list( $p_project_id = null, 
$p_include_all_projects = true, $p_filter_project_id = null, $p_trace = false ) 
{
                $t_project_ids = current_user_get_accessible_projects();
                if ( $p_include_all_projects ) {
                        PRINT '<option value="' . ALL_PROJECTS . '"';
@@ -298,9 +298,32 @@
                $t_project_count = count( $t_project_ids );
                for ($i=0;$i<$t_project_count;$i++) {
                        $t_id = $t_project_ids[$i];
-                       PRINT "<option value=\"$t_id\"";
-                       check_selected( $p_project_id, $t_id );
-                       PRINT '>' . string_display( project_get_field( $t_id, 
'name' ) ) . '</option>' . "\n";
+                       if ( $t_id != $p_filter_project_id ) {
+                               PRINT "<option value=\"$t_id\"";
+                               check_selected( $p_project_id, $t_id );
+                               PRINT '>' . string_display( project_get_field( 
$t_id, 'name' ) ) . '</option>' . "\n";
+                               print_subproject_option_list( $t_id, 
$p_project_id, $p_filter_project_id, $p_trace );
+                       }
+               }
+       }
+       # --------------------
+       # List projects that the current user has access to
+       function print_subproject_option_list( $p_parent_id, $p_project_id = 
null, $p_filter_project_id = null, $p_trace = false, $p_parents = Array() ) {
+               array_push( $p_parents, $p_parent_id );
+               $t_project_ids = current_user_get_accessible_subprojects( 
$p_parent_id );
+               $t_project_count = count( $t_project_ids );
+               for ($i=0;$i<$t_project_count;$i++) {
+                       $t_full_id = $t_id = $t_project_ids[$i];
+                       if ( $t_id != $p_filter_project_id ) {
+                               PRINT "<option value=\"";
+                               if ( $p_trace ) {
+                                 $t_full_id = join( $p_parents, ";") . ';' . 
$t_id;
+                               }
+                               PRINT "$t_full_id\"";
+                               check_selected( $p_project_id, $t_full_id );
+                               PRINT '>' . str_repeat( "&raquo; ", count( 
$p_parents ) ) . string_display( project_get_field( $t_id, 'name' ) ) . 
'</option>' . "\n";
+                               print_subproject_option_list( $t_id, 
$p_project_id, $p_filter_project_id, $p_trace, $p_parents );
+                       }
                }
        }
        # --------------------

Index: current_user_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/current_user_api.php,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- current_user_api.php        12 Feb 2005 20:01:10 -0000      1.26
+++ current_user_api.php        13 Feb 2005 21:36:37 -0000      1.27
@@ -59,12 +59,24 @@
                return user_set_default_project( auth_get_current_user_id(), 
$p_project_id );
        }
        # --------------------
-       # Return the an array of projects to which the currently logged in user
+       # Return an array of projects to which the currently logged in user
        #  has access
        function current_user_get_accessible_projects() {
                return user_get_accessible_projects( auth_get_current_user_id() 
);
        }
        # --------------------
+       # Return an array of subprojects of the specified project to which the
+       # currently logged in user has access
+       function current_user_get_accessible_subprojects( $p_project_id ) {
+               return user_get_accessible_subprojects( 
auth_get_current_user_id(), $p_project_id );
+       }
+       # --------------------
+       # Return an array of subprojects of the specified project to which the
+       # currently logged in user has access, including subprojects of 
subprojects
+       function current_user_get_all_accessible_subprojects( $p_project_id ) {
+               return user_get_all_accessible_subprojects( 
auth_get_current_user_id(), $p_project_id );
+       }
+       # --------------------
        # Return true if the currently logged in user is has a role of 
administrator
        #  or higher, false otherwise
        function current_user_is_administrator() {

Index: helper_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/helper_api.php,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- helper_api.php      12 Feb 2005 20:01:11 -0000      1.53
+++ helper_api.php      13 Feb 2005 21:36:37 -0000      1.54
@@ -156,6 +156,9 @@
 
                if ( null === $t_project_id ) {
                        $t_project_id = current_user_get_pref( 
'default_project' );
+               } else {
+                       $t_project_id = split( ';', $t_project_id );
+                       $t_project_id = $t_project_id[ count( $t_project_id ) - 
1 ];
                }
 
                if ( !project_exists( $t_project_id ) ||
@@ -166,6 +169,34 @@
 
                return (int)$t_project_id;
        }
+
+       # --------------------
+       # Return the current project id as stored in a cookie, in an Array
+       #  If no cookie exists, the user's default project is returned
+       #  If the current project is a subproject, the return value will include
+       #   any parent projects
+       function helper_get_current_project_trace() {
+               $t_cookie_name = config_get( 'project_cookie' );
+
+               $t_project_id = gpc_get_cookie( $t_cookie_name, null );
+
+               if ( null === $t_project_id ) {
+                       $t_bottom     = current_user_get_pref( 
'default_project' );
+                       $t_project_id = Array( $t_bottom );
+               } else {
+                       $t_project_id = split( ';', $t_project_id );
+                       $t_bottom     = $t_project_id[ count( $t_project_id ) - 
1 ];
+               }
+
+               if ( !project_exists( $t_bottom ) ||
+                        ( 0 == project_get_field( $t_bottom, 'enabled' ) ) ||
+                        !access_has_project_level( VIEWER, $t_bottom ) ) {
+                       $t_project_id = Array( ALL_PROJECTS );
+               }
+
+               return $t_project_id;
+       }
+
        # --------------------
        # Set the current project id (stored in a cookie)
        function helper_set_current_project( $p_project_id ) {
@@ -239,4 +270,36 @@
 
                return call_user_func_array( $t_function, $p_args_array );
        }
+
+       # --------------------
+       function helper_project_specific_where( $p_project_id, $p_user_id = 
null ) {
+               if ( null == $p_user_id ) {
+                       $p_user_id = auth_get_current_user_id();
+               }
+
+               if ( ALL_PROJECTS == $p_project_id ) {
+                       $t_topprojects = $t_project_ids = 
user_get_accessible_projects( $p_user_id );
+                       foreach ( $t_topprojects as $t_project ) {
+                               $t_project_ids = array_merge( $t_project_ids, 
user_get_all_accessible_subprojects( $p_user_id, $t_project ) );
+                       }
+
+                       $t_project_ids = array_unique( $t_project_ids );
+               } else {
+                       access_ensure_project_level( config_get( 
'view_changelog_threshold' ), $p_project_id );
+                       $t_project_ids = user_get_all_accessible_subprojects( 
$t_user_id, $p_project_id );
+                       array_unshift( $t_project_ids, $p_project_id );
+               }
+
+               $t_project_ids = array_map( 'db_prepare_int', $t_project_ids );
+
+               if ( 0 == count( $t_project_ids ) ) {
+                       $t_project_filter = ' 1<>1';
+               } elseif ( 1 == count( $t_project_ids ) ) {
+                       $t_project_filter = ' project_id=' . $t_project_ids[0];
+               } else {
+                       $t_project_filter = ' project_id IN (' . join( ',', 
$t_project_ids ) . ')';
+               }
+
+               return $t_project_filter;
+       }
 ?>

--- NEW FILE: project_hierarchy_api.php ---
<?php
        # Mantis - a php based bugtracking system
        # Copyright (C) 2000 - 2002  Kenzaburo Ito - 
kenito-J7RQz27tXwtAfugRpC6u6w@xxxxxxxxxxxxxxxx
        # Copyright (C) 2002 - 2005  Mantis Team   - 
mantisbt-dev-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@xxxxxxxxxxxxxxxx
        # This program is distributed under the terms and conditions of the GPL
        # See the README and LICENSE files for details

        # --------------------------------------------------------
        # $Id: project_hierarchy_api.php,v 1.1 2005/02/13 21:36:38 jlatour Exp $
        # --------------------------------------------------------

        ### Project Hierarchy API ###

        $t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;

        # --------------------
        function project_hierarchy_add( $p_child_id, $p_parent_id ) {
                if ( in_array( $p_parent_id, 
project_hierarchy_get_all_subprojects( $p_child_id ) ) ) {
                        trigger_error( ERROR_PROJECT_RECURSIVE_HIERARCHY, ERROR 
);
                }

                $t_project_hierarchy_table = config_get( 
'mantis_project_hierarchy_table' );

                $c_child_id  = db_prepare_int( $p_child_id  );
                $c_parent_id = db_prepare_int( $p_parent_id );

                $query = "INSERT INTO $t_project_hierarchy_table
                                ( child_id, parent_id )
                                                VALUES
                                                ( $c_child_id, $c_parent_id )";

                db_query($query);
        }

        # --------------------
        function project_hierarchy_remove( $p_child_id, $p_parent_id ) {
                $t_project_hierarchy_table = config_get( 
'mantis_project_hierarchy_table' );

                $c_child_id  = db_prepare_int( $p_child_id  );
                $c_parent_id = db_prepare_int( $p_parent_id );

                $query = "DELETE FROM $t_project_hierarchy_table
                                WHERE child_id = $c_child_id
                                                AND parent_id = $c_parent_id";

                db_query($query);
        }

        # --------------------
        function project_hierarchy_remove_all( $p_project_id ) {
                $t_project_hierarchy_table = config_get( 
'mantis_project_hierarchy_table' );

                $c_project_id = db_prepare_int( $p_project_id );

                $query = "DELETE FROM $t_project_hierarchy_table
                                WHERE child_id = $c_project_id
                                                  OR parent_id = $c_project_id";

                db_query($query);
        }

        # --------------------
        function project_hierarchy_is_toplevel( $p_project_id ) {
                $t_project_hierarchy_table = config_get( 
'mantis_project_hierarchy_table' );

                $c_project_id = db_prepare_int( $p_project_id );

                $query = "SELECT * FROM $t_project_hierarchy_table
                                WHERE child_id = $c_project_id";

                $result = db_query($query);

                return ( db_num_rows( $result ) == 0 );
        }

        # --------------------
        function project_hierarchy_get_subprojects( $p_project_id ) {
                $c_project_id = db_prepare_int( $p_project_id );

                $t_project_table                        = config_get( 
'mantis_project_table' );
                $t_project_hierarchy_table      = config_get( 
'mantis_project_hierarchy_table' );

                $query = "SELECT DISTINCT( p.id )
                                  FROM $t_project_table p
                                  LEFT JOIN $t_project_hierarchy_table ph
                                    ON ph.child_id = p.id
                                  WHERE p.enabled = 1 AND
                                    ph.parent_id = $c_project_id
                                  ORDER BY p.name";

                $result = db_query( $query );
                $row_count = db_num_rows( $result );

                $t_projects = array();

                for ( $i=0 ; $i < $row_count ; $i++ ) {
                        $row = db_fetch_array( $result );

                        array_push( $t_projects, $row['id'] );
                }

                return $t_projects;
        }

        # --------------------
        function project_hierarchy_get_all_subprojects( $p_project_id ) {
                $t_todo        = project_hierarchy_get_subprojects( 
$p_project_id );
                $t_subprojects = Array();

                while ( $t_todo ) {
                        $t_elem = array_shift( $t_todo );
                        if ( !in_array( $t_elem, $t_subprojects ) ) {
                                array_push( $t_subprojects, $t_elem );
                                $t_todo = array_merge( $t_todo, 
project_hierarchy_get_subprojects( $t_elem ) );
                        }
                }

                return $t_subprojects;
        }
?>

Index: user_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/user_api.php,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -d -r1.83 -r1.84
--- user_api.php        13 Feb 2005 12:52:47 -0000      1.83
+++ user_api.php        13 Feb 2005 21:36:38 -0000      1.84
@@ -582,33 +582,49 @@
                }
        }
 
+       $g_user_accessible_projects_cache    = null;
+
        # --------------------
        # retun an array of project IDs to which the user has access
        function user_get_accessible_projects( $p_user_id ) {
+               global $g_user_accessible_projects_cache;
+
+               if ( null != $g_user_accessible_projects_cache
+                    && auth_get_current_user_id() == $p_user_id ) {
+                       return $g_user_accessible_projects_cache;
+               }
+
                $c_user_id = db_prepare_int( $p_user_id );
 
                $t_project_table                        = config_get( 
'mantis_project_table' );
                $t_project_user_list_table      = config_get( 
'mantis_project_user_list_table' );
+               $t_project_hierarchy_table      = config_get( 
'mantis_project_hierarchy_table' );
 
                $t_public       = VS_PUBLIC;
                $t_private      = VS_PRIVATE;
 
                if ( access_has_global_level( config_get( 
'private_project_threshold' ), $p_user_id ) ) {
-                       $query = "SELECT DISTINCT( id ), name
-                                         FROM $t_project_table
-                                         WHERE enabled=1
-                                         ORDER BY name";
+                       $query = "SELECT DISTINCT( p.id )
+                                         FROM $t_project_table p
+                                         LEFT JOIN $t_project_hierarchy_table 
ph
+                                           ON ph.child_id = p.id
+                                         WHERE p.enabled = 1
+                                           AND ph.child_id IS NULL
+                                         ORDER BY p.name";
                } else {
-                       $query = "SELECT DISTINCT( p.id ), p.name
+                       $query = "SELECT DISTINCT( p.id )
                                          FROM $t_project_table p
                                          LEFT JOIN $t_project_user_list_table u
                                            ON p.id=u.project_id
+                                         LEFT JOIN $t_project_hierarchy_table 
ph
+                                           ON ph.child_id = p.id
                                          WHERE ( p.enabled = 1 ) AND
                                                ( p.view_state='$t_public'
                                                    OR 
(p.view_state='$t_private'
                                                            AND
                                                        u.user_id='$c_user_id' )
                                                )
+                                           AND ph.child_id IS NULL
                                          ORDER BY p.name";
                }
 
@@ -623,9 +639,102 @@
                        array_push( $t_projects, $row['id'] );
                }
 
+               if ( auth_get_current_user_id() == $p_user_id ) {
+                       $g_user_accessible_projects_cache = $t_projects;
+               }
+
                return $t_projects;
        }
 
+       $g_user_accessible_subprojects_cache = null;
+
+       # --------------------
+       # retun an array of subproject IDs of a certain project to which the 
user has access
+       function user_get_accessible_subprojects( $p_user_id, $p_project_id ) {
+               global $g_user_accessible_subprojects_cache;
+
+               if ( null != $g_user_accessible_subprojects_cache
+                    && auth_get_current_user_id() == $p_user_id ) {
+                       if ( isset( $g_user_accessible_subprojects_cache[ 
$p_project_id ] ) ) {
+                               return $g_user_accessible_subprojects_cache[ 
$p_project_id ];
+                       } else {
+                               return Array();
+                       }
+               }
+
+               $c_user_id    = db_prepare_int( $p_user_id );
+               $c_project_id = db_prepare_int( $p_project_id );
+
+               $t_project_table                        = config_get( 
'mantis_project_table' );
+               $t_project_user_list_table      = config_get( 
'mantis_project_user_list_table' );
+               $t_project_hierarchy_table      = config_get( 
'mantis_project_hierarchy_table' );
+
+               $t_public       = VS_PUBLIC;
+               $t_private      = VS_PRIVATE;
+
+               if ( user_is_administrator( $p_user_id ) ) {
+                       $query = "SELECT p.id, ph.parent_id
+                                         FROM $t_project_table p
+                                         LEFT JOIN $t_project_hierarchy_table 
ph
+                                           ON ph.child_id = p.id
+                                         WHERE p.enabled = 1
+                                               AND ph.parent_id IS NOT NULL
+                                         ORDER BY p.name";
+               } else {
+                       $query = "SELECT p.id, ph.parent_id
+                                         FROM $t_project_table p
+                                         LEFT JOIN $t_project_user_list_table u
+                                           ON p.id = u.project_id
+                                         LEFT JOIN $t_project_hierarchy_table 
ph
+                                           ON ph.child_id = p.id
+                                         WHERE ( p.enabled = 1 ) AND
+                                               ph.parent_id IS NOT NULL AND
+                                               ( p.view_state='$t_public'
+                                                   OR 
(p.view_state='$t_private'
+                                                           AND
+                                                       u.user_id='$c_user_id' )
+                                               )
+                                         ORDER BY p.name";
+               }
+
+               $result = db_query( $query );
+               $row_count = db_num_rows( $result );
+
+               $t_projects = Array();
+
+               for ( $i=0 ; $i < $row_count ; $i++ ) {
+                       $row = db_fetch_array( $result );
+
+                       if ( !isset( $t_projects[ $row['parent_id'] ] ) ) {
+                               $t_projects[ $row['parent_id'] ] = Array();
+                       }
+
+                       array_push( $t_projects[ $row['parent_id'] ], 
$row['id'] );
+               }
+
+               if ( auth_get_current_user_id() == $p_user_id ) {
+                       $g_user_accessible_subprojects_cache = $t_projects;
+               }
+
+               return $t_projects[ $p_project_id ];
+       }
+
+       # --------------------
+       function user_get_all_accessible_subprojects( $p_user_id, $p_project_id 
) {
+               $t_todo        = user_get_accessible_subprojects( $p_user_id, 
$p_project_id );
+               $t_subprojects = Array();
+
+               while ( $t_todo ) {
+                       $t_elem = array_shift( $t_todo );
+                       if ( !in_array( $t_elem, $t_subprojects ) ) {
+                               array_push( $t_subprojects, $t_elem );
+                               $t_todo = array_merge( $t_todo, 
user_get_accessible_subprojects( $p_user_id, $t_elem ) );
+                       }
+               }
+
+               return $t_subprojects;
+       }
+
        # --------------------
        # return the number of open assigned bugs to a user in a project
        function user_get_assigned_open_bug_count( $p_user_id, 
$p_project_id=ALL_PROJECTS ) {

Index: news_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/news_api.php,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- news_api.php        12 Feb 2005 20:01:18 -0000      1.18
+++ news_api.php        13 Feb 2005 21:36:38 -0000      1.19
@@ -11,6 +11,10 @@
 
        ### News API ###
 
+       $t_core_path = config_get( 'core_path' );
+
+       require_once( $t_core_path.'current_user_api.php' );
+
        # --------------------
        # Add a news item
        function news_create( $p_project_id, $p_poster_id, $p_view_state, 
$p_announcement, $p_headline, $p_body ) {
@@ -143,16 +147,25 @@
        # --------------------
        # get news items (selected project plus sitewide posts)
        function news_get_rows( $p_project_id, $p_sitewide=true ) {
-               $c_project_id = db_prepare_int( $p_project_id );
-
                $t_news_table = config_get( 'mantis_news_table' );
 
+               $t_projects = current_user_get_all_accessible_subprojects( 
$p_project_id );
+               $t_projects[] = $p_project_id;
+
+               if ( $p_sitewide && ALL_PROJECTS != $p_project_id ) {
+                       $t_projects[] = ALL_PROJECTS;
+               }
+
+               $t_projects = array_map( 'db_prepare_int', $t_projects );
+
                $query = "SELECT *, date_posted
-                                 FROM $t_news_table
-                                 WHERE project_id='$c_project_id'";
+                                 FROM $t_news_table";
 
-               if ( $p_sitewide ) {
-                       $query .= ' OR project_id=' . ALL_PROJECTS;
+               if ( 1 == count( $t_projects ) ) {
+                       $c_project_id = $t_projects[0];
+                       $query .= " WHERE project_id='$c_project_id'";
+               } else {
+                       $query .= ' WHERE project_id IN (' . join( $t_projects, 
',' ) . ')';
                }
 
                $query .= " ORDER BY date_posted DESC";
@@ -189,9 +202,16 @@
                        $p_project_id = helper_get_current_project();
                }
 
-               $c_project_id   = db_prepare_int( $p_project_id );
                $c_offset               = db_prepare_int( $p_offset );
 
+               $t_projects = current_user_get_all_accessible_subprojects( 
$p_project_id );
+               $t_projects[] = $p_project_id;
+               if ( ALL_PROJECTS != $p_project_id ) {
+                       $t_projects[] = ALL_PROJECTS;
+               }
+
+               $t_projects = array_map( 'db_prepare_int', $t_projects );
+
                $t_news_table                   = config_get( 
'mantis_news_table' );
                $t_news_view_limit              = config_get( 'news_view_limit' 
);
                $t_news_view_limit_days = config_get( 'news_view_limit_days' );
@@ -200,18 +220,32 @@
                        case 0 :
                                # BY_LIMIT - Select the news posts
                                $query = "SELECT *, date_posted
-                                               FROM $t_news_table
-                                               WHERE 
project_id='$c_project_id' OR project_id=" . ALL_PROJECTS . "
-                                               ORDER BY announcement DESC, id 
DESC";
+                                               FROM $t_news_table";
+
+                               if ( 1 == count( $t_projects ) ) {
+                                       $c_project_id = $t_projects[0];
+                                       $query .= " WHERE 
project_id='$c_project_id'";
+                               } else {
+                                       $query .= ' WHERE project_id IN (' . 
join( $t_projects, ',' ) . ')';
+                               }
+
+                               $query .= ' ORDER BY announcement DESC, id 
DESC';
                                $result = db_query( $query , $t_news_view_limit 
, $c_offset);
                                break;
                        case 1 :
                                # BY_DATE - Select the news posts
                                $query = "SELECT *, date_posted
-                                               FROM $t_news_table
-                                               WHERE ( 
project_id='$c_project_id' OR project_id=" . ALL_PROJECTS . " ) AND
-                                                       " . 
db_helper_compare_days( db_now(), 'date_posted', "< $t_news_view_limit_days") . 
" OR
-                                                       announcement = 1
+                                               FROM $t_news_table";
+
+                               if ( 1 == count( $t_projects ) ) {
+                                       $c_project_id = $t_projects[0];
+                                       $query .= " WHERE 
project_id='$c_project_id'";
+                               } else {
+                                       $query .= ' WHERE project_id IN (' . 
join( $t_projects, ',' ) . ')';
+                               }
+
+                               $query .= " AND " . db_helper_compare_days( 
db_now(), 'date_posted', "< $t_news_view_limit_days") .
+                                                 " OR  announcement = 1
                                                ORDER BY announcement DESC, id 
DESC";
                                $result = db_query( $query, $t_news_view_limit, 
$c_offset );
                                break;

Index: constant_inc.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/constant_inc.php,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- constant_inc.php    12 Feb 2005 20:01:10 -0000      1.37
+++ constant_inc.php    13 Feb 2005 21:36:37 -0000      1.38
@@ -198,6 +198,7 @@
        define( 'ERROR_PROJECT_NOT_FOUND',                              700 );
        define( 'ERROR_PROJECT_NAME_NOT_UNIQUE',                701 );
        define( 'ERROR_PROJECT_NAME_INVALID',                   702 );
+       define( 'ERROR_PROJECT_RECURSIVE_HIERARCHY',    703 );
 
        # ERROR_USER_*
        define( 'ERROR_USER_NAME_NOT_UNIQUE',                   800 );

Index: html_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/html_api.php,v
retrieving revision 1.147
retrieving revision 1.148
diff -u -d -r1.147 -r1.148
--- html_api.php        12 Feb 2005 20:01:11 -0000      1.147
+++ html_api.php        13 Feb 2005 21:36:37 -0000      1.148
@@ -311,7 +311,7 @@
                                } else {
                                        PRINT '<select name="project_id" 
class="small">';
                                }
-                               print_project_option_list( 
helper_get_current_project() );
+                               print_project_option_list( join( ';', 
helper_get_current_project_trace() ), true, null, true );
                                PRINT '</select>';
                                PRINT '<input type="submit" 
class="button-small" value="' . lang_get( 'switch' ) . '" />';
                                PRINT '</form>';

Index: project_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/project_api.php,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- project_api.php     12 Feb 2005 20:01:18 -0000      1.64
+++ project_api.php     13 Feb 2005 21:36:38 -0000      1.65
@@ -255,6 +255,9 @@
                # Delete the project versions
                version_remove_all( $p_project_id );
 
+               # Delete relations to other projects
+               project_hierarchy_remove_all( $p_project_id );
+
                # Delete the project files
                project_delete_all_files( $p_project_id );
 



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click


<Prev in Thread] Current Thread [Next in Thread>