View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0008590 | mantisbt | feature | public | 2007-11-19 04:22 | 2007-11-22 03:05 |
| Reporter | matt_moi | Assigned To | |||
| Priority | normal | Severity | feature | Reproducibility | always |
| Status | new | Resolution | open | ||
| Product Version | 1.0.8 | ||||
| Summary | 0008590: copy the configuration of a project | ||||
| Description | This feature allows to copy the configuration of a project to another. It is placed in the page of managment of a project (manage_proj_edit_page.php) like the sections to copy a categorie or the users from a project to another. In way ti works is :
So it copies only the options defined for the source project. | ||||
| Additional Information | The file with changes are:
(cf attached files - sections with @@@) + | ||||
| Tags | No tags attached. | ||||
| Attached Files | manage_proj_edit_page.php (20,616 bytes)
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2004 Mantis Team - mantisbt-dev@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the README and LICENSE files for details
# --------------------------------------------------------
# $Id: manage_proj_edit_page.php,v 1.92.6.1.4.3 2007/03/06 07:00:33 vboctor Exp $
# --------------------------------------------------------
?>
<?php
require_once( 'core.php' );
$t_core_path = config_get( 'core_path' );
require_once( $t_core_path . 'category_api.php' );
require_once( $t_core_path . 'version_api.php' );
require_once( $t_core_path . 'custom_field_api.php' );
require_once( $t_core_path . 'icon_api.php' );
?>
<?php
$f_project_id = gpc_get_int( 'project_id' );
access_ensure_project_level( config_get( 'manage_project_threshold' ), $f_project_id );
$row = project_get_row( $f_project_id );
?>
<?php html_page_top1() ?>
<?php html_page_top2() ?>
<?php print_manage_menu( 'manage_proj_edit_page.php' ) ?>
<br />
<!-- PROJECT PROPERTIES -->
<div align="center">
<form method="post" action="manage_proj_update.php">
<table class="width75" cellspacing="1">
<!-- Title -->
<tr>
<td class="form-title" colspan="2">
<input type="hidden" name="project_id" value="<?php echo $f_project_id ?>" />
<?php echo lang_get( 'edit_project_title' ) ?>
</td>
</tr>
<!-- Name -->
<tr <?php echo helper_alternate_class() ?>>
<td class="category" width="25%">
<?php echo lang_get( 'project_name' ) ?>
</td>
<td width="75%">
<input type="text" name="name" size="50" maxlength="128" value="<?php echo string_attribute( $row['name'] ) ?>" />
</td>
</tr>
<!-- Status -->
<tr <?php echo helper_alternate_class() ?>>
<td class="category">
<?php echo lang_get( 'status' ) ?>
</td>
<td>
<select name="status">
<?php print_enum_string_option_list( 'project_status', $row['status'] ) ?>
</select>
</td>
</tr>
<!-- Enabled -->
<tr <?php echo helper_alternate_class() ?>>
<td class="category">
<?php echo lang_get( 'enabled' ) ?>
</td>
<td>
<input type="checkbox" name="enabled" <?php check_checked( $row['enabled'], ON ); ?> />
</td>
</tr>
<!-- View Status (public/private) -->
<tr <?php echo helper_alternate_class() ?>>
<td class="category">
<?php echo lang_get( 'view_status' ) ?>
</td>
<td>
<select name="view_state">
<?php print_enum_string_option_list( 'view_state', $row['view_state']) ?>
</select>
</td>
</tr>
<!-- File upload path (if uploading is enabled) -->
<?php if ( file_is_uploading_enabled() ) { ?>
<tr <?php echo helper_alternate_class() ?>>
<td class="category">
<?php echo lang_get( 'upload_file_path' ) ?>
</td>
<td>
<input type="text" name="file_path" size="50" maxlength="250" value="<?php echo string_attribute( $row['file_path'] ) ?>" />
</td>
</tr>
<?php } ?>
<!-- Description -->
<tr <?php echo helper_alternate_class() ?>>
<td class="category">
<?php echo lang_get( 'description' ) ?>
</td>
<td>
<textarea name="description" cols="60" rows="5" wrap="virtual"><?php echo string_textarea( $row['description'] ) ?></textarea>
</td>
</tr>
<!-- Submit Button -->
<tr>
<td> </td>
<td>
<input type="submit" class="button" value="<?php echo lang_get( 'update_project_button' ) ?>" />
</td>
</tr>
</table>
</form>
</div>
<br />
<!-- PROJECT DELETE -->
<?php
# You must have global permissions to delete projects
if ( access_has_global_level ( config_get( 'delete_project_threshold' ) ) ) { ?>
<div class="border-center">
<form method="post" action="manage_proj_delete.php">
<input type="hidden" name="project_id" value="<?php echo $f_project_id ?>" />
<input type="submit" class="button" value="<?php echo lang_get( 'delete_project_button' ) ?>" />
</form>
</div>
<?php } ?>
<br />
<?php
# reset the class counter
helper_alternate_class( 0 );
?>
<!-- SUBPROJECTS -->
<div align="center">
<table class="width75" cellspacing="1">
<!-- Title -->
<tr>
<td class="form-title" colspan="6">
<?php echo lang_get( 'subprojects' ) ?>
<?php
# Check the user's global access level before allowing project creation
if ( access_has_global_level ( config_get( 'create_project_threshold' ) ) ) {
print_button( 'manage_proj_create_page.php?parent_id=' . $f_project_id, lang_get( 'create_new_subproject_link' ) );
}
?>
</td>
</tr>
<!-- Subprojects -->
<?php
$t_subproject_ids = current_user_get_accessible_subprojects( $f_project_id, /* show_disabled */ true );
if ( Array() != $t_subproject_ids ) {
?>
<tr class="row-category">
<td width="20%">
<?php echo lang_get( 'name' ) ?>
</td>
<td width="10%">
<?php echo lang_get( 'status' ) ?>
</td>
<td width="10%">
<?php echo lang_get( 'enabled' ) ?>
</td>
<td width="10%">
<?php echo lang_get( 'view_status' ) ?>
</td>
<td width="30%">
<?php echo lang_get( 'description' ) ?>
</td>
<td width="20%">
<?php echo lang_get( 'actions' ) ?>
</td>
</tr>
<?php
foreach ( $t_subproject_ids as $t_subproject_id ) {
$t_subproject = project_get_row( $t_subproject_id );
?>
<tr <?php echo helper_alternate_class() ?>>
<td>
<a href="manage_proj_edit_page.php?project_id=<?php echo $t_subproject['id'] ?>"><?php echo string_display( $t_subproject['name'] ) ?></a>
</td>
<td>
<?php echo get_enum_element( 'project_status', $t_subproject['status'] ) ?>
</td>
<td>
<?php echo trans_bool( $t_subproject['enabled'] ) ?>
</td>
<td>
<?php echo get_enum_element( 'project_view_state', $t_subproject['view_state'] ) ?>
</td>
<td>
<?php echo string_display_links( $t_subproject['description'] ) ?>
</td>
<td class="center">
<?php
print_button( 'manage_proj_edit_page.php?project_id=' . $t_subproject['id'], lang_get( 'edit_link' ) );
echo ' ';
print_button( 'manage_proj_subproj_delete.php?project_id=' . $f_project_id . '&subproject_id=' . $t_subproject['id'], lang_get( 'unlink_link' ) );
?>
</td>
</tr>
<?php
} # End of foreach loop over subprojects
} # End of hiding subproject listing if there are no subprojects
?>
<!-- Add subproject -->
<tr>
<td class="left" colspan="2">
<form method="post" action="manage_proj_subproj_add.php">
<input type="hidden" name="project_id" value="<?php echo $f_project_id ?>" />
<select name="subproject_id">
<?php
$t_all_subprojects = project_hierarchy_get_subprojects( $f_project_id, /* $p_show_disabled */ true );
$t_all_subprojects[] = $f_project_id;
$t_manage_access = config_get( 'manage_project_threshold' );
$t_projects = project_get_all_rows();
$t_projects = multi_sort( $t_projects, 'name', ASC );
foreach ( $t_projects as $t_project ) {
if ( in_array( $t_project['id'], $t_all_subprojects ) ||
in_array( $f_project_id, project_hierarchy_get_all_subprojects( $t_project['id'] ) ) ||
! access_has_project_level( $t_manage_access, $t_project['id'] ) ) {
continue;
}
?>
<option value="<?php echo $t_project['id'] ?>"><?php echo string_attribute( $t_project['name'] ) ?></option>
<?php
} # End looping over projects
?>
</select>
<input type="submit" value="<?php echo lang_get('add_subproject'); ?>">
</form>
</td>
</tr>
</table>
</div>
<br />
<!-- PROJECT CATEGORIES -->
<div align="center">
<table class="width75" cellspacing="1">
<!-- Title -->
<tr>
<td class="form-title" colspan="3">
<?php echo lang_get( 'categories' ) ?>
</td>
</tr>
<?php
$t_categories = category_get_all_rows( $f_project_id );
if ( count( $t_categories ) > 0 ) {
?>
<tr class="row-category">
<td>
<?php echo lang_get( 'category' ) ?>
</td>
<td>
<?php echo lang_get( 'assign_to' ) ?>
</td>
<td class="center">
<?php echo lang_get( 'actions' ) ?>
</td>
</tr>
<?php
}
foreach ( $t_categories as $t_category ) {
$t_name = $t_category['category'];
if ( NO_USER != $t_category['user_id'] && user_exists( $t_category['user_id'] )) {
$t_user_name = user_get_name( $t_category['user_id'] );
} else {
$t_user_name = '';
}
?>
<!-- Repeated Info Row -->
<tr <?php echo helper_alternate_class() ?>>
<td>
<?php echo string_display( $t_name ) ?>
</td>
<td>
<?php echo $t_user_name ?>
</td>
<td class="center">
<?php
$t_name = urlencode( $t_name );
print_button( 'manage_proj_cat_edit_page.php?project_id=' . $f_project_id . '&category=' . $t_name, lang_get( 'edit_link' ) );
echo ' ';
print_button( 'manage_proj_cat_delete.php?project_id=' . $f_project_id . '&category=' . $t_name, lang_get( 'delete_link' ) );
?>
</td>
</tr>
<?php
} # end for loop
?>
<!-- Add Category Form -->
<tr>
<td class="left" colspan="3">
<form method="post" action="manage_proj_cat_add.php">
<input type="hidden" name="project_id" value="<?php echo $f_project_id ?>" />
<input type="text" name="category" size="32" maxlength="64" />
<input type="submit" class="button" value="<?php echo lang_get( 'add_category_button' ) ?>" />
</form>
</td>
</tr>
<!-- Copy Categories Form -->
<tr>
<td class="left" colspan="3">
<form method="post" action="manage_proj_cat_copy.php">
<input type="hidden" name="project_id" value="<?php echo $f_project_id ?>" />
<select name="other_project_id">
<?php print_project_option_list( null, false, $f_project_id ); ?>
</select>
<input type="submit" name="copy_from" class="button" value="<?php echo lang_get( 'copy_categories_from' ) ?>" />
<input type="submit" name="copy_to" class="button" value="<?php echo lang_get( 'copy_categories_to' ) ?>" />
</form>
</td>
</tr>
</table>
<br />
<?php
# reset the class counter
helper_alternate_class( 0 );
?>
<!-- PROJECT VERSIONS -->
<table class="width75" cellspacing="1">
<!-- Title -->
<tr>
<td class="form-title" colspan="3">
<?php echo lang_get( 'versions' ) ?>
</td>
</tr>
<?php
$t_versions = version_get_all_rows( $f_project_id );
if ( count( $t_versions ) > 0 ) {
?>
<tr class="row-category">
<td>
<?php echo lang_get( 'version' ) ?>
</td>
<td class="center">
<?php echo lang_get( 'timestamp' ) ?>
</td>
<td class="center">
<?php echo lang_get( 'actions' ) ?>
</td>
</tr>
<?php
}
foreach ( $t_versions as $t_version ) {
$t_name = $t_version['version'];
$t_date_order = $t_version['date_order'];
$t_date_formatted = string_format_complete_date( $t_version['date_order'] );
?>
<!-- Repeated Info Rows -->
<tr <?php echo helper_alternate_class() ?>>
<td>
<?php echo string_display( $t_name ) ?>
</td>
<td class="center">
<?php echo $t_date_formatted ?>
</td>
<td class="center">
<?php
$t_version_id = version_get_id( $t_name, $f_project_id );
print_button( 'manage_proj_ver_edit_page.php?version_id=' . $t_version_id, lang_get( 'edit_link' ) );
echo ' ';
print_button( 'manage_proj_ver_delete.php?version_id=' . $t_version_id, lang_get( 'delete_link' ) );
?>
</td>
</tr>
<?php
} # end for loop
?>
<!-- Version Add Form -->
<tr>
<td class="left" colspan="3">
<form method="post" action="manage_proj_ver_add.php">
<input type="hidden" name="project_id" value="<?php echo $f_project_id ?>" />
<input type="text" name="version" size="32" maxlength="64" />
<input type="submit" name="add_version" class="button" value="<?php echo lang_get( 'add_version_button' ) ?>" />
<input type="submit" name="add_and_edit_version" class="button" value="<?php echo lang_get( 'add_and_edit_version_button' ) ?>" />
</form>
</td>
</tr>
</table>
</div>
<?php
# reset the class counter
helper_alternate_class( 0 );
?>
<!-- PROJECT CUSTOM FIELD -->
<?php
# You need either global permissions or project-specific permissions to link
# custom fields
if ( access_has_project_level( config_get( 'custom_field_link_threshold' ), $f_project_id ) &&
( count( custom_field_get_ids() ) > 0 ) ) {
?>
<br />
<div align="center">
<table class="width75" cellspacing="1">
<tr>
<td class="form-title" colspan="3">
<?php echo lang_get( 'custom_fields_setup' ) ?>
</td>
</tr>
<?php
$t_custom_fields = custom_field_get_linked_ids( $f_project_id );
if ( count( $t_custom_fields ) > 0 ) {
?>
<tr class="row-category">
<td width="50%">
<?php echo lang_get( 'custom_field' ) ?>
</td>
<td width="25%">
<?php echo lang_get( 'custom_field_sequence' ) ?>
</td>
<td class="center" width="25%">
<?php echo lang_get( 'actions' ); ?>
</td>
</tr>
<?php
}
foreach( $t_custom_fields as $t_field_id ) {
$t_desc = custom_field_get_definition( $t_field_id );
?>
<tr <?php echo helper_alternate_class() ?>>
<td>
<?php echo string_display( $t_desc['name'] ) ?>
</td>
<td>
<form method="post" action="manage_proj_custom_field_update.php">
<input type="hidden" name="project_id" value="<?php echo $f_project_id ?>" />
<input type="hidden" name="field_id" value="<?php echo $t_field_id ?>" />
<input type="text" name="sequence" value="<?php echo custom_field_get_sequence( $t_field_id, $f_project_id ) ?>" size="2" />
<input type="submit" class="button-small" value="<?php echo lang_get( 'update' ) ?>" />
</form>
</td>
<td class="center">
<?php
# You need global permissions to edit custom field defs
print_button( "manage_proj_custom_field_remove.php?field_id=$t_field_id&project_id=$f_project_id", lang_get( 'remove_link' ) );
?>
</td>
</tr>
<?php
} # end for loop
?>
<tr>
<td class="left" colspan="3">
<form method="post" action="manage_proj_custom_field_add_existing.php">
<input type="hidden" name="project_id" value="<?php echo $f_project_id ?>" />
<select name="field_id">
<?php
$t_custom_fields = custom_field_get_ids();
foreach( $t_custom_fields as $t_field_id )
{
if( !custom_field_is_linked( $t_field_id, $f_project_id ) ) {
$t_desc = custom_field_get_definition( $t_field_id );
echo "<option value=\"$t_field_id\">" . string_attribute( $t_desc['name'] ) . '</option>' ;
}
}
?>
</select>
<input type="submit" class="button" value="<?php echo lang_get( 'add_existing_custom_field' ) ?>" />
</form>
</td>
</tr>
</table>
</div>
<?php
}
?>
<!-- CONFIGURATION MANAGEMENT (COPY) -->
<?php
# @@@ Matthieu Dhallenne
# Copy the options of configuration from a project to another
# We want to allow people with global permissions and people with high enough
# permissions on the project we are editing
if ( access_has_project_level( config_get( 'project_user_threshold' ), $f_project_id ) ) {
?>
<div>
<table class="width75" cellspacing="1">
<!-- Copy Configuration Form -->
<form method="post" action="manage_proj_config_copy.php">
<input type="hidden" name="project_id" value="<?php echo $f_project_id ?>" />
<tr><td></td></tr>
<tr>
<td class="form-title" colspan="5">
<?php echo lang_get( 'copy_config_title' ) ?>
</td>
</tr>
<tr>
<td class="left" colspan="3">
<select name="other_project_id">
<?php print_project_option_list( null, false, $f_project_id ); ?>
</select>
<input type="submit" name="copy_from" class="button" value="<?php echo lang_get( 'copy_config_from' ) ?>" />
</td>
</tr>
</form>
<table>
</div>
<br>
<?php
}
?>
<!-- PROJECT VIEW STATUS -->
<br />
<div align="center">
<table class="width75" cellspacing="1">
<tr>
<td class="center">
<?php
if ( VS_PUBLIC == project_get_field( $f_project_id, 'view_state' ) ) {
echo lang_get( 'public_project_msg' );
} else {
echo lang_get( 'private_project_msg' );
}
?>
</td>
</tr>
</table>
</div>
<!-- USER MANAGEMENT (ADD) -->
<?php
# We want to allow people with global permissions and people with high enough
# permissions on the project we are editing
if ( access_has_project_level( config_get( 'project_user_threshold' ), $f_project_id ) ) {
?>
<br />
<div align="center">
<table class="width75" cellspacing="1">
<form method="post" action="manage_proj_user_add.php">
<input type="hidden" name="project_id" value="<?php echo $f_project_id ?>" />
<tr>
<td class="form-title" colspan="5">
<?php echo lang_get( 'add_user_title' ) ?>
</td>
</tr>
<tr class="row-1" valign="top">
<td class="category">
<?php echo lang_get( 'username' ) ?>
</td>
<td class="category">
<?php echo lang_get( 'access_level' ) ?>
</td>
<td class="category"> </td>
</tr>
<tr class="row-1" valign="top">
<td>
<select name="user_id[]" multiple="multiple" size="10">
<?php print_project_user_list_option_list( $f_project_id ) ?>
</select>
</td>
<td>
<select name="access_level">
<?php # only access levels that are less than or equal current user access level for current project ?>
<?php print_project_access_levels_option_list( config_get( 'default_new_account_access_level' ), $f_project_id ) ?>
</select>
</td>
<td>
<input type="submit" class="button" value="<?php echo lang_get( 'add_user_button' ) ?>" />
</td>
</tr>
</form>
<!-- Copy Users Form -->
<form method="post" action="manage_proj_user_copy.php">
<tr>
<td class="left" colspan="3">
<input type="hidden" name="project_id" value="<?php echo $f_project_id ?>" />
<select name="other_project_id">
<?php print_project_option_list( null, false, $f_project_id ); ?>
</select>
<input type="submit" name="copy_from" class="button" value="<?php echo lang_get( 'copy_users_from' ) ?>" />
<input type="submit" name="copy_to" class="button" value="<?php echo lang_get( 'copy_users_to' ) ?>" />
</td>
</tr>
</form>
</table>
</div>
<?php
}
?>
<!-- LIST OF USERS -->
<br />
<div align="center">
<table class="width75" cellspacing="1">
<tr>
<td class="form-title" colspan="4">
<?php echo lang_get( 'manage_accounts_title' ) ?>
</td>
</tr>
<tr class="row-category">
<td>
<?php echo lang_get( 'username' ) ?>
</td>
<td>
<?php echo lang_get( 'email' ) ?>
</td>
<td>
<?php echo lang_get( 'access_level' ) ?>
</td>
<td class="center">
<?php echo lang_get( 'actions' ) ?>
</td>
</tr>
<?php
$t_users = project_get_all_user_rows( $f_project_id );
$t_display = array();
$t_sort = array();
foreach ( $t_users as $t_user ) {
$t_user_name = string_attribute( $t_user['username'] );
$t_sort_name = strtolower( $t_user_name );
if ( ( isset( $t_user['realname'] ) ) && ( $t_user['realname'] > "" ) && ( ON == config_get( 'show_realname' ) ) ){
$t_user_name = string_attribute( $t_user['realname'] ) . " (" . $t_user_name . ")";
if ( ON == config_get( 'sort_by_last_name') ) {
$t_sort_name_bits = split( ' ', strtolower( $t_user_name ), 2 );
$t_sort_name = $t_sort_name_bits[1] . ', ' . $t_sort_name_bits[1];
} else {
$t_sort_name = strtolower( $t_user_name );
}
}
$t_display[] = $t_user_name;
$t_sort[] = $t_sort_name;
}
array_multisort( $t_sort, SORT_ASC, SORT_STRING, $t_users, $t_display );
# reset the class counter
helper_alternate_class( 0 );
for ($i = 0; $i < count( $t_sort ); $i++ ) {
$t_user = $t_users[$i];
?>
<tr <?php echo helper_alternate_class() ?>>
<td>
<?php echo $t_display[$i] ?>
</td>
<td>
<?php
$t_email = user_get_email( $t_user['id'] );
print_email_link( $t_email, $t_email );
?>
</td>
<td>
<?php echo get_enum_element( 'access_levels', $t_user['access_level'] ) ?>
</td>
<td class="center">
<?php
# You need global or project-specific permissions to remove users
# from this project
if ( access_has_project_level( config_get( 'project_user_threshold' ), $f_project_id ) ) {
if ( project_includes_user( $f_project_id, $t_user['id'] ) ) {
print_button( 'manage_proj_user_remove.php?project_id=' . $f_project_id . '&user_id=' . $t_user['id'], lang_get( 'remove_link' ) );
}
}
?>
</td>
</tr>
<?php
} # end for
?>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="center">
<?php
# You need global or project-specific permissions to remove users
# from this project
if ( access_has_project_level( config_get( 'project_user_threshold' ), $f_project_id ) ) {
print_button( 'manage_proj_user_remove.php?project_id=' . $f_project_id, lang_get( 'remove_all_link' ) );
}
?>
</td>
</tr>
</table>
</div>
<?php html_page_bottom1( __FILE__ ) ?>
config_api.php (15,088 bytes)
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2004 Mantis Team - mantisbt-dev@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the README and LICENSE files for details
# --------------------------------------------------------
# $Id: config_api.php,v 1.35.6.1 2006/01/16 19:58:42 thraxisp Exp $
# --------------------------------------------------------
# cache for config variables
$g_cache_config = array();
$g_cache_config_access = array();
$g_cache_filled = false;
# cache environment to speed up lookups
$g_cache_db_table_exists = false;
### Configuration API ###
# ------------------
# Retrieves the value of a config option
# This function will return one of (in order of preference):
# 1. value from cache
# 2. value from database
# looks for specified config_id + current user + current project.
# if not found, config_id + current user + all_project
# if not found, config_id + default user + current project
# if not found, config_id + default user + all_project.
# 3.use GLOBAL[config_id]
function config_get( $p_option, $p_default = null, $p_user = null, $p_project = null ) {
global $g_cache_config, $g_cache_config_access, $g_cache_db_table_exists, $g_cache_filled;
# @@ debug @@ echo "lu o=$p_option ";
# bypass table lookup for certain options
$t_match_pattern = '/' . implode( '|', config_get_global( 'global_settings' ) ) . '/';
$t_bypass_lookup = ( 0 < preg_match( $t_match_pattern, $p_option ) );
# @@ debug @@ if ($t_bypass_lookup) { echo "bp=$p_option match=$t_match_pattern <br />"; }
if ( ! $t_bypass_lookup ) {
$t_config_table = config_get_global( 'mantis_config_table' );
# @@ debug @@ if ( ! db_is_connected() ) { echo "no db "; }
# @@ debug @@ echo "lu table=" . ( db_table_exists( $t_config_table ) ? "yes " : "no " );
if ( ! $g_cache_db_table_exists ) {
$g_cache_db_table_exists = ( TRUE === db_is_connected() ) &&
db_table_exists( $t_config_table );
}
if ( $g_cache_db_table_exists ) {
# @@ debug @@ echo " lu db $p_option ";
# @@ debug @@ error_print_stack_trace();
# prepare the user's list
$t_users = array();
if ( null === $p_user ) {
$t_users[] = auth_is_user_authenticated() ? auth_get_current_user_id() : ALL_USERS;
} else {
$t_users[] = $p_user;
}
if ( ! in_array( ALL_USERS, $t_users ) ) {
$t_users[] = ALL_USERS;
}
# prepare the projects list
$t_projects = array();
if ( ( null === $p_project ) ) {
$t_projects[] = auth_is_user_authenticated() ? helper_get_current_project() : ALL_PROJECTS;
} else {
$t_projects[] = $p_project;
}
if ( ! in_array( ALL_PROJECTS, $t_projects ) ) {
$t_projects[] = ALL_PROJECTS;
}
# @@ debug @@ echo 'pr= '; var_dump($t_projects);
# @@ debug @@ echo 'u= '; var_dump($t_users);
if ( ! $g_cache_filled ) {
$query = "SELECT config_id, user_id, project_id, type, value, access_reqd FROM $t_config_table";
$result = db_query( $query );
while ( false <> ( $row = db_fetch_array( $result ) ) ) {
$t_config = $row['config_id'];
$t_user = $row['user_id'];
$t_project = $row['project_id'];
$g_cache_config[$t_config][$t_user][$t_project] = $row['type'] . ';' . $row['value'];
$g_cache_config_access[$t_config][$t_user][$t_project] = $row['access_reqd'];
}
$g_cache_filled = true;
}
if( isset( $g_cache_config[$p_option] ) ) {
$t_found = false;
reset( $t_users );
while ( ( list( , $t_user ) = each( $t_users ) ) && ! $t_found ) {
reset( $t_projects );
while ( ( list( , $t_project ) = each( $t_projects ) ) && ! $t_found ) {
if ( isset( $g_cache_config[$p_option][$t_user][$t_project] ) ) {
$t_value = $g_cache_config[$p_option][$t_user][$t_project];
$t_found = true;
# @@ debug @@ echo "clu found u=$t_user, p=$t_project, v=$t_value ";
}
}
}
if ( $t_found ) {
list( $t_type, $t_raw_value ) = explode( ';', $t_value, 2 );
switch ( $t_type ) {
case CONFIG_TYPE_INT:
$t_value = (int) $t_raw_value;
break;
case CONFIG_TYPE_COMPLEX:
$t_value = unserialize( $t_raw_value );
break;
case CONFIG_TYPE_STRING:
default:
$t_value = config_eval( $t_raw_value );
}
return $t_value;
}
}
}
}
return config_get_global( $p_option, $p_default );
}
# @@@ Matthieu Dhallenne
# Retrieves the option list of a config option
# This function will return a result of a query which is the list of config_id for a specific project
function config_get_options( $p_project ) {
$t_config_table = config_get_global( 'mantis_config_table' );
if ( TRUE === db_is_connected() && db_table_exists( $t_config_table )) {
$query = "SELECT DISTINCT config_id FROM $t_config_table WHERE project_id = $p_project";
$result = db_query( $query );
return $result;
}
else
{
error_parameters( $t_config_table );
}
}
# ----------------------
# force config variable from a global to avoid recursion
function config_get_global( $p_option, $p_default = null ) {
if ( isset( $GLOBALS['g_' . $p_option] ) ) {
$t_value = config_eval( $GLOBALS['g_' . $p_option] );
if ( $t_value !== $GLOBALS['g_' . $p_option] ) {
$GLOBALS['g_' . $p_option] = $t_value;
}
return $t_value;
} else {
# unless we were allowing for the option not to exist by passing
# a default, trigger a WARNING
if ( null === $p_default ) {
error_parameters( $p_option );
trigger_error( ERROR_CONFIG_OPT_NOT_FOUND, WARNING );
}
return $p_default;
}
}
# ------------------
# Retrieves the access level needed to change a config value
function config_get_access( $p_option, $p_user = null, $p_project = null ) {
global $g_cache_config, $g_cache_config_access, $g_cache_filled;
# @@ debug @@ echo "lu o=$p_option ";
if ( ! $g_cache_filled ) {
$t = config_get( $p_option, -1, $p_user, $p_project );
}
# prepare the user's list
$t_users = array( );
if ( ( null === $p_user ) && ( auth_is_user_authenticated() ) ) {
$t_users[] = auth_get_current_user_id();
} else if ( ! in_array( $p_user, $t_users ) ) {
$t_users[] = $p_user;
}
$t_users[] = ALL_USERS;
# prepare the projects list
$t_projects = array( );
if ( ( null === $p_project ) && ( auth_is_user_authenticated() ) ) {
$t_selected_project = helper_get_current_project();
if ( ALL_PROJECTS <> $t_selected_project ) {
$t_projects[] = $t_selected_project;
}
} else if ( ! in_array( $p_project, $t_projects ) ) {
$t_projects[] = $p_project;
}
# @@ debug @@ echo 'pr= '; var_dump($t_projects);
# @@ debug @@ echo 'u= '; var_dump($t_users);
$t_found = false;
if ( isset( $g_cache_config[$p_option] ) ) {
reset( $t_users );
while ( ( list( , $t_user ) = each( $t_users ) ) && ! $t_found ) {
reset( $t_projects );
while ( ( list( , $t_project ) = each( $t_projects ) ) && ! $t_found ) {
if ( isset( $g_cache_config[$p_option][$t_user][$t_project] ) ) {
$t_access = $g_cache_config_access[$p_option][$t_user][$t_project];
$t_found = true;
# @@ debug @@ echo "clua found u=$t_user, p=$t_project, a=$t_access ";
}
}
}
}
return $t_found ? $t_access : ADMINISTRATOR;
}
# ------------------
# Returns true if the specified config option exists (ie. a
# value or default can be found), false otherwise
function config_is_set( $p_option, $p_user = null, $p_project = null ) {
global $g_cache_config, $g_cache_filled;
if ( ! $g_cache_filled ) {
$t = config_get( $p_option, -1, $p_user, $p_project );
}
# prepare the user's list
$t_users = array( ALL_USERS );
if ( ( null === $p_user ) && ( auth_is_user_authenticated() ) ) {
$t_users[] = auth_get_current_user_id();
} else if ( ! in_array( $p_user, $t_users ) ) {
$t_users[] = $p_user;
}
$t_users[] = ALL_USERS;
# prepare the projects list
$t_projects = array( ALL_PROJECTS );
if ( ( null === $p_project ) && ( auth_is_user_authenticated() ) ) {
$t_selected_project = helper_get_current_project();
if ( ALL_PROJECTS <> $t_selected_project ) {
$t_projects[] = $t_selected_project;
}
} else if ( ! in_array( $p_project, $t_projects ) ) {
$t_projects[] = $p_project;
}
$t_found = false;
reset( $t_users );
while ( ( list( , $t_user ) = each( $t_users ) ) && ! $t_found ) {
reset( $t_projects );
while ( ( list( , $t_project ) = each( $t_projects ) ) && ! $t_found ) {
if ( isset( $g_cache_config[$p_option][$t_user][$t_project] ) ) {
$t_found = true;
}
}
}
if ( $t_found ) {
return true;
}
return isset( $GLOBALS['g_' . $p_option] ) ;
}
# ------------------
# Sets the value of the given config option to the given value
# If the config option does not exist, an ERROR is triggered
function config_set( $p_option, $p_value, $p_user = NO_USER, $p_project = ALL_PROJECTS, $p_access = ADMINISTRATOR ) {
if ( is_array( $p_value ) || is_object( $p_value ) ) {
$t_type = CONFIG_TYPE_COMPLEX;
$c_value = db_prepare_string( serialize( $p_value ) );
} else if ( is_int( $p_value ) || is_numeric( $p_value ) ) {
$t_type = CONFIG_TYPE_INT;
$c_value = db_prepare_int( $p_value );
} else {
$t_type = CONFIG_TYPE_STRING;
$c_value = db_prepare_string( $p_value );
}
$c_option = db_prepare_string( $p_option );
$c_user = db_prepare_int( $p_user );
$c_project = db_prepare_int( $p_project );
$c_access = db_prepare_int( $p_access );
$t_config_table = config_get_global( 'mantis_config_table' );
$query = "SELECT COUNT(*) from $t_config_table
WHERE config_id = '$c_option' AND
project_id = $c_project AND
user_id = $c_user";
$result = db_query( $query );
if ( 0 < db_result( $result ) ) {
$t_set_query = "UPDATE $t_config_table
SET value='$c_value', type=$t_type, access_reqd=$c_access
WHERE config_id = '$c_option' AND
project_id = $c_project AND
user_id = $c_user";
} else {
$t_set_query = "INSERT INTO $t_config_table
( value, type, access_reqd, config_id, project_id, user_id )
VALUES
('$c_value', $t_type, $c_access, '$c_option', $c_project, $c_user )";
}
$result = db_query( $t_set_query );
config_set_cache( $p_option, $p_value, $p_user, $p_project, $p_access );
return true;
}
# ------------------
# Sets the value of the given config option to the given value
# If the config option does not exist, an ERROR is triggered
function config_set_cache( $p_option, $p_value, $p_user = NO_USER, $p_project = ALL_PROJECTS, $p_access = ADMINISTRATOR ) {
global $g_cache_config, $g_cache_config_access;
$g_cache_config[$p_option][$p_user][$p_project] = $p_value;
$g_cache_config_access[$p_option][$p_user][$p_project] = $p_access;
return true;
}
# ------------------
# delete the config entry
function config_delete( $p_option, $p_user = ALL_USERS, $p_project = ALL_PROJECTS ) {
global $g_cache_config, $g_cache_config_access;
# bypass table lookup for certain options
$t_match_pattern = '/' . implode( '|', config_get_global( 'global_settings' ) ) . '/';
$t_bypass_lookup = ( 0 < preg_match( $t_match_pattern, $p_option ) );
# @@ debug @@ if ($t_bypass_lookup) { echo "bp=$p_option match=$t_match_pattern <br />"; }
# @@ debug @@ if ( ! db_is_connected() ) { echo "no db"; }
if ( ( ! $t_bypass_lookup ) && ( TRUE === db_is_connected() )
&& ( db_table_exists( config_get_global( 'mantis_config_table' ) ) ) ) {
$t_config_table = config_get_global( 'mantis_config_table' );
# @@ debug @@ echo "lu table=" . ( db_table_exists( $t_config_table ) ? "yes" : "no" );
# @@ debug @@ error_print_stack_trace();
$c_option = db_prepare_string( $p_option );
$c_user = db_prepare_int( $p_user );
$c_project = db_prepare_int( $p_project );
$query = "DELETE FROM $t_config_table
WHERE config_id = '$c_option' AND
project_id=$c_project AND
user_id=$c_user";
$result = @db_query( $query);
}
config_flush_cache( $p_option, $p_user, $p_project );
}
# ------------------
# delete the config entry
function config_delete_project( $p_project = ALL_PROJECTS ) {
global $g_cache_config, $g_cache_config_access;
$t_config_table = config_get_global( 'mantis_config_table' );
$c_project = db_prepare_int( $p_project );
$query = "DELETE FROM $t_config_table
WHERE project_id=$c_project";
$result = @db_query( $query);
# flush cache here in case some of the deleted configs are in use.
config_flush_cache();
}
# ------------------
# delete the config entry from the cache
# @@@ to be used sparingly
function config_flush_cache( $p_option='', $p_user = ALL_USERS, $p_project = ALL_PROJECTS ) {
global $g_cache_config, $g_cache_config_access, $g_cache_filled;
if ( '' !== $p_option ) {
unset( $GLOBALS['g_cache_config'][$p_option][$p_user][$p_project] );
unset( $GLOBALS['g_cache_config_access'][$p_option][$p_user][$p_project] );
} else {
unset( $GLOBALS['g_cache_config'] );
unset( $GLOBALS['g_cache_config_access'] );
$g_cache_filled = false;
}
}
# ------------------
# Checks if an obsolete configuration variable is still in use. If so, an error
# will be generated and the script will exit. This is called from admin_check.php.
function config_obsolete( $p_var, $p_replace ) {
# @@@ we could trigger a WARNING here, once we have errors that can
# have extra data plugged into them (we need to give the old and
# new config option names in the warning text)
if ( config_is_set( $p_var ) ) {
PRINT '<p><b>Warning:</b> The configuration option <tt>$g_' . $p_var . '</tt> is now obsolete';
if ( is_array( $p_replace ) ) {
PRINT ', please see the following options: <ul>';
foreach ( $p_replace as $t_option ) {
PRINT '<li>$g_' . $t_option . '</li>';
}
PRINT '</ul>';
} else if ( !is_blank( $p_replace ) ) {
PRINT ', please use <tt>$g_' . $p_replace . '</tt> instead.';
}
PRINT '</p>';
}
}
# ------------------
# check for recursion in defining config variables
# If there is a %text% in the returned value, re-evaluate the "text" part and replace
# the string
function config_eval( $p_value ) {
$t_value = $p_value;
if ( is_string( $t_value ) && !is_numeric( $t_value ) ) {
if ( 0 < preg_match_all( '/%(.*)%/U', $t_value, $t_matches ) ) {
$t_count = count( $t_matches[0] );
for ($i=0; $i<$t_count; $i++) {
# $t_matches[0][$i] is the matched string including the delimiters
# $t_matches[1][$i] is the target parameter string
$t_repl = config_get( $t_matches[1][$i] );
$t_value = str_replace( $t_matches[0][$i], $t_repl, $t_value );
}
}
}
return $t_value;
}
?>
project_api.php (23,077 bytes)
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2004 Mantis Team - mantisbt-dev@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the README and LICENSE files for details
# --------------------------------------------------------
# $Id: project_api.php,v 1.75 2005/06/28 19:22:53 thraxisp Exp $
# --------------------------------------------------------
$t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
require_once( $t_core_dir . 'category_api.php' );
require_once( $t_core_dir . 'version_api.php' );
require_once( $t_core_dir . 'bug_api.php' );
require_once( $t_core_dir . 'file_api.php' );
require_once( $t_core_dir . 'news_api.php' );
### Project API ###
#===================================
# Caching
#===================================
#########################################
# SECURITY NOTE: cache globals are initialized here to prevent them
# being spoofed if register_globals is turned on
$g_cache_project = array();
$g_cache_project_missing = array();
$g_cache_project_all = false;
# --------------------
# Cache a project row if necessary and return the cached copy
# If the second parameter is true (default), trigger an error
# if the project can't be found. If the second parameter is
# false, return false if the project can't be found.
function project_cache_row( $p_project_id, $p_trigger_errors=true ) {
global $g_cache_project, $g_cache_project_missing;
$c_project_id = db_prepare_int( $p_project_id );
if ( isset ( $g_cache_project[(int)$p_project_id] ) ) {
return $g_cache_project[(int)$p_project_id];
} else if ( isset( $g_cache_project_missing[(int)$p_project_id] ) ) {
return false;
}
$t_project_table = config_get( 'mantis_project_table' );
$query = "SELECT *
FROM $t_project_table
WHERE id='$c_project_id'";
$result = db_query( $query );
if ( 0 == db_num_rows( $result ) ) {
$g_cache_project_missing[(int)$p_project_id] = true;
if ( $p_trigger_errors ) {
trigger_error( ERROR_PROJECT_NOT_FOUND, ERROR );
} else {
return false;
}
}
$row = db_fetch_array( $result );
$g_cache_project[(int)$p_project_id] = $row;
return $row;
}
# --------------------
# Cache all project rows and return an array of them
function project_cache_all() {
global $g_cache_project, $g_cache_project_all;
if ( !$g_cache_project_all ) {
$t_project_table = config_get( 'mantis_project_table' );
$query = "SELECT *
FROM $t_project_table";
$result = db_query( $query );
$count = db_num_rows( $result );
for ( $i = 0 ; $i < $count ; $i++ ) {
$row = db_fetch_array( $result );
$g_cache_project[(int)$row['id']] = $row;
}
$g_cache_project_all = true;
}
return $g_cache_project;
}
# --------------------
# Clear the project cache (or just the given id if specified)
function project_clear_cache( $p_project_id = null ) {
global $g_cache_project, $g_cache_project_missing, $g_cache_project_all;
if ( null === $p_project_id ) {
$g_cache_project = array();
$g_cache_project_missing = array();
$g_cache_project_all = false;
} else {
unset( $g_cache_project[(int)$p_project_id] );
unset( $g_cache_project_missing[(int)$p_project_id] );
$g_cache_project_all = false;
}
return true;
}
#===================================
# Boolean queries and ensures
#===================================
# --------------------
# check to see if project exists by id
# return true if it does, false otherwise
function project_exists( $p_project_id ) {
# we're making use of the caching function here. If we
# succeed in caching the project then it exists and is
# now cached for use by later function calls. If we can't
# cache it we return false.
if ( false == project_cache_row( $p_project_id, false ) ) {
return false;
} else {
return true;
}
}
# --------------------
# check to see if project exists by id
# if it doesn't exist then error
# otherwise let execution continue undisturbed
function project_ensure_exists( $p_project_id ) {
if ( !project_exists( $p_project_id ) ) {
trigger_error( ERROR_PROJECT_NOT_FOUND, ERROR );
}
}
# --------------------
# check to see if project exists by name
function project_is_name_unique( $p_name ) {
$c_name = db_prepare_string( $p_name );
$t_project_table = config_get( 'mantis_project_table' );
$query ="SELECT COUNT(*)
FROM $t_project_table
WHERE name='$c_name'";
$result = db_query( $query );
if ( 0 == db_result( $result ) ) {
return true;
} else {
return false;
}
}
# --------------------
# check to see if project exists by id
# if it doesn't exist then error
# otherwise let execution continue undisturbed
function project_ensure_name_unique( $p_name ) {
if ( !project_is_name_unique( $p_name ) ) {
trigger_error( ERROR_PROJECT_NAME_NOT_UNIQUE, ERROR );
}
}
# --------------------
# check to see if the user/project combo already exists
# returns true is duplicate is found, otherwise false
function project_includes_user( $p_project_id, $p_user_id ) {
$t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
$c_project_id = db_prepare_int( $p_project_id );
$c_user_id = db_prepare_int( $p_user_id );
$query = "SELECT COUNT(*)
FROM $t_project_user_list_table
WHERE project_id='$c_project_id' AND
user_id='$c_user_id'";
$result = db_query( $query );
if ( 0 == db_result( $result ) ) {
return false;
} else {
return true;
}
}
#===================================
# Creation / Deletion / Updating
#===================================
# --------------------
# Create a new project
function project_create( $p_name, $p_description, $p_status, $p_view_state = VS_PUBLIC, $p_file_path = '', $p_enabled = true ) {
# Make sure file path has trailing slash
$p_file_path = terminate_directory_path( $p_file_path );
$c_name = db_prepare_string( $p_name );
$c_description = db_prepare_string( $p_description );
$c_status = db_prepare_int( $p_status );
$c_view_state = db_prepare_int( $p_view_state );
$c_file_path = db_prepare_string( $p_file_path );
$c_enabled = db_prepare_bool( $p_enabled );
if ( is_blank( $p_name ) ) {
trigger_error( ERROR_PROJECT_NAME_INVALID, ERROR );
}
project_ensure_name_unique( $p_name );
if ( !is_blank( $p_file_path ) ) {
file_ensure_valid_upload_path( $p_file_path );
}
$t_project_table = config_get( 'mantis_project_table' );
$query = "INSERT INTO $t_project_table
( name, status, enabled, view_state, file_path, description )
VALUES
( '$c_name', '$c_status', '$c_enabled', '$c_view_state', '$c_file_path', '$c_description' )";
db_query( $query );
# return the id of the new project
return db_insert_id($t_project_table);
}
# --------------------
# Delete a project
function project_delete( $p_project_id ) {
$t_email_notifications = config_get( 'enable_email_notification' );
# temporarily disable all notifications
config_set_cache( 'enable_email_notification', OFF );
$c_project_id = db_prepare_int( $p_project_id );
$t_project_table = config_get( 'mantis_project_table' );
# Delete the bugs
bug_delete_all( $p_project_id );
# Delete associations with custom field definitions.
custom_field_unlink_all( $p_project_id );
# Delete the project categories
category_remove_all( $p_project_id );
# 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 );
# Delete the records assigning users to this project
project_remove_all_users( $p_project_id );
# Delete all news entries associated with the project being deleted
news_delete_all( $p_project_id );
# Delete project specific configurations
config_delete_project( $p_project_id );
# Delete any user prefs that are project specific
user_pref_delete_project( $p_project_id );
# Delete the project entry
$query = "DELETE FROM $t_project_table
WHERE id='$c_project_id'";
db_query( $query );
config_set_cache( 'enable_email_notification', $t_email_notifications );
project_clear_cache( $p_project_id );
# db_query() errors on failure so:
return true;
}
# --------------------
# Update a project
function project_update( $p_project_id, $p_name, $p_description, $p_status, $p_view_state, $p_file_path, $p_enabled ) {
# Make sure file path has trailing slash
$p_file_path = terminate_directory_path( $p_file_path );
$c_project_id = db_prepare_int( $p_project_id );
$c_name = db_prepare_string( $p_name );
$c_description = db_prepare_string( $p_description );
$c_status = db_prepare_int( $p_status );
$c_view_state = db_prepare_int( $p_view_state );
$c_file_path = db_prepare_string( $p_file_path );
$c_enabled = db_prepare_bool( $p_enabled );
if ( is_blank( $p_name ) ) {
trigger_error( ERROR_PROJECT_NAME_INVALID, ERROR );
}
$t_old_name = project_get_field( $p_project_id, 'name' );
if ( strcasecmp( $p_name, $t_old_name ) != 0 ) {
project_ensure_name_unique( $p_name );
}
if ( !is_blank( $p_file_path ) ) {
file_ensure_valid_upload_path( $p_file_path );
}
$t_project_table = config_get( 'mantis_project_table' );
$query = "UPDATE $t_project_table
SET name='$c_name',
status='$c_status',
enabled='$c_enabled',
view_state='$c_view_state',
file_path='$c_file_path',
description='$c_description'
WHERE id='$c_project_id'";
db_query( $query );
project_clear_cache( $p_project_id );
# db_query errors on failure so:
return true;
}
#===================================
# Data Access
#===================================
# --------------------
# Get the id of the project with the specified name
function project_get_id_by_name( $p_project_name ) {
$c_project_name = db_prepare_string( $p_project_name );
$t_project_table = config_get( 'mantis_project_table' );
$query = "SELECT id FROM $t_project_table WHERE name = '$c_project_name'";
$t_result = db_query( $query, 1 );
if ( db_num_rows( $t_result ) == 0 ) {
return 0;
} else {
return db_result( $t_result );
}
}
# --------------------
# Return the row describing the given project
function project_get_row( $p_project_id ) {
return project_cache_row( $p_project_id );
}
# --------------------
# Return all rows describing all projects
function project_get_all_rows() {
return project_cache_all();
}
# --------------------
# Return the specified field of the specified project
function project_get_field( $p_project_id, $p_field_name ) {
$row = project_get_row( $p_project_id );
if ( isset( $row[$p_field_name] ) ) {
return $row[$p_field_name];
} else {
error_parameters( $p_field_name );
trigger_error( ERROR_DB_FIELD_NOT_FOUND, WARNING );
return '';
}
}
# --------------------
# Return the name of the project
# Handles ALL_PROJECTS by returning the internationalized string for All Projects
function project_get_name( $p_project_id ) {
if ( ALL_PROJECTS == $p_project_id ) {
return lang_get( 'all_projects' );
} else {
return project_get_field( $p_project_id, 'name' );
}
}
# --------------------
# Return the user's local (overridden) access level on the project or false
# if the user is not listed on the project
function project_get_local_user_access_level( $p_project_id, $p_user_id ) {
$c_project_id = db_prepare_int( $p_project_id );
$c_user_id = db_prepare_int( $p_user_id );
if ( ALL_PROJECTS == $c_project_id ) {
return false;
}
$t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
$query = "SELECT access_level
FROM $t_project_user_list_table
WHERE user_id='$c_user_id' AND project_id='$c_project_id'";
$result = db_query( $query );
if ( db_num_rows( $result ) > 0 ) {
return db_result( $result );
} else {
return false;
}
}
# --------------------
# return the descriptor holding all the info from the project user list
# for the specified project
function project_get_local_user_rows( $p_project_id ) {
$c_project_id = db_prepare_int( $p_project_id );
$t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
$query = "SELECT *
FROM $t_project_user_list_table
WHERE project_id='$c_project_id'";
$result = db_query( $query );
$t_user_rows = array();
$t_row_count = db_num_rows( $result );
for ( $i=0 ; $i < $t_row_count ; $i++ ) {
array_push( $t_user_rows, db_fetch_array( $result ) );
}
return $t_user_rows;
}
# --------------------
# Return an array of info about users who have access to the the given project
# For each user we have 'id', 'username', and 'access_level' (overall access level)
# If the second parameter is given, return only users with an access level
# higher than the given value.
# if the first parameter is given as 'ALL_PROJECTS', return the global access level (without
# any reference to the specific project
function project_get_all_user_rows( $p_project_id = ALL_PROJECTS, $p_access_level = ANYBODY ) {
$c_project_id = db_prepare_int( $p_project_id );
# Optimization when access_level is NOBODY
if ( NOBODY == $p_access_level ) {
return array();
}
$t_user_table = config_get( 'mantis_user_table' );
$t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
$t_project_table = config_get( 'mantis_project_table' );
$t_global_access_level = $p_access_level;
if ( $c_project_id != ALL_PROJECTS ) {
# looking for specific project
if ( VS_PRIVATE == project_get_field( $p_project_id, 'view_state' ) ) {
# @@@ (thraxisp) this is probably more complex than it needs to be
# When a new project is created, those who meet 'private_project_threshold' are added
# automatically, but don't have an entry in project_user_list_table.
# if they did, you would not have to add global levels.
$t_private_project_threshold = config_get( 'private_project_threshold' );
if ( is_array( $t_private_project_threshold ) ) {
if ( is_array( $p_access_level ) ) {
# both private threshold and request are arrays, use intersection
$t_global_access_level = array_intersect( $p_access_level, $t_private_project_threshold );
} else {
# private threshold is an array, but request is a number, use values in threshold higher than request
$t_global_access_level = array();
foreach ( $t_private_project_threshold as $t_threshold ) {
if ( $p_access_level <= $t_threshold ) {
$t_global_access_level[] = $t_threshold;
}
}
}
} else {
if ( is_array( $p_access_level ) ) {
# private threshold is a number, but request is an array, use values in request higher than threshold
$t_global_access_level = array();
foreach ( $p_access_level as $t_threshold ) {
if ( $t_threshold >= $t_private_project_threshold ) {
$t_global_access_level[] = $t_threshold;
}
}
} else {
# both private threshold and request are numbers, use maximum
$t_global_access_level = max( $p_access_level, $t_private_project_threshold );
}
}
}
}
$t_project_clause = ( $c_project_id != ALL_PROJECTS ) ? ' AND p.id = ' . $c_project_id : '';
if ( is_array( $t_global_access_level ) ) {
if ( 0 == count( $t_global_access_level ) ) {
$t_global_access_clause = ">= " . NOBODY . " ";
} else if ( 1 == count( $t_global_access_level ) ) {
$t_global_access_clause = "= " . array_shift( $t_global_access_level ) . " ";
} else {
$t_global_access_clause = "IN (" . implode( ',', $t_global_access_level ) . ")";
}
} else {
$t_global_access_clause = ">= $t_global_access_level ";
}
$t_on = ON;
$t_adm = ADMINISTRATOR;
$t_users = array();
$query = "SELECT id, username, realname, access_level
FROM $t_user_table
WHERE enabled = $t_on
AND access_level $t_global_access_clause";
$result = db_query( $query );
$t_row_count = db_num_rows( $result );
for ( $i=0 ; $i < $t_row_count ; $i++ ) {
$row = db_fetch_array( $result );
$t_users[$row['id']] = $row;
}
if( $c_project_id != ALL_PROJECTS ) {
# Get the project overrides
$query = "SELECT u.id, u.username, u.realname, l.access_level
FROM $t_project_user_list_table l, $t_user_table u
WHERE l.user_id = u.id
AND u.enabled = $t_on
AND l.project_id = $c_project_id";
$result = db_query( $query );
$t_row_count = db_num_rows( $result );
for ( $i=0 ; $i < $t_row_count ; $i++ ) {
$row = db_fetch_array( $result );
if ( is_array( $p_access_level ) ) {
$t_keep = in_array( $row['access_level'], $p_access_level );
} else {
$t_keep = $row['access_level'] >= $p_access_level;
}
if ( $t_keep ) {
$t_users[$row['id']] = $row;
} else {
# If user's overridden level is lower than required, so remove
# them from the list if they were previously there
unset( $t_users[$row['id']] );
}
}
}
return array_values( $t_users );
}
#===================================
# Data Modification
#===================================
# --------------------
# add user with the specified access level to a project
function project_add_user( $p_project_id, $p_user_id, $p_access_level ) {
$t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
$c_project_id = db_prepare_int( $p_project_id );
$c_user_id = db_prepare_int( $p_user_id );
$c_access_level = db_prepare_int( $p_access_level );
if ( DEFAULT_ACCESS_LEVEL == $p_access_level ) {
# Default access level for this user
$c_access_level = db_prepare_int( user_get_access_level ( $p_user_id ) );
}
$query = "INSERT
INTO $t_project_user_list_table
( project_id, user_id, access_level )
VALUES
( '$c_project_id', '$c_user_id', '$c_access_level')";
db_query( $query );
# db_query errors on failure so:
return true;
}
# --------------------
# update entry
# must make sure entry exists beforehand
function project_update_user_access( $p_project_id, $p_user_id, $p_access_level ) {
$t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
$c_project_id = db_prepare_int( $p_project_id );
$c_user_id = db_prepare_int( $p_user_id );
$c_access_level = db_prepare_int( $p_access_level );
$query = "UPDATE $t_project_user_list_table
SET access_level='$c_access_level'
WHERE project_id='$c_project_id' AND
user_id='$c_user_id'";
db_query( $query );
# db_query errors on failure so:
return true;
}
# --------------------
# update or add the entry as appropriate
# This function involves one more db query than project_update_user_acces()
# or project_add_user()
function project_set_user_access( $p_project_id, $p_user_id, $p_access_level ) {
if ( project_includes_user( $p_project_id, $p_user_id ) ) {
return project_update_user_access( $p_project_id, $p_user_id, $p_access_level );
} else {
return project_add_user( $p_project_id, $p_user_id, $p_access_level );
}
}
# --------------------
# remove user from project
function project_remove_user( $p_project_id, $p_user_id ) {
$t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
$c_project_id = db_prepare_int( $p_project_id );
$c_user_id = db_prepare_int( $p_user_id );
$query = "DELETE FROM $t_project_user_list_table
WHERE project_id='$c_project_id' AND
user_id='$c_user_id'";
db_query( $query );
# db_query errors on failure so:
return true;
}
# --------------------
# delete all users from the project user list for a given project
# this is useful when deleting or closing a project
function project_remove_all_users( $p_project_id ) {
$t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
$c_project_id = db_prepare_int( $p_project_id );
$query = "DELETE FROM $t_project_user_list_table
WHERE project_id='$c_project_id'";
db_query( $query );
# db_query errors on failure so:
return true;
}
# --------------------
# Copy all users and their permissions from the source project to the
# destination project
function project_copy_users( $p_destination_id, $p_source_id ) {
# Copy all users from current project over to another project
$rows = project_get_local_user_rows( $p_source_id );
for ( $i = 0 ; $i < sizeof( $rows ) ; $i++ ) {
extract( $rows[$i], EXTR_PREFIX_ALL, 'v' );
# if there is no duplicate then add a new entry
# otherwise just update the access level for the existing entry
if ( project_includes_user( $p_destination_id, $v_user_id ) ) {
project_update_user_access( $p_destination_id, $v_user_id, $v_access_level );
} else {
project_add_user( $p_destination_id, $v_user_id, $v_access_level );
}
}
}
# @@@ Matthieu Dhallenne
# Copy the configuration from the source project to the
# destination project
function project_copy_config( $p_destination_id, $p_source_id ) {
$t_options = config_get_options( $p_source_id );
config_delete_project ($p_destination_id);
while ( false <> ( $row = db_fetch_array( $t_options ) ) ) {
$t_config = $row['config_id'];
#@@@ debug @@@ echo("<table><tr><td>".$t_config."</td></tr></table>");
project_copy_option( $t_config, $p_destination_id, $p_source_id);
}
}
# @@@ Matthieu Dhallenne
# Copy an option from the source project to the
# destination project
function project_copy_option( $p_option, $p_destination_id, $p_source_id ) {
$t_workflow = config_get( $p_option, null, null, $p_source_id );
# access required is only ADMINISTRATOR after the copy
config_set($p_option, $t_workflow, NO_USER, $p_destination_id, ADMINISTRATOR);
}
# --------------------
# Delete all files associated with a project
function project_delete_all_files( $p_project_id ) {
file_delete_project_files( $p_project_id );
}
#===================================
# Other
#===================================
# --------------------
# Pads the project id with the appropriate number of zeros.
function project_format_id( $p_project_id ) {
$t_padding = config_get( 'display_project_padding' );
return( str_pad( $p_project_id, $t_padding, '0', STR_PAD_LEFT ) );
}
# --------------------
# Return true if the file name identifier is unique, false otherwise
function project_file_is_name_unique( $p_name ) {
$t_file_table = config_get( 'mantis_project_file_table' );
$c_name = db_prepare_string( $p_name );
$query = "SELECT COUNT(*)
FROM $t_file_table
WHERE filename='$c_name'";
$result = db_query( $query );
$t_count = db_result( $result );
if ( $t_count > 0 ) {
return false;
} else {
return true;
}
}
?>
| ||||
| related to | 0005490 | new | Copy Project |