Dependency Graph
View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0012724 | mantisbt | sub-projects | public | 2011-01-26 14:15 | 2019-03-23 14:12 |
| Reporter | kivio.wanderley | Assigned To | cproensa | ||
| Priority | normal | Severity | minor | Reproducibility | always |
| Status | closed | Resolution | duplicate | ||
| Product Version | 1.2.3 | ||||
| Summary | 0012724: The sub-subprojects are listed out of the tree on the top select list. Hard to see. | ||||
| Description | When i have a project GRAND with a subproject FATHER and this one with a subproject SON. If im on the SON and GRAND projects but not on FATHER they appear out of the projects tree on the top list. | ||||
| Steps To Reproduce | Set a chain of projects like this:
Assing a user on P01 and P03. So on the project list on top depending on the name of these they dont appear like above. They are listed with alphabetical sort making hard to see that their on the same chain. | ||||
| Additional Information | Founded on "print_pai.php" on function "print_project_option_list" it gets projects that can be or parent or child. And if it gets a GRAND to print and youre on the SON and not on the FATHER this function calls the "print_subproject_option_list" but this checks on FATHER and so that youre not on this it is cut out from the tree. | ||||
| Tags | No tags attached. | ||||
| Attached Files | print_api.php (61,159 bytes)
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2005 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: print_api.php,v 1.3 2009/09/29 12:39:22 d333859 Exp $
# --------------------------------------------------------
$t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
require_once( $t_core_dir . 'current_user_api.php' );
require_once( $t_core_dir . 'string_api.php' );
require_once( $t_core_dir . 'prepare_api.php' );
require_once( $t_core_dir . 'profile_api.php' );
### Print API ###
# this file handles printing functions
# --------------------
# Print the headers to cause the page to redirect to $p_url
# If $p_die is true (default), terminate the execution of the script
# immediately
# If we have handled any errors on this page and the 'stop_on_errors' config
# option is turned on, return false and don't redirect.
function print_header_redirect( $p_url, $p_die = true, $p_sanitize = false ) {
$t_use_iis = config_get( 'use_iis');
if ( ON == config_get( 'stop_on_errors' ) && error_handled() ) {
return false;
}
# validate the url as part of this site before continuing
if ( $p_sanitize ) {
$t_url = string_sanitize_url( $p_url );
} else {
$t_url = $p_url;
}
# don't send more headers if they have already been sent (guideweb)
if ( ! headers_sent() ) {
header( 'Content-Type: text/html; charset=' . lang_get( 'charset' ) );
if ( ON == $t_use_iis ) {
header( "Refresh: 0;url=$t_url" );
} else {
header( "Location: $t_url" );
}
} else {
trigger_error( ERROR_PAGE_REDIRECTION, ERROR );
return false;
}
if ( $p_die ) {
die; # additional output can cause problems so let's just stop output here
}
return true;
}
# --------------------
# Print a redirect header to view a bug
function print_header_redirect_view( $p_bug_id ) {
print_header_redirect( string_get_bug_view_url( $p_bug_id ) );
}
# --------------------
# Get a view URL for the bug id based on the user's preference and
# call print_successful_redirect() with that URL
function print_successful_redirect_to_bug( $p_bug_id ) {
$t_url = string_get_bug_view_url( $p_bug_id, auth_get_current_user_id() );
print_successful_redirect( $t_url );
}
# --------------------
# If the show query count is ON, print success and redirect after the
# configured system wait time.
# If the show query count is OFF, redirect right away.
function print_successful_redirect( $p_redirect_to ) {
if ( ON == config_get( 'show_queries_count' ) ) {
html_meta_redirect( $p_redirect_to );
html_page_top1();
html_page_top2();
PRINT '<br /><div class="center">';
PRINT lang_get( 'operation_successful' ) . '<br />';
print_bracket_link( $p_redirect_to, lang_get( 'proceed' ) );
PRINT '</div>';
html_page_bottom1();
} else {
print_header_redirect( $p_redirect_to );
}
}
# --------------------
# Print a redirect header to update a bug
function print_header_redirect_update( $p_bug_id ) {
print_header_redirect( string_get_bug_update_url( $p_bug_id ) );
}
# --------------------
# Print a redirect header to update a bug
function print_header_redirect_report() {
print_header_redirect( string_get_bug_report_url() );
}
# --------------------
# prints the name of the user given the id. also makes it an email link.
function print_user( $p_user_id ) {
echo prepare_user_name( $p_user_id );
}
# --------------------
# same as print_user() but fills in the subject with the bug summary
function print_user_with_subject( $p_user_id, $p_bug_id ) {
$c_user_id = db_prepare_int( $p_user_id );
if ( NO_USER == $p_user_id ) {
return;
}
$t_username = user_get_name( $p_user_id );
if ( user_exists( $p_user_id ) && user_get_field( $p_user_id, 'enabled' ) ) {
$t_email = user_get_field( $p_user_id, 'email' );
print_email_link_with_subject( $t_email, $t_username, $p_bug_id );
} else {
echo '<font STYLE="text-decoration: line-through">';
echo $t_username;
echo '</font>';
}
}
# --------------------
function print_duplicate_id( $p_duplicate_id ) {
if ( $p_duplicate_id != 0 ) {
PRINT string_get_bug_view_link( $p_duplicate_id );
}
}
# --------------------
# print out an email editing input
function print_email_input( $p_field_name, $p_email ) {
$t_limit_email_domain = config_get( 'limit_email_domain' );
if ( $t_limit_email_domain ) {
# remove the domain part
$p_email = eregi_replace( "@$t_limit_email_domain$", '', $p_email );
PRINT '<input type="text" name="'.$p_field_name.'" size="20" maxlength="64" value="'.$p_email.'" />@'.$t_limit_email_domain;
} else {
PRINT '<input type="text" name="'.$p_field_name.'" size="32" maxlength="64" value="'.$p_email.'" />';
}
}
# --------------------
# print out an email editing input
function print_captcha_input( $p_field_name ) {
echo '<input type="text" name="'.$p_field_name.'" size="5" maxlength="5" value="" />';
}
###########################################################################
# Option List Printing API
###########################################################################
# --------------------
# sorts the array by the first element of the array element
# @@@ might not be used
function cmp( $p_var1, $p_var2 ) {
if ( $p_var1[0][0] == $p_var2[0][0] ) {
return 0;
}
if ( $p_var1[0][0] < $p_var2[0][0] ) {
return -1;
} else {
return 1;
}
}
# --------------------
# This populates an option list with the appropriate users by access level
#
# @@@ from print_reporter_option_list
function print_user_option_list( $p_user_id, $p_project_id = null, $p_access = ANYBODY ) {
$t_users = array();
if ( null === $p_project_id ) {
$p_project_id = helper_get_current_project();
}
$t_users = project_get_all_user_rows( $p_project_id, $p_access ); # handles ALL_PROJECTS case
$t_display = array();
$t_sort = array();
$t_show_realname = ( ON == config_get( 'show_realname' ) );
$t_sort_by_last_name = ( ON == config_get( 'sort_by_last_name' ) );
foreach ( $t_users as $t_user ) {
$t_user_name = string_attribute( $t_user['username'] );
$t_sort_name = strtolower( $t_user_name );
if ( $t_show_realname && ( $t_user['realname'] <> "" ) ){
$t_user_name = string_attribute( $t_user['realname'] );
if ( $t_sort_by_last_name ) {
$t_sort_name_bits = split( ' ', strtolower( $t_user_name ), 2 );
$t_sort_name = ( isset( $t_sort_name_bits[1] ) ? $t_sort_name_bits[1] . ', ' : '' ) . $t_sort_name_bits[0];
} 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 );
for ($i = 0; $i < count( $t_sort ); $i++ ) {
$t_row = $t_users[$i];
PRINT '<option value="' . $t_row['id'] . '" ';
check_selected( $p_user_id, $t_row['id'] );
PRINT '>' . $t_display[$i] . '</option>';
}
}
# --------------------
# ugly functions need to be refactored
# This populates the reporter option list with the appropriate users
#
# @@@ This function really ought to print out all the users, I think.
# I just encountered a situation where a project used to be public and
# was made private, so now I can't filter on any of the reporters who
# actually reported the bugs at the time. Maybe we could get all user
# who are listed as the reporter in any bug? It would probably be a
# faster query actually.
function print_reporter_option_list( $p_user_id, $p_project_id = null ) {
print_user_option_list( $p_user_id, $p_project_id, config_get( 'report_bug_threshold' ) );
}
# --------------------
function print_duplicate_id_option_list() {
$query = "SELECT id
FROM " . config_get ( 'mantis_bug_table' ) . "
ORDER BY id ASC";
$result = db_query( $query );
$duplicate_id_count = db_num_rows( $result );
PRINT '<option value="0"></option>';
for ($i=0;$i<$duplicate_id_count;$i++) {
$row = db_fetch_array( $result );
$t_duplicate_id = $row['id'];
PRINT "<option value=\"$t_duplicate_id\">".$t_duplicate_id."</option>";
}
}
# --------------------
# Get current headlines and id prefix with v_
function print_news_item_option_list() {
$t_mantis_news_table = config_get( 'mantis_news_table' );
$t_project_id = helper_get_current_project();
if ( access_has_project_level( ADMINISTRATOR ) ) {
$query = "SELECT id, headline, announcement, view_state
FROM $t_mantis_news_table
ORDER BY date_posted DESC";
} else {
$query = "SELECT id, headline, announcement, view_state
FROM $t_mantis_news_table
WHERE project_id='$t_project_id'
ORDER BY date_posted DESC";
}
$result = db_query( $query );
$news_count = db_num_rows( $result );
for ($i=0;$i<$news_count;$i++) {
$row = db_fetch_array( $result );
extract( $row, EXTR_PREFIX_ALL, 'v' );
$v_headline = string_display( $v_headline );
$t_notes = array();
$t_note_string = '';
if ( 1 == $v_announcement ) {
array_push( $t_notes, lang_get( 'announcement' ) );
}
if ( VS_PRIVATE == $v_view_state ) {
array_push( $t_notes, lang_get( 'private' ) );
}
if ( sizeof( $t_notes ) > 0 ) {
$t_note_string = ' ['.implode( ' ', $t_notes ).']';
}
PRINT "<option value=\"$v_id\">$v_headline$t_note_string</option>";
}
}
#---------------
# Constructs the string for one news entry given the row retrieved from the news table.
function print_news_entry( $p_headline, $p_body, $p_poster_id, $p_view_state, $p_announcement, $p_date_posted ) {
$t_headline = string_display_links( $p_headline );
$t_body = string_display_links( $p_body );
$t_date_posted = date( config_get( 'normal_date_format' ), $p_date_posted );
if ( VS_PRIVATE == $p_view_state ) {
$t_news_css = 'news-heading-private';
} else {
$t_news_css = 'news-heading-public';
}
$output = '<div align="center">';
$output .= '<table class="width75" cellspacing="0">';
$output .= '<tr>';
$output .= "<td class=\"$t_news_css\">";
$output .= "<span class=\"bold\">$t_headline</span> - ";
$output .= "<span class=\"italic-small\">$t_date_posted</span> - ";
echo $output;
# @@@ eventually we should replace print's with methods to construct the
# strings.
print_user( $p_poster_id );
$output = '';
$output .= ' <span class="small">';
if ( 1 == $p_announcement ) {
$output .= '[' . lang_get( 'announcement' ) . ']';
}
if ( VS_PRIVATE == $p_view_state ) {
$output .= '[' . lang_get( 'private' ) . ']';
}
$output .= '</span>';
$output .= '</td>';
$output .= '</tr>';
$output .= '<tr>';
$output .= "<td class=\"news-body\">$t_body</td>";
$output .= '</tr>';
$output .= '</table>';
$output .= '</div>';
echo $output;
}
# --------------------
# print a news item given a row in the news table.
function print_news_entry_from_row( $p_news_row ) {
extract( $p_news_row, EXTR_PREFIX_ALL, 'v' );
print_news_entry( $v_headline, $v_body, $v_poster_id, $v_view_state, $v_announcement, $v_date_posted );
}
# --------------------
# print a news item
function print_news_string_by_news_id( $p_news_id ) {
$row = news_get_row( $p_news_id );
# only show VS_PRIVATE posts to configured threshold and above
if ( ( VS_PRIVATE == $row['view_state'] ) &&
!access_has_project_level( config_get( 'private_news_threshold' ) ) ) {
continue;
}
print_news_entry_from_row( $row );
}
# --------------------
# Used for update pages
function print_field_option_list( $p_list, $p_item='' ) {
$t_mantis_bug_table = config_get( 'mantis_bug_table' );
$t_category_string = get_enum_string( $t_mantis_bug_table, $p_list );
$t_arr = explode_enum_string( $t_category_string );
$entry_count = count( $t_arr );
for ($i=0;$i<$entry_count;$i++) {
$t_s = str_replace( '\'', '', $t_arr[$i] );
PRINT "<option value=\"$t_s\"";
check_selected( $p_item, $t_s );
PRINT ">$t_s</option>";
} # end for
}
# --------------------
/* (Kivio) 29/09/2009
DESCRICAO: Ao visualizar o caso, em "Atribuir a:" listar apenas os usu�rios participantes do projeto. Retirando a adi��o padr�o dos administradores.
OBS.: Copia da fun��o "print_user_option_list" com uma restri��o "if" no "for"
*/
function print_assign_to_option_list( $p_user_id='', $p_project_id = null, $p_threshold = null ) {
if ( null === $p_threshold ) {
$p_threshold = config_get( 'handle_bug_threshold' );
}
$t_users = array();
if ( null === $p_project_id ) {
$p_project_id = helper_get_current_project();
}
$t_users = project_get_all_user_rows( $p_project_id, $p_threshold ); # handles ALL_PROJECTS case
$t_display = array();
$t_sort = array();
$t_show_realname = ( ON == config_get( 'show_realname' ) );
$t_sort_by_last_name = ( ON == config_get( 'sort_by_last_name' ) );
foreach ( $t_users as $t_user ) {
$t_user_name = string_attribute( $t_user['username'] );
$t_sort_name = strtolower( $t_user_name );
if ( $t_show_realname && ( $t_user['realname'] <> "" ) ){
$t_user_name = string_attribute( $t_user['realname'] );
if ( $t_sort_by_last_name ) {
$t_sort_name_bits = split( ' ', strtolower( $t_user_name ), 2 );
$t_sort_name = ( isset( $t_sort_name_bits[1] ) ? $t_sort_name_bits[1] . ', ' : '' ) . $t_sort_name_bits[0];
} 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 );
for ($i = 0; $i < count( $t_sort ); $i++ ) {
$t_row = $t_users[$i];
if ( project_includes_user( $p_project_id, $t_row['id'] )
|| (user_get_access_level($t_row['id'], $p_project_id)) == ADMINISTRATOR ) { #(kivio 25.11.2010)
PRINT '<option value="' . $t_row['id'] . '" ';
check_selected( $p_user_id, $t_row['id'] );
PRINT '>' . $t_display[$i] . '</option>';
}
}
}
/* Fim da customizacao 29/09/2009
*/
/* kivio.wanderley) 29/12/2010
DESCRICAO: Usuario cadastrado em projeto com varios pais. Projeto e mostrado na arvore
*/
function get_projects($p_project_id, $p_filter = null, $p_arr = array()) {
$t_project_hierarchy_table = config_get( 'mantis_project_hierarchy_table' );
$query = "SELECT child_id, parent_id
FROM $t_project_hierarchy_table";
$result = db_query( $query );
$row_count = db_num_rows( $result );
$parent_arr = $child_arr = array();
/* Get all hierarchy IDs */
for ( $i=0 ; $i < $row_count ; $i++ ) {
$row = db_fetch_array( $result );
$parent_id = $row['parent_id'];
$child_id = $row['child_id'];
if(!is_array($p_arr[$parent_id])) $p_arr[$parent_id] = array();
array_push($p_arr[$parent_id],$child_id);
$p_solo_projects[] = $parent_id;
$p_solo_projects[] = $child_id;
}
/* Print projects without children */
$p_solo_projects = array_unique($p_solo_projects);
$p_solo_projects = array_diff($p_filter, $p_solo_projects );
foreach ($p_solo_projects as $v) {
PRINT "<option value=\"$v\"";
check_selected( $p_project_id, $v );
PRINT '>' . string_display( project_get_field( $v, 'name' ) ) . '</option>' . "\n";
}
/* Arrange array */
foreach ($p_arr as $par_id=>$childs_array) {
$p_arr = arrange_project_tree_array( $p_arr, $par_id, $childs_array );
}
/* Print the projects tree */
$ar = explode(",", print_project_tree($p_project_id, $p_arr, $p_filter));
foreach ($ar as $v) {
PRINT $v;
}
}
function print_project_tree($p_project_id, $p_arr, $p_filter, $p_sep = 0) {
foreach ($p_arr as $par_id=>$child_id) {
if(is_array($child_id)) { //If this child is parent
/* Get string with children */
$result = print_project_tree($p_project_id, $child_id, $p_filter, $p_sep+1);
/* Check ID selected */
if( check_selected2($p_project_id, $par_id) ) $selected = "selected";
else $selected = '';
/* If this parent got children */
if($result != '') {
if(!in_array($par_id, $p_filter)) $disabled = "disabled";
else $disabled = '';
$print .= "<option $selected $disabled value=\"$par_id\"" . '>' . str_repeat( "» ", $p_sep) . string_display( project_get_field( $par_id, 'name' ) ) . '</option>' .",". "\n";
$print .= $result;
} else {
if(in_array($par_id, $p_filter)) {
$print .= "<option $selected value=\"$par_id\"" . '>' . str_repeat( "» ", $p_sep) . string_display( project_get_field( $par_id, 'name' ) ) . '</option>' .",". "\n";
}
}
} else {
if(in_array($child_id, $p_filter)) {
/* Check ID selected */
if( check_selected2($p_project_id, $child_id) ) $selected = "selected";
else $selected = '';
$print .= "<option $selected value=\"$child_id\"" . '>' . str_repeat( "» ", $p_sep) . string_display( project_get_field( $child_id, 'name' ) ) . '</option>' .",". "\n";
}
}
}
return $print;
}
function arrange_project_tree_array( $p_arr, $par_id, $childs_array, $bool = false) {
foreach ($p_arr as $par_key=>$array) { //Verifica se o pai existe como filho de outro pai
foreach ($array as $key=>$chi_id) {
if(is_array($chi_id)) { //If child id a parent search this
/* Get the child array with its parents and children */
$result = arrange_project_tree_array( $p_arr[$par_key], $par_id, $childs_array, true );
/* Set the resulted array */
$p_arr[$par_key] = $result;
/* Unset the array now placed like child */
unset($p_arr[$par_id]);
} else {
if($par_id == $chi_id) { //If the searching ID is equal to this child ID
$p_arr[$par_key][$chi_id] = $childs_array; //Set the array
unset($p_arr[$par_key][$key]); //Unset the array now placed like child
if($bool == true) { //Used if the p_arr is a child array
return $p_arr;
} else {
unset($p_arr[$par_id]);
}
}
}
}
}
return $p_arr;
}
//--
# --------------------
# List projects that the current user has access to
function print_project_option_list( $p_project_id = null, $p_include_all_projects = true, $p_filter_project_id = null, $p_trace = false ) {
project_cache_all();
$t_project_ids = current_user_get_accessible_projects();
if ( $p_include_all_projects ) {
PRINT '<option value="' . ALL_PROJECTS . '"';
check_selected( $p_project_id, ALL_PROJECTS );
PRINT '>' . lang_get( 'all_projects' ) . '</option>' . "\n";
}
//--
if ( !access_has_global_level( config_get( 'private_project_threshold' ), auth_get_current_user_id() ) ) {
get_projects($p_project_id, $t_project_ids);
echo "...", "\n";
} else {
//--
$t_project_count = count( $t_project_ids );
for ($i=0;$i<$t_project_count;$i++) {
$t_id = $t_project_ids[$i];
if ( $t_id != $p_filter_project_id ) { //(kivio.wanderley 29.12.2010) && !in_array($t_id, $values)
PRINT "<option value=\"$t_id\"";
check_selected( $p_project_id, $t_id );
PRINT '>' . str_repeat( "» ", $t_sep) . string_display( project_get_field( $t_id, 'name' ) ) . '</option>' . "\n"; //(kivio.wanderley 29.12.2010) str_repeat( "» ", $t_sep)
print_subproject_option_list( $t_sep, $t_id, $p_project_id, $p_filter_project_id, $p_trace ); //(kivio.wanderley 29.12.2010) $t_sep
}
}
}//END if( !access_has_global_level ...
}
# --------------------
# List projects that the current user has access to
function print_subproject_option_list( $p_sep=0, $p_parent_id, $p_project_id = null, $p_filter_project_id = null, $p_trace = false, $p_parents = Array() ) { //(kivio.wanderley 29.12.2010) $p_sep=0
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 ) {
$t_sep = $p_sep+1; //(kivio.wanderley 29.12.2010)
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( "» ", $t_sep) . string_display( project_get_field( $t_id, 'name' ) ) . '</option>' . "\n"; //(kivio.wanderley 29.12.2010) str_repeat( "» ", $t_sep)
print_subproject_option_list( $t_sep, $t_id, $p_project_id, $p_filter_project_id, $p_trace, $p_parents );
}
}
}
/* Fim da customizacao 29/12/2010
*/
# --------------------
# prints the profiles given the user id
function print_profile_option_list( $p_user_id, $p_select_id='' ) {
if ( '' === $p_select_id ) {
$p_select_id = profile_get_default( $p_user_id );
}
$t_profiles = profile_get_all_for_user( $p_user_id );
PRINT '<option value=""></option>';
foreach ( $t_profiles as $t_profile ) {
extract( $t_profile, EXTR_PREFIX_ALL, 'v' );
$v_platform = string_display( $v_platform );
$v_os = string_display( $v_os );
$v_os_build = string_display( $v_os_build );
PRINT "<option value=\"$v_id\"";
check_selected( $p_select_id, $v_id );
PRINT ">$v_platform $v_os $v_os_build</option>";
}
}
# --------------------
# prints the profiles used in a certain project
function print_profile_option_list_for_project( $p_project_id, $p_select_id='') {
if ( '' === $p_select_id ) {
$p_select_id = profile_get_default( $p_user_id );
}
$t_profiles = profile_get_all_for_project( $p_project_id );
PRINT '<option value=""></option>';
foreach ( $t_profiles as $t_profile ) {
extract( $t_profile, EXTR_PREFIX_ALL, 'v' );
$v_platform = string_display( $v_platform );
$v_os = string_display( $v_os );
$v_os_build = string_display( $v_os_build );
PRINT "<option value=\"$v_id\"";
check_selected( $p_select_id, $v_id );
PRINT ">$v_platform $v_os $v_os_build</option>";
}
}
# --------------------
function print_news_project_option_list( $p_project_id ) {
$t_mantis_project_table = config_get( 'mantis_project_table' );
$t_mantis_project_user_list_table = config_get( 'mantis_project_user_list_table' );
if ( access_has_project_level( ADMINISTRATOR ) ) {
$query = "SELECT *
FROM $t_mantis_project_table
ORDER BY name";
} else {
$t_user_id = auth_get_current_user_id();
$query = "SELECT p.id, p.name
FROM $t_mantis_project_table p, $t_mantis_project_user_list_table m
WHERE p.id=m.project_id AND
m.user_id='$t_user_id' AND
p.enabled='1'";
}
$result = db_query( $query );
$project_count = db_num_rows( $result );
for ($i=0;$i<$project_count;$i++) {
$row = db_fetch_array( $result );
extract( $row, EXTR_PREFIX_ALL, 'v' );
PRINT "<option value=\"$v_id\"";
check_selected( $v_id, $p_project_id );
PRINT ">$v_name</option>";
} # end for
}
# --------------------
# Since categories can be orphaned we need to grab all unique instances of category
# We check in the project category table and in the bug table
# We put them all in one array and make sure the entries are unique
function print_category_option_list( $p_category='', $p_project_id = null ) {
$t_mantis_project_category_table = config_get( 'mantis_project_category_table' );
if ( null === $p_project_id ) {
$c_project_id = helper_get_current_project();
} else {
$c_project_id = db_prepare_int( $p_project_id );
}
$t_project_where = helper_project_specific_where( $c_project_id );
# grab all categories in the project category table
$cat_arr = array();
$query = "SELECT DISTINCT category
FROM $t_mantis_project_category_table
WHERE $t_project_where
ORDER BY category";
$result = db_query( $query );
$category_count = db_num_rows( $result );
for ($i=0;$i<$category_count;$i++) {
$row = db_fetch_array( $result );
$cat_arr[] = string_attribute( $row['category'] );
}
sort( $cat_arr );
$cat_arr = array_unique( $cat_arr );
foreach( $cat_arr as $t_category ) {
PRINT "<option value=\"$t_category\"";
check_selected( $t_category, $p_category );
PRINT ">$t_category</option>";
}
}
# --------------------
# Since categories can be orphaned we need to grab all unique instances of category
# We check in the project category table and in the bug table
# We put them all in one array and make sure the entries are unique
function print_category_complete_option_list( $p_category='', $p_project_id = null ) {
$t_mantis_project_category_table = config_get( 'mantis_project_category_table' );
$t_mantis_bug_table = config_get( 'mantis_bug_table' );
if ( null === $p_project_id ) {
$t_project_id = helper_get_current_project();
} else {
$t_project_id = $p_project_id;
}
$t_project_where = helper_project_specific_where( $t_project_id );
# grab all categories in the project category table
$cat_arr = array();
$query = "SELECT DISTINCT category
FROM $t_mantis_project_category_table
WHERE $t_project_where
ORDER BY category";
$result = db_query( $query );
$category_count = db_num_rows( $result );
for ($i=0;$i<$category_count;$i++) {
$row = db_fetch_array( $result );
$cat_arr[] = string_attribute( $row['category'] );
}
# grab all categories in the bug table
$query = "SELECT DISTINCT category
FROM $t_mantis_bug_table
WHERE $t_project_where
ORDER BY category";
$result = db_query( $query );
$category_count = db_num_rows( $result );
for ($i=0;$i<$category_count;$i++) {
$row = db_fetch_array( $result );
$cat_arr[] = string_attribute( $row['category'] );
}
sort( $cat_arr );
$cat_arr = array_unique( $cat_arr );
foreach( $cat_arr as $t_category ) {
PRINT "<option value=\"$t_category\"";
check_selected( $p_category, $t_category );
PRINT ">$t_category</option>";
}
}
# --------------------
# Print the option list for versions
# $p_version = currently selected version.
# $p_project_id = project id, otherwise current project will be used.
# $p_released = null to get all, 1: only released, 0: only future versions
# $p_leading_black = allow selection of no version
# $p_with_subs = include subprojects
function print_version_option_list( $p_version='', $p_project_id = null, $p_released = null, $p_leading_blank = true, $p_with_subs=false ) {
if ( null === $p_project_id ) {
$c_project_id = helper_get_current_project();
} else {
$c_project_id = db_prepare_int( $p_project_id );
}
if ( $p_with_subs ) {
$versions = version_get_all_rows_with_subs( $c_project_id, $p_released );
} else {
$versions = version_get_all_rows( $c_project_id, $p_released );
}
if ( $p_leading_blank ) {
echo '<option value=""></option>';
}
foreach( $versions as $version ) {
$t_version = string_shorten( string_attribute( $version['version'] ) );
echo "<option value=\"$t_version\"";
check_selected( $p_version, $t_version );
echo ">$t_version</option>";
}
}
# --------------------
function print_build_option_list( $p_build='' ) {
$t_bug_table = config_get( 'mantis_bug_table' );
$t_overall_build_arr = array();
$t_project_id = helper_get_current_project();
$t_project_where = helper_project_specific_where( $t_project_id );
# Get the "found in" build list
$query = "SELECT DISTINCT build
FROM $t_bug_table
WHERE $t_project_where
ORDER BY build DESC";
$result = db_query( $query );
$option_count = db_num_rows( $result );
for ( $i = 0; $i < $option_count; $i++ ) {
$row = db_fetch_array( $result );
$t_overall_build_arr[] = $row['build'];
}
foreach( $t_overall_build_arr as $t_build ) {
PRINT "<option value=\"$t_build\"";
check_selected( $p_build, $t_build );
PRINT ">" . string_shorten( $t_build ) . "</option>";
}
}
# --------------------
# select the proper enum values based on the input parameter
# $p_enum_name - name of enumeration (eg: status)
# $p_val: current value
function print_enum_string_option_list( $p_enum_name, $p_val = 0 ) {
$t_config_var_name = $p_enum_name.'_enum_string';
$t_config_var_value = config_get( $t_config_var_name );
$t_arr = explode_enum_string( $t_config_var_value );
$t_enum_count = count( $t_arr );
for ( $i = 0; $i < $t_enum_count; $i++) {
$t_elem = explode_enum_arr( $t_arr[$i] );
$t_key = trim( $t_elem[0] );
$t_elem2 = get_enum_element( $p_enum_name, $t_key );
echo "<option value=\"$t_key\"";
check_selected( $p_val, $t_key );
echo ">$t_elem2</option>";
} # end for
}
# --------------------
# Select the proper enum values for status based on workflow
# or the input parameter if workflows are not used
# $p_enum_name : name of enumeration (eg: status)
# $p_current_value : current value
function get_status_option_list( $p_user_auth = 0, $p_current_value = 0, $p_show_current = true, $p_add_close = false ) {
$t_config_var_value = config_get( 'status_enum_string' );
$t_enum_workflow = config_get( 'status_enum_workflow' );
/* (K�vio) 27/08/2009
* DESCRI��O: Autoriza relator do caso modificar para qualquer status
*/
$t_bug_id = gpc_get_int( 'bug_id' ); // (K�vio) Catch current bug_id
# (K�vio) Tambem exibe todos os status do caso se seu relator for quem esiver logado
if ( ( count( $t_enum_workflow ) < 1 ) || auth_get_current_user_id() == bug_get_field( $t_bug_id, 'reporter_id' ) ) {
# workflow not defined, use default enum
$t_arr = explode_enum_string( $t_config_var_value );
} else {
# workflow defined - find allowed states
if ( isset( $t_enum_workflow[$p_current_value] ) ) {
$t_arr = explode_enum_string( $t_enum_workflow[$p_current_value] );
} else {
# workflow was not set for this status, this shouldn't happen
$t_arr = explode_enum_string( $t_config_var_value );
}
}
$t_enum_count = count( $t_arr );
$t_enum_list = array();
for ( $i = 0; $i < $t_enum_count; $i++ ) {
$t_elem = explode_enum_arr( $t_arr[$i] );
if ( ( $p_user_auth >= access_get_status_threshold( $t_elem[0] ) ) &&
( ! ( ( false == $p_show_current ) && ( $p_current_value == $t_elem[0] ) ) ) ) {
$t_enum_list[$t_elem[0]] = get_enum_element( 'status', $t_elem[0] );
}
} # end for
if ( true == $p_show_current ) {
$t_enum_list[$p_current_value] = get_enum_element( 'status', $p_current_value );
}
if ( ( true == $p_add_close ) && ( $p_current_value >= config_get( 'bug_resolved_status_threshold' ) ) ) {
$t_enum_list[CLOSED] = get_enum_element( 'status', CLOSED );
}
return $t_enum_list;
}
# --------------------
# print the status option list for the bug_update pages
function print_status_option_list( $p_select_label, $p_current_value = 0, $p_allow_close = false, $p_project_id = null ) {
$t_current_auth = access_get_project_level( $p_project_id );
$t_enum_list = get_status_option_list( $t_current_auth, $p_current_value, true, $p_allow_close );
if ( count( $t_enum_list ) > 0 ) {
# resort the list into ascending order
ksort( $t_enum_list );
reset( $t_enum_list );
echo '<select name="' . $p_select_label . '">';
foreach ( $t_enum_list as $key => $val ) {
echo "<option value=\"$key\"";
check_selected( $key, $p_current_value );
echo ">$val</option>";
}
echo '</select>';
} else {
echo get_enum_to_string( 'status_enum_string', $p_current_value );
}
}
# --------------------
# prints the list of a project's users
# if no project is specified uses the current project
function print_project_user_option_list( $p_project_id=null ) {
print_user_option_list( 0, $p_project_id );
}
# --------------------
# prints the list of access levels that are less than or equal to the access level of the
# logged in user. This is used when adding users to projects
function print_project_access_levels_option_list( $p_val, $p_project_id = null ) {
$t_current_user_access_level = access_get_project_level( $p_project_id );
$t_access_levels_enum_string = config_get( 'access_levels_enum_string' );
# Add [default access level] to add the user to a project
# with his default access level.
PRINT "<option value=\"" . DEFAULT_ACCESS_LEVEL . "\"";
PRINT ">[" . lang_get( 'default_access_level' ) . "]</option>";
$t_arr = explode_enum_string( $t_access_levels_enum_string );
$enum_count = count( $t_arr );
for ($i=0;$i<$enum_count;$i++) {
$t_elem = explode_enum_arr( $t_arr[$i] );
# a user must not be able to assign another user an access level that is higher than theirs.
if ( $t_elem[0] > $t_current_user_access_level ) {
continue;
}
$t_access_level = get_enum_element( 'access_levels', $t_elem[0] );
PRINT "<option value=\"$t_elem[0]\"";
check_selected( $p_val, $t_elem[0] );
PRINT ">$t_access_level</option>";
} # end for
}
// Retorna os n�veis de acesso menores que o n�vel de acesso de projeto do usu�rio logado
// Customiza��o feita em 18/02/2008
// Customiza��o para pertmitir que um Administrador de um projeto possa criar usu�rios.
function print_project_access_levels_option_list_customizada( $p_val, $p_project_id = null ) {
$t_current_user_access_level = access_get_project_level( $p_project_id );
$t_access_levels_enum_string = config_get( 'access_levels_enum_string' );
# Add [default access level] to add the user to a project
# with his default access level.
//PRINT "<option value=\"" . DEFAULT_ACCESS_LEVEL . "\"";
//PRINT ">[" . lang_get( 'default_access_level' ) . "]</option>";
$t_arr = explode_enum_string( $t_access_levels_enum_string );
$enum_count = count( $t_arr );
for ($i=0;$i<$enum_count;$i++) {
$t_elem = explode_enum_arr( $t_arr[$i] );
# a user must not be able to assign another user an access level that is higher than theirs.
if ( $t_elem[0] >= $t_current_user_access_level ) {
continue;
}
$t_access_level = get_enum_element( 'access_levels', $t_elem[0] );
PRINT "<option value=\"$t_elem[0]\"";
check_selected( $p_val, $t_elem[0] );
PRINT ">$t_access_level</option>";
} # end for
}
# --------------------
function print_language_option_list( $p_language ) {
$t_arr = config_get( 'language_choices_arr' );
$enum_count = count( $t_arr );
for ($i=0;$i<$enum_count;$i++) {
$t_language = string_attribute( $t_arr[$i] );
PRINT "<option value=\"$t_language\"";
check_selected( $t_language, $p_language );
PRINT ">$t_language</option>";
} # end for
}
# --------------------
# @@@ preliminary support for multiple bug actions.
function print_all_bug_action_option_list() {
$commands = array( 'MOVE' => lang_get('actiongroup_menu_move'),
'COPY' => lang_get('actiongroup_menu_copy'),
'ASSIGN' => lang_get('actiongroup_menu_assign'),
'CLOSE' => lang_get('actiongroup_menu_close'),
'DELETE' => lang_get('actiongroup_menu_delete'),
'RESOLVE' => lang_get('actiongroup_menu_resolve'),
'SET_STICKY' => lang_get( 'actiongroup_menu_set_sticky' ),
'UP_PRIOR' => lang_get('actiongroup_menu_update_priority'),
'UP_STATUS' => lang_get('actiongroup_menu_update_status'),
'UP_CATEGORY' => lang_get('actiongroup_menu_update_category'),
'VIEW_STATUS' => lang_get( 'actiongroup_menu_update_view_status' ) );
$t_project_id = helper_get_current_project();
if ( ALL_PROJECTS != $t_project_id ) {
$t_user_id = auth_get_current_user_id();
$t_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
foreach( $t_custom_field_ids as $t_custom_field_id ) {
# if user has not access right to modify the field, then there is no
# point in showing it.
if ( !custom_field_has_write_access_to_project( $t_custom_field_id, $t_project_id, $t_user_id ) ) {
continue;
}
$t_custom_field_def = custom_field_get_definition( $t_custom_field_id );
$t_command_id = 'custom_field_' . $t_custom_field_id;
$t_command_caption = sprintf( lang_get( 'actiongroup_menu_update_field' ), lang_get_defaulted( $t_custom_field_def['name'] ) );
$commands[$t_command_id] = $t_command_caption;
}
}
$t_custom_group_actions = config_get( 'custom_group_actions' );
foreach( $t_custom_group_actions as $t_custom_group_action ) {
$commands[$t_custom_group_action['action']] = lang_get_defaulted( $t_custom_group_action['action'] );
}
while (list ($key,$val) = each ($commands)) {
PRINT "<option value=\"".$key."\">".$val."</option>";
}
}
# --------------------
# list of users that are NOT in the specified project and that are enabled
# if no project is specified use the current project
# also exclude any administrators
function print_project_user_list_option_list( $p_project_id=null ) {
$t_mantis_project_user_list_table = config_get( 'mantis_project_user_list_table' );
$t_mantis_user_table = config_get( 'mantis_user_table' );
if ( null === $p_project_id ) {
$p_project_id = helper_get_current_project();
}
$c_project_id = (int)$p_project_id;
$t_adm = ADMINISTRATOR;
$query = "SELECT DISTINCT u.id, u.username, u.realname
FROM $t_mantis_user_table u
LEFT JOIN $t_mantis_project_user_list_table p
ON p.user_id=u.id AND p.project_id='$c_project_id'
WHERE u.access_level<$t_adm AND
u.enabled = 1 AND
p.user_id IS NULL
ORDER BY u.realname, u.username";
$result = db_query( $query );
$t_display = array();
$t_sort = array();
$t_users = array();
$t_show_realname = ( ON == config_get( 'show_realname' ) );
$t_sort_by_last_name = ( ON == config_get( 'sort_by_last_name' ) );
$category_count = db_num_rows( $result );
for ($i=0;$i<$category_count;$i++) {
$row = db_fetch_array( $result );
$t_users[] = $row['id'];
$t_user_name = string_attribute( $row['username'] );
$t_sort_name = $t_user_name;
if ( ( isset( $row['realname'] ) ) && ( $row['realname'] <> "" ) && $t_show_realname ) {
$t_user_name = string_attribute( $row['realname'] );
if ( $t_sort_by_last_name ) {
$t_sort_name_bits = split( ' ', strtolower( $t_user_name ), 2 );
$t_sort_name = ( isset( $t_sort_name_bits[1] ) ? $t_sort_name_bits[1] . ', ' : '' ) . $t_sort_name_bits[0];
} 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 );
for ($i = 0; $i < count( $t_sort ); $i++ ) {
PRINT '<option value="' . $t_users[$i] . '">' . $t_display[$i] . '</option>';
}
}
/*
* (K�vio) 22/01/2010
* DESCRI��O: Ao gerenciar usuario a lista de projetos nao atribuidos em ordem
* In�cio >>>
*/
# --------------------
# return "TRUE" instead of "selected"
# used by the function "print_project_option_list2()" and "print_subproject_option_list2()"
function check_selected2( $p_var, $p_val=true ) {
if ( is_array( $p_var ) ) {
foreach( $p_var as $p_this_var ) {
if ( $p_this_var == $p_val ) {
return true;
}
}
} else {
if ( $p_var == $p_val ) {
return true;
}
}
}
# --------------------
# modified function "print_project_option_list()"
function print_project_option_list2( $p_project_id = null, $p_filter_project_id = null ) {
project_cache_all();
$t_project_ids = current_user_get_accessible_projects();
$t_project_count = count( $t_project_ids );
for ($i=0;$i<$t_project_count;$i++) {
$t_id = $t_project_ids[$i];
if ( $t_id != $p_filter_project_id ) {
if( check_selected2( $p_project_id, $t_id ) ) {
PRINT "<option value=\"$t_id\"";
PRINT '>' . string_display( project_get_field( $t_id, 'name' ) ) . '</option>' . "\n";
}
else { # (kivio 29.10.10) Projects that user is assigned shown in color gray
//PRINT "<option value=\"$t_id\" style='color:gray'";//" disabled='disabled'"
//PRINT '>' . string_display( project_get_field( $t_id, 'name' ) ) . '</option>' . "\n";
}// End else
print_subproject_option_list2( $t_id, $p_project_id, $p_filter_project_id );
}
}// End for
}
# --------------------
# modified function "print_subproject_option_list()"
function print_subproject_option_list2( $p_parent_id, $p_project_id = null, $p_filter_project_id = null, $p_parents = Array() ) {
array_push( $p_parents, $p_parent_id );
$t_subproject_ids = current_user_get_accessible_subprojects( $p_parent_id );
$t_subproject_count = count( $t_subproject_ids );
for ($j=0;$j<$t_subproject_count;$j++) {
$t_full_id = $t_id = $t_subproject_ids[$j];
if ( $t_id != $p_filter_project_id ) {
if( check_selected2( $p_project_id, $t_full_id ) ) {
PRINT "<option value=\"";
PRINT "$t_full_id\"";
PRINT '>' . str_repeat( "» ", count( $p_parents ) ) . string_display( project_get_field( $t_id, 'name' ) ) . '</option>' . "\n";
}
else { # (kivio 29.10.10) Subprojects that user is assigned shown in color gray
//PRINT "<option value=\"";
//PRINT "$t_full_id\" style='color:gray'";//disabled='disabled'";
//PRINT '>' . str_repeat( "» ", count( $p_parents ) ) . string_display( project_get_field( $t_id, 'name' ) ) . '</option>' . "\n";
}
print_subproject_option_list2( $t_id, $p_project_id, $p_filter_project_id, $p_parents );
}
}// End for
}
# --------------------
# list of projects that a user is NOT in
function print_project_user_list_option_list2( $p_user_id ) {
$t_mantis_project_user_list_table = config_get( 'mantis_project_user_list_table' );
$t_mantis_project_table = config_get( 'mantis_project_table' );
$c_user_id = db_prepare_int( $p_user_id );
$query = "SELECT DISTINCT p.id, p.name
FROM $t_mantis_project_table p
LEFT JOIN $t_mantis_project_user_list_table u
ON p.id=u.project_id AND u.user_id='$c_user_id'
WHERE p.enabled=1 AND
u.user_id IS NULL
ORDER BY p.name";
$result = db_query( $query );
$category_count = db_num_rows( $result );
$t_project_id = array();
for ($i=0;$i<$category_count;$i++) {
$row = db_fetch_array( $result );
$t_project_name = string_attribute( $row['name'] );
$t_project_id[$i] = $row['id'];
}
print_project_option_list2( $t_project_id, null );
}
/*
* (K�vio) 22/01/2010
* Fim <<<
*/
# --------------------
# list of projects that a user is in
function print_project_user_list( $p_user_id, $p_include_remove_link = true ) {
$t_mantis_project_user_list_table = config_get( 'mantis_project_user_list_table' );
$t_mantis_project_table = config_get( 'mantis_project_table' );
$c_user_id = db_prepare_int( $p_user_id );
$query = "SELECT DISTINCT p.id, p.name, p.view_state, u.access_level
FROM $t_mantis_project_table p
LEFT JOIN $t_mantis_project_user_list_table u
ON p.id=u.project_id
WHERE p.enabled=1 AND
u.user_id='$c_user_id'
ORDER BY p.name";
$result = db_query( $query );
$category_count = db_num_rows( $result );
echo '<tr class="row-2">'; # (kivio 29.10.10)
echo '<td class="left">'; # (kivio 29.10.10)
for ($i=0;$i<$category_count;$i++) {
$row = db_fetch_array( $result );
$t_project_id = $row['id'];
$t_project_name = $row['name'];
$t_view_state = $row['view_state'];
$t_access_level = $row['access_level'];
$t_access_level = get_enum_element( 'access_levels', $t_access_level );
$t_view_state = get_enum_element( 'project_view_state', $t_view_state );
echo $t_project_name.' ['.$t_access_level.'] ('.$t_view_state.')';
if ( $p_include_remove_link && access_has_project_level( config_get( 'project_user_threshold' ), $t_project_id ) ) {
# (kivio 29.10.10) Linha comentada e adicao do input
//echo ' [<a class="small" href="manage_user_proj_delete.php?project_id='.$t_project_id.'&user_id='.$p_user_id.'">'. lang_get( 'remove_link' ).'</a>]';
echo ' <input type="checkbox" name="projects_chk[]" value="',$t_project_id,'" />';
}
echo '<br />';
}
# (kivio 29.10.10) Link para acao de remover
echo '</td>';
echo '</tr>';
echo '<td/>';
echo '<td class="left">';
echo '<input type="submit" class="button" name="submit_action" value="'.lang_get( 'remove_selected' ).'" />';
echo '</td>';
}
# --------------------
###########################################################################
# String printing API
###########################################################################
# --------------------
# prints a link to VIEW a bug given an ID
# account for the user preference and site override
function print_bug_link( $p_bug_id, $p_detail_info = true ) {
PRINT string_get_bug_view_link( $p_bug_id, null, $p_detail_info );
}
# --------------------
# prints a link to UPDATE a bug given an ID
# account for the user preference and site override
function print_bug_update_link( $p_bug_id ) {
PRINT string_get_bug_update_link( $p_bug_id );
}
# --------------------
# formats the priority given the status
# shows the priority in BOLD if the bug is NOT closed and is of significant priority
function print_formatted_priority_string( $p_status, $p_priority ) {
$t_pri_str = get_enum_element( 'priority', $p_priority );
if ( ( HIGH <= $p_priority ) &&
( CLOSED != $p_status ) ) {
PRINT "<span class=\"bold\">$t_pri_str</span>";
} else {
PRINT $t_pri_str;
}
}
# --------------------
# formats the severity given the status
# shows the severity in BOLD if the bug is NOT closed and is of significant severity
function print_formatted_severity_string( $p_status, $p_severity ) {
$t_sev_str = get_enum_element( 'severity', $p_severity );
if ( ( MAJOR <= $p_severity ) &&
( CLOSED != $p_status ) ) {
PRINT "<span class=\"bold\">$t_sev_str</span>";
} else {
PRINT $t_sev_str;
}
}
# --------------------
function print_project_category_string( $p_project_id ) {
$t_mantis_project_category_table = config_get( 'mantis_project_category_table' );
$c_project_id = db_prepare_int( $p_project_id );
$query = "SELECT category
FROM $t_mantis_project_category_table
WHERE project_id='$c_project_id'
ORDER BY category";
$result = db_query( $query );
$category_count = db_num_rows( $result );
$t_string = '';
for ($i=0;$i<$category_count;$i++) {
$row = db_fetch_array( $result );
$t_category = $row['category'];
if ( $i+1 < $category_count ) {
$t_string .= $t_category.', ';
} else {
$t_string .= $t_category;
}
}
return $t_string;
}
# --------------------
function print_project_version_string( $p_project_id ) {
$t_mantis_project_version_table = config_get( 'mantis_project_version_table' );
$t_mantis_project_table = config_get( 'mantis_project_table' );
$c_project_id = db_prepare_int( $p_project_id );
$query = "SELECT version
FROM $t_mantis_project_version_table
WHERE project_id='$c_project_id'";
$result = db_query( $query );
$version_count = db_num_rows( $result );
$t_string = '';
for ($i=0;$i<$version_count;$i++) {
$row = db_fetch_array( $result );
$t_version = $row['version'];
if ( $i+1 < $version_count ) {
$t_string .= $t_version.', ';
} else {
$t_string .= $t_version;
}
}
return $t_string;
}
# --------------------
###########################################################################
# Link Printing API
###########################################################################
# --------------------
# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
function print_view_bug_sort_link( $p_string, $p_sort_field, $p_sort, $p_dir, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
if ( $p_columns_target == COLUMNS_TARGET_PRINT_PAGE ) {
if ( $p_sort_field == $p_sort ) {
# We toggle between ASC and DESC if the user clicks the same sort order
if ( 'ASC' == $p_dir ) {
$p_dir = 'DESC';
} else {
$p_dir = 'ASC';
}
} else { # Otherwise always start with ASCending
$t_dir = 'ASC';
}
echo '<a href="view_all_set.php?sort='.$p_sort_field.'&dir='.$p_dir.'&type=2&print=1">'.$p_string.'</a>';
} else if ( $p_columns_target == COLUMNS_TARGET_VIEW_PAGE ) {
if ( $p_sort_field == $p_sort ) {
# we toggle between ASC and DESC if the user clicks the same sort order
if ( 'ASC' == $p_dir ) {
$p_dir = 'DESC';
} else {
$p_dir = 'ASC';
}
} else { # Otherwise always start with ASCending
$t_dir = 'ASC';
}
echo '<a href="view_all_set.php?sort='.$p_sort_field.'&dir='.$p_dir.'&type=2">'.$p_string.'</a>';
} else {
echo $p_string;
}
}
# --------------------
function print_manage_user_sort_link( $p_page, $p_string, $p_field, $p_dir, $p_sort_by, $p_hide=0 ) {
if ( $p_sort_by == $p_field ) { # If this is the selected field flip the order
if ( 'ASC' == $p_dir || ASC == $p_dir ) {
$t_dir = 'DESC';
} else {
$t_dir = 'ASC';
}
} else { # Otherwise always start with ASCending
$t_dir = 'ASC';
}
PRINT '<a href="' . $p_page . '?sort=' . $p_field . '&dir=' . $t_dir . '&save=1&hide=' . $p_hide . '">' . $p_string . '</a>';
}
# --------------------
function print_manage_project_sort_link( $p_page, $p_string, $p_field, $p_dir, $p_sort_by ) {
if ( $p_sort_by == $p_field ) { # If this is the selected field flip the order
if ( 'ASC' == $p_dir || ASC == $p_dir ) {
$t_dir = 'DESC';
} else {
$t_dir = 'ASC';
}
} else { # Otherwise always start with ASCending
$t_dir = 'ASC';
}
PRINT '<a href="' . $p_page . '?sort=' . $p_field . '&dir=' . $t_dir . '">' . $p_string . '</a>';
}
# --------------------
# print a button which presents a standalone form.
# if the $p_link is blank then the text is printed but no link is created
# if $p_new_window is true, link will open in a new window, default false.
function print_button( $p_action_page, $p_label ) {
echo '<form method="POST" action="', $p_action_page, '"><input type="submit" class="button-small" value="', $p_label, '" /></form>';
}
# --------------------
# print the bracketed links used near the top
# if the $p_link is blank then the text is printed but no link is created
# if $p_new_window is true, link will open in a new window, default false.
function print_bracket_link( $p_link, $p_url_text, $p_new_window = false ) {
if (is_blank( $p_link )) {
PRINT "[ $p_url_text ]";
} else {
if( true == $p_new_window ) {
PRINT "[ <a href=\"$p_link\" target=\"_blank\">$p_url_text</a> ]";
} else {
PRINT "[ <a href=\"$p_link\">$p_url_text</a> ]";
}
}
}
# --------------------
# print a HTML link
function print_link( $p_link, $p_url_text ) {
if (is_blank( $p_link )) {
PRINT " $p_url_text ";
} else {
PRINT " <a href=\"$p_link\">$p_url_text</a> ";
}
}
# --------------------
# print a HTML page link
function print_page_link( $p_page_url, $p_text = '', $p_page_no=0, $p_page_cur=0 ) {
if (is_blank( $p_text )) {
$p_text = $p_page_no;
}
if ( ( 0 < $p_page_no ) && ( $p_page_no != $p_page_cur ) ) {
PRINT " <a href=\"$p_page_url?page_number=$p_page_no\">$p_text</a> ";
} else {
PRINT " $p_text ";
}
}
# --------------------
# print a list of page number links (eg [1 2 3])
function print_page_links( $p_page, $p_start, $p_end, $p_current ) {
$t_items = array();
$t_link = '';
# Check if we have more than one page,
# otherwise return without doing anything.
if ( $p_end - $p_start < 1 ) {
return;
}
# Get localized strings
$t_first = lang_get( 'first' );
$t_last = lang_get( 'last' );
$t_prev = lang_get( 'prev' );
$t_next = lang_get( 'next' );
$t_page_links = 10;
print( "[ " );
# First and previous links
print_page_link( $p_page, $t_first, 1, $p_current );
print_page_link( $p_page, $t_prev, $p_current - 1, $p_current );
# Page numbers ...
$t_first_page = max( $p_start, $p_current - $t_page_links/2 );
$t_first_page = min( $t_first_page, $p_end - $t_page_links );
$t_first_page = max( $t_first_page, $p_start );
if ( $t_first_page > 1 ) {
print( " ... " );
}
$t_last_page = $t_first_page + $t_page_links;
$t_last_page = min( $t_last_page, $p_end );
for ( $i = $t_first_page ; $i <= $t_last_page ; $i++ ) {
if ( $i == $p_current ) {
array_push( $t_items, $i );
} else {
array_push( $t_items, "<a href=\"$p_page?page_number=$i\">$i</a>" );
}
}
PRINT implode( ' ', $t_items );
if ( $t_last_page < $p_end ) {
print( " ... " );
}
# Next and Last links
if ( $p_current < $p_end ) {
print_page_link( $p_page, $t_next, $p_current + 1, $p_current );
} else {
print_page_link( $p_page, $t_next );
}
print_page_link( $p_page, $t_last, $p_end, $p_current );
print( " ]" );
}
# --------------------
# print a mailto: href link
function print_email_link( $p_email, $p_text ) {
PRINT get_email_link($p_email, $p_text);
}
# --------------------
# return the mailto: href string link instead of printing it
function get_email_link( $p_email, $p_text ) {
return prepare_email_link( $p_email, $p_text );
}
# --------------------
# print a mailto: href link with subject
function print_email_link_with_subject( $p_email, $p_text, $p_bug_id ) {
$t_subject = email_build_subject( $p_bug_id );
PRINT get_email_link_with_subject( $p_email, $p_text, $t_subject );
}
# --------------------
# return the mailto: href string link instead of printing it
# add subject line
function get_email_link_with_subject( $p_email, $p_text, $p_summary ) {
if ( !access_has_project_level( config_get( 'show_user_email_threshold' ) ) ) {
return $p_text;
}
# If we apply string_url() to the whole mailto: link then the @
# gets turned into a %40 and you can't right click in browsers to
# do Copy Email Address. If we don't apply string_url() to the
# summary text then an ampersand (for example) will truncate the text
$p_summary = string_url( $p_summary );
$t_mailto = string_attribute( "mailto:$p_email?subject=$p_summary" );
$p_text = string_display( $p_text );
return "<a href=\"$t_mailto\">$p_text</a>";
}
/* (K�vio) 14/10/2010
DESCRI��O: Substitui��o da fun��o pela da vers�o 1.2.3 do mantis
*/
# --------------------
# Print a hidden input for each name=>value pair in the array
#
# If a value is an array an input will be created for each item with a name
# that ends with []
# The names and values are passed through string_html_specialchars() before being displayed
function print_hidden_inputs( $p_assoc_array ) {
foreach( $p_assoc_array as $t_key => $t_val ) {
print_hidden_input( $t_key, $t_val );
}
}
function print_hidden_input( $p_field_key, $p_field_val ) {
if( is_array( $p_field_val ) ) {
foreach( $p_field_val AS $t_key => $t_value ) {
if( is_array( $t_value ) ) {
$t_key = string_html_entities( $t_key );
$t_field_key = $p_field_key . '[' . $t_key . ']';
print_hidden_input( $t_field_key, $t_value );
} else {
$t_field_key = $p_field_key . '[' . $t_key . ']';
print_hidden_input( $t_field_key, $t_value );
}
}
} else {
$t_key = string_html_entities( $p_field_key );
$t_val = string_html_entities( $p_field_val );
echo "<input type=\"hidden\" name=\"$t_key\" value=\"$t_val\" />\n";
}
}
/* Fim da customiza��o 14/10/2010
*/
#=============================
# Functions that used to be in html_api
#=============================
# --------------------
# This prints the little [?] link for user help
# The $p_a_name is a link into the documentation.html file
function print_documentation_link( $p_a_name='' ) {
# @@@ Disable documentation links for now. May be re-enabled if linked to new manual.
# PRINT "<a href=\"doc/documentation.html#$p_a_name\" target=\"_info\">[?]</a>";
}
# --------------------
# print the hr
function print_hr( $p_hr_size=null, $p_hr_width=null ) {
if ( null === $p_hr_size ) {
$p_hr_size = config_get( 'hr_size' );
}
if ( null === $p_hr_width ) {
$p_hr_width = config_get( 'hr_width' );
}
PRINT "<hr size=\"$p_hr_size\" width=\"$p_hr_width%\" />";
}
# --------------------
# prints the signup link
function print_signup_link() {
if( ( ON == config_get( 'allow_signup' ) ) &&
( ON == config_get( 'enable_email_notification' ) ) ) {
print_bracket_link( 'signup_page.php', lang_get( 'signup_link' ) );
}
}
# --------------------
# prints the login link
function print_login_link() {
print_bracket_link( 'login_page.php', lang_get( 'login_title' ) );
}
# --------------------
# prints the lost pwd link
function print_lost_password_link() {
# lost password feature disabled or reset password via email disabled -> stop here!
if( ( ON == config_get( 'lost_password_feature' ) ) &&
( ON == config_get( 'send_reset_password' ) ) &&
( ON == config_get( 'enable_email_notification' ) ) ) {
print_bracket_link( 'lost_pwd_page.php', lang_get( 'lost_password_link' ) );
}
}
# --------------------
function print_proceed( $p_result, $p_query, $p_link ) {
PRINT '<br />';
PRINT '<div align="center">';
if ( $p_result ) { # SUCCESS
PRINT lang_get( 'operation_successful' ) . '<br />';
} else { # FAILURE
print_sql_error( $p_query );
}
print_bracket_link( $p_link, lang_get( 'proceed' ) );
PRINT '</div>';
}
#===============================
# Deprecated Functions
#===============================
# --------------------
# print our standard mysql query error
# this function should rarely (if ever) be reached. instead the db_()
# functions should trap (although inelegantly).
function print_sql_error( $p_query ) {
global $MANTIS_ERROR, $g_administrator_email;
PRINT $MANTIS_ERROR[ERROR_SQL];
print_email_link( $g_administrator_email, lang_get( 'administrator' ) );
PRINT "<br />$p_query;<br />";
}
# --------------------
# This is our generic error printing function
# Errors should terminate the script immediately
function print_mantis_error( $p_error_num=0 ) {
global $MANTIS_ERROR;
PRINT '<html><head></head><body>';
PRINT $MANTIS_ERROR[$p_error_num];
PRINT '</body></html>';
exit;
}
# --------------------
# Get icon corresponding to the specified filename
function print_file_icon( $p_filename ) {
$t_file_type_icons = config_get( 'file_type_icons' );
$ext = strtolower( file_get_extension( $p_filename ) );
if ( is_blank( $ext ) || !isset( $t_file_type_icons[$ext] ) ) {
$ext = '?';
}
$t_name = $t_file_type_icons[$ext];
PRINT '<img src="' . config_get( 'path' ) . 'images/'. $t_name . '" width="16" height="16" border="0" />';
}
# --------------------
# Prints an RSS image that is hyperlinked to an RSS feed.
function print_rss( $p_feed_url, $p_title = '' ) {
$t_path = config_get( 'path' );
echo '<a href="', $p_feed_url, '" title="', $p_title, '"><img src="', $t_path, '/images/', 'rss.gif" border="0" alt="', $p_title, '" width="26" height="13" /></a>';
}
?> user_api.php (36,120 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: user_api.php,v 1.1 2008/03/11 19:12:57 d333859 Exp $
# --------------------------------------------------------
$t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
require_once( $t_core_dir . 'email_api.php' );
require_once( $t_core_dir . 'ldap_api.php' );
### User API ###
#===================================
# Caching
#===================================
#########################################
# SECURITY NOTE: cache globals are initialized here to prevent them
# being spoofed if register_globals is turned on
$g_cache_user = array();
# --------------------
# Cache a user row if necessary and return the cached copy
# If the second parameter is true (default), trigger an error
# if the user can't be found. If the second parameter is
# false, return false if the user can't be found.
function user_cache_row( $p_user_id, $p_trigger_errors=true) {
global $g_cache_user;
$c_user_id = db_prepare_int( $p_user_id );
$t_user_table = config_get( 'mantis_user_table' );
if ( isset ( $g_cache_user[$c_user_id] ) ) {
return $g_cache_user[$c_user_id];
}
$query = "SELECT *
FROM $t_user_table
WHERE id='$c_user_id'";
$result = db_query( $query );
if ( 0 == db_num_rows( $result ) ) {
if ( $p_trigger_errors ) {
trigger_error( ERROR_USER_NOT_FOUND, ERROR );
} else {
return false;
}
}
$row = db_fetch_array( $result );
$g_cache_user[$c_user_id] = $row;
return $row;
}
# --------------------
# Clear the user cache (or just the given id if specified)
function user_clear_cache( $p_user_id = null ) {
global $g_cache_user;
if ( null === $p_user_id ) {
$g_cache_user = array();
} else {
$c_user_id = db_prepare_int( $p_user_id );
unset( $g_cache_user[$c_user_id] );
}
return true;
}
#===================================
# Boolean queries and ensures
#===================================
# --------------------
# check to see if user exists by id
# return true if it does, false otherwise
#
# Use user_cache_row() to benefit from caching if called multiple times
# and because if the user does exist the data may well be wanted
function user_exists( $p_user_id ) {
$row = user_cache_row( $p_user_id, false );
if ( false === $row ) {
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 user_ensure_exists( $p_user_id ) {
if ( !user_exists( $p_user_id ) ) {
trigger_error( ERROR_USER_NOT_FOUND, ERROR );
}
}
# --------------------
# return true if the username is unique, false if there is already a user
# with that username
function user_is_name_unique( $p_username ) {
$c_username = db_prepare_string( $p_username );
$t_user_table = config_get( 'mantis_user_table' );
$query = "SELECT username
FROM $t_user_table
WHERE username='$c_username'";
$result = db_query( $query, 1 );
if ( db_num_rows( $result ) > 0 ) {
return false;
} else {
return true;
}
}
# --------------------
# Check if the username is unique and trigger an ERROR if it isn't
function user_ensure_name_unique( $p_username ) {
if ( !user_is_name_unique( $p_username ) ) {
trigger_error( ERROR_USER_NAME_NOT_UNIQUE, ERROR );
}
}
# --------------------
# Check if the realname is a valid username (does not account for uniqueness)
# Return 0 if it is invalid, The number of matches + 1
function user_is_realname_unique( $p_username, $p_realname ) {
if ( is_blank( $p_realname ) ) { # don't bother checking if realname is blank
return 1;
}
$c_realname = db_prepare_string( $p_realname );
# allow realname to match username
$t_count = 0;
if ( $p_realname <> $p_username ) {
# check realname does not match an existing username
if ( user_get_id_by_name( $p_realname ) ) {
return 0;
}
# check to see if the realname is unique
$t_user_table = config_get( 'mantis_user_table' );
$query = "SELECT id
FROM $t_user_table
WHERE realname='$c_realname'";
$result = db_query( $query );
$t_count = db_num_rows( $result );
if ( $t_count > 0 ) {
# set flags for non-unique realnames
if ( config_get( 'differentiate_duplicates' ) ) {
user_set_field( $t_user_id, 'duplicate_realname', ON );
for ( $i=0 ; $i < $count ; $i++ ) {
$t_id = db_result( $result, $i );
user_set_field( $t_id, 'duplicate_realname', ON );
}
}
}
}
return $t_count + 1;
}
# --------------------
# Check if the realname is a unique
# Trigger an error if the username is not valid
function user_ensure_realname_unique( $p_username, $p_realname ) {
if ( 1 > user_is_realname_unique( $p_username, $p_realname ) ) {
trigger_error( ERROR_USER_REAL_MATCH_USER, ERROR );
}
}
# --------------------
# Check if the username is a valid username (does not account for uniqueness)
# realname can match
# Return true if it is, false otherwise
function user_is_name_valid( $p_username ) {
# The DB field is only 32 characters
if ( strlen( $p_username ) > 32 ) {
return false;
}
# Only allow a basic set of characters
//Comentado em 11/03/2008
// Customiza��o para permitir cadastrar usu�rio com login igual ao login do email previdencia.
//Ex.: Permitir cadastrar usu�rio com nome do usu�rio felipe.santiago
// if ( 0 == preg_match( config_get( 'user_login_valid_regex' ), $p_username ) ) {
// return false;
// }
# We have a valid username
return true;
}
# --------------------
# Check if the username is a valid username (does not account for uniqueness)
# Trigger an error if the username is not valid
function user_ensure_name_valid( $p_username ) {
if ( !user_is_name_valid( $p_username ) ) {
trigger_error( ERROR_USER_NAME_INVALID, ERROR );
}
}
# --------------------
# return whether user is monitoring bug for the user id and bug id
function user_is_monitoring_bug( $p_user_id, $p_bug_id ) {
$c_user_id = db_prepare_int( $p_user_id );
$c_bug_id = db_prepare_int( $p_bug_id );
$t_bug_monitor_table = config_get( 'mantis_bug_monitor_table' );
$query = "SELECT COUNT(*)
FROM $t_bug_monitor_table
WHERE user_id='$c_user_id' AND bug_id='$c_bug_id'";
$result = db_query( $query );
if ( 0 == db_result( $result ) ) {
return false;
} else {
return true;
}
}
# --------------------
# return true if the user has access of ADMINISTRATOR or higher, false otherwise
function user_is_administrator( $p_user_id ) {
$t_access_level = user_get_field( $p_user_id, 'access_level' );
if ( $t_access_level >= ADMINISTRATOR ) {
return true;
} else {
return false;
}
}
# --------------------
# return true is the user account is protected, false otherwise
function user_is_protected( $p_user_id ) {
if ( ON == user_get_field( $p_user_id, 'protected' ) ) {
return true;
} else {
return false;
}
}
# --------------------
# Trigger an ERROR if the user account is protected
function user_ensure_unprotected( $p_user_id ) {
if ( user_is_protected( $p_user_id ) ) {
trigger_error( ERROR_PROTECTED_ACCOUNT, ERROR );
}
}
# --------------------
# return true is the user account is enabled, false otherwise
function user_is_enabled( $p_user_id ) {
if ( ON == user_get_field( $p_user_id, 'enabled' ) ) {
return true;
} else {
return false;
}
}
# --------------------
# count the number of users at or greater than a specific level
function user_count_level( $p_level=ANYBODY ) {
$t_level = db_prepare_int( $p_level );
$t_user_table = config_get( 'mantis_user_table' );
$query = "SELECT COUNT(id) FROM $t_user_table WHERE access_level>=$t_level";
$result = db_query( $query );
# Get the list of connected users
$t_users = db_result( $result );
return $t_users;
}
# --------------------
# Return an array of user ids that are logged in.
# A user is considered logged in if the last visit timestamp is within the
# specified session duration.
# If the session duration is 0, then no users will be returned.
function user_get_logged_in_user_ids( $p_session_duration_in_minutes ) {
$t_session_duration_in_minutes = (integer)$p_session_duration_in_minutes;
# if session duration is 0, then there is no logged in users.
if ( $t_session_duration_in_minutes == 0 ) {
return array();
}
# Generate timestamp
# @@@ The following code may not be portable accross DBMS.
$t_last_timestamp_threshold = mktime( date( "H" ), date( "i" ) -1 * $t_session_duration_in_minutes, date("s"), date("m"), date("d"), date("Y") );
$c_last_timestamp_threshold = date( "Y-m-d H:i:s" , $t_last_timestamp_threshold );
$t_user_table = config_get( 'mantis_user_table' );
# Execute query
$query = "SELECT id FROM $t_user_table WHERE last_visit > '$c_last_timestamp_threshold'";
$result = db_query( $query, 1 );
# Get the list of connected users
$t_users_connected = array();
while ( $row = db_fetch_array( $result ) ) {
$t_users_connected[] = $row['id'];
}
return $t_users_connected;
}
#===================================
# Creation / Deletion / Updating
#===================================
# --------------------
# Create a user.
# returns false if error, the generated cookie string if ok
function user_create( $p_username, $p_password, $p_email='', $p_access_level=null, $p_protected=false, $p_enabled=true, $p_realname='' ) {
if ( null === $p_access_level ) {
$p_access_level = config_get( 'default_new_account_access_level');
}
$t_password = auth_process_plain_password( $p_password );
$c_username = db_prepare_string( $p_username );
$c_realname = db_prepare_string( $p_realname );
$c_password = db_prepare_string( $t_password );
$c_email = db_prepare_string( $p_email );
$c_access_level = db_prepare_int( $p_access_level );
$c_protected = db_prepare_bool( $p_protected );
$c_enabled = db_prepare_bool( $p_enabled );
user_ensure_name_valid( $p_username );
user_ensure_name_unique( $p_username );
user_ensure_realname_unique( $p_username, $p_realname );
email_ensure_valid( $p_email );
$t_seed = $p_email . $p_username;
$t_cookie_string = auth_generate_unique_cookie_string( $t_seed );
$t_user_table = config_get( 'mantis_user_table' );
$query = "INSERT INTO $t_user_table
( username, email, password, date_created, last_visit,
enabled, access_level, login_count, cookie_string, realname )
VALUES
( '$c_username', '$c_email', '$c_password', " . db_now() . "," . db_now() . ",
$c_enabled, $c_access_level, 0, '$t_cookie_string', '$c_realname')";
db_query( $query );
# Create preferences for the user
$t_user_id = db_insert_id( $t_user_table );
user_pref_set_default( $t_user_id );
# Users are added with protected set to FALSE in order to be able to update
# preferences. Now set the real value of protected.
if ( $c_protected ) {
user_set_field( $t_user_id, 'protected', 1 );
}
# Send notification email
if ( !is_blank( $p_email ) ) {
$t_confirm_hash = auth_generate_confirm_hash( $t_user_id );
email_signup( $t_user_id, $p_password, $t_confirm_hash );
}
return $t_cookie_string;
}
# --------------------
# Signup a user.
# If the use_ldap_email config option is on then tries to find email using
# ldap. $p_email may be empty, but the user wont get any emails.
# returns false if error, the generated cookie string if ok
function user_signup( $p_username, $p_email=null ) {
if ( null === $p_email ) {
$p_email = '';
# @@@ I think the ldap_email stuff is a bit borked
# Where is it being set? When is it being used?
# Shouldn't we override an email that is passed in here?
# If the user doesn't exist in ldap, is the account created?
# If so, there password won't get set anywhere... (etc)
# RJF: I was going to check for the existence of an LDAP email.
# however, since we can't create an LDAP account at the moment,
# and we don't know the user password in advance, we may not be able
# to retrieve it anyway.
# I'll re-enable this once a plan has been properly formulated for LDAP
# account management and creation.
/* $t_email = '';
if ( ON == config_get( 'use_ldap_email' ) ) {
$t_email = ldap_email_from_username( $p_username );
}
if ( !is_blank( $t_email ) ) {
$p_email = $t_email;
}
*/
}
$p_email = trim( $p_email );
$t_seed = $p_email . $p_username;
# Create random password
$t_password = auth_generate_random_password( $t_seed );
return user_create( $p_username, $t_password, $p_email );
}
# --------------------
# delete project-specific user access levels.
# returns true when successfully deleted
function user_delete_project_specific_access_levels( $p_user_id ) {
$c_user_id = db_prepare_int($p_user_id);
user_ensure_unprotected( $p_user_id );
$t_project_user_list_table = config_get('mantis_project_user_list_table');
$query = "DELETE FROM $t_project_user_list_table
WHERE user_id='$c_user_id'";
db_query( $query );
user_clear_cache( $p_user_id );
return true;
}
# --------------------
# delete profiles for the specified user
# returns true when successfully deleted
function user_delete_profiles( $p_user_id ) {
$c_user_id = db_prepare_int($p_user_id);
user_ensure_unprotected( $p_user_id );
$t_user_profile_table = config_get('mantis_user_profile_table');
# Remove associated profiles
$query = "DELETE FROM $t_user_profile_table
WHERE user_id='$c_user_id'";
db_query( $query );
user_clear_cache( $p_user_id );
return true;
}
# --------------------
# delete a user account (account, profiles, preferences, project-specific access levels)
# returns true when the account was successfully deleted
function user_delete( $p_user_id ) {
$c_user_id = db_prepare_int($p_user_id);
$t_user_table = config_get('mantis_user_table');
user_ensure_unprotected( $p_user_id );
# Remove associated profiles
user_delete_profiles( $p_user_id );
# Remove associated preferences
user_pref_delete_all( $p_user_id );
# Remove project specific access levels
user_delete_project_specific_access_levels( $p_user_id );
#unset non-unique realname flags if necessary
if ( config_get( 'differentiate_duplicates' ) ) {
$c_realname = db_prepare_string( user_get_field( $p_user_id, 'realname' ) );
$query = "SELECT id
FROM $t_user_table
WHERE realname='$c_realname'";
$result = db_query( $query );
$t_count = db_num_rows( $result );
if ( $t_count == 2 ) {
# unset flags if there are now only 2 unique names
for ( $i=0 ; $i < $t_count ; $i++ ) {
$t_user_id = db_result( $result, $i );
user_set_field( $t_user_id, 'duplicate_realname', OFF );
}
}
}
user_clear_cache( $p_user_id );
# Remove account
$query = "DELETE FROM $t_user_table
WHERE id='$c_user_id'";
db_query( $query );
return true;
}
#===================================
# Data Access
#===================================
# --------------------
# get a user id from a username
# return false if the username does not exist
function user_get_id_by_name( $p_username ) {
$c_username = db_prepare_string( $p_username );
$t_user_table = config_get( 'mantis_user_table' );
$query = "SELECT id
FROM $t_user_table
WHERE username='$c_username'";
$result = db_query( $query );
if ( 0 == db_num_rows( $result ) ) {
return false;
} else {
return db_result( $result );
}
}
# --------------------
# return all data associated with a particular user name
# return false if the username does not exist
function user_get_row_by_name( $p_username ) {
$t_user_id = user_get_id_by_name( $p_username );
if ( false === $t_user_id ) {
return false;
}
$row = user_get_row( $t_user_id );
return $row;
}
# --------------------
# return a user row
function user_get_row( $p_user_id ) {
return user_cache_row( $p_user_id );
}
# --------------------
# return the specified user field for the user id
function user_get_field( $p_user_id, $p_field_name ) {
if ( NO_USER == $p_user_id ) {
trigger_error( 'user_get_field() for NO_USER', WARNING );
return "@null@";
}
$row = user_get_row( $p_user_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 '';
}
}
# --------------------
# lookup the user's email in LDAP or the db as appropriate
function user_get_email( $p_user_id ) {
$t_email = '';
if ( ON == config_get( 'use_ldap_email' ) ) {
$t_email = ldap_email( $p_user_id );
}
if ( is_blank( $t_email ) ) {
$t_email = user_get_field( $p_user_id, 'email' );
}
return $t_email;
}
# --------------------
# lookup the user's realname
function user_get_realname( $p_user_id ) {
$t_realname = user_get_field( $p_user_id, 'realname' );
return $t_realname;
}
# --------------------
# return the username or a string "user<id>" if the user does not exist
# if show_realname is set, replace the name with a realname (if set)
function user_get_name( $p_user_id ) {
$row = user_cache_row( $p_user_id, false );
if ( false == $row ) {
return lang_get( 'prefix_for_deleted_users' ) . (int)$p_user_id;
} else {
if ( ON == config_get( 'show_realname' ) ) {
if ( is_blank( $row['realname'] ) ) {
return $row['username'];
} else {
if ( isset( $row['duplicate_realname'] ) && ( ON == $row['duplicate_realname'] ) ) {
return $row['realname'] . ' (' . $row['username'] . ')';
} else {
return $row['realname'];
}
}
} else {
return $row['username'];
}
}
}
# --------------------
# return the user's access level
# account for private project and the project user lists
function user_get_access_level( $p_user_id, $p_project_id = ALL_PROJECTS ) {
$t_access_level = user_get_field( $p_user_id, 'access_level' );
if ( $t_access_level >= ADMINISTRATOR ) {
return $t_access_level;
}
$t_project_access_level = project_get_local_user_access_level( $p_project_id, $p_user_id );
if ( false === $t_project_access_level ) {
return $t_access_level;
} else {
return $t_project_access_level;
}
}
$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, $p_show_disabled = false ) {
global $g_user_accessible_projects_cache;
if ( null !== $g_user_accessible_projects_cache
&& auth_get_current_user_id() == $p_user_id
&& false == $p_show_disabled ) {
return $g_user_accessible_projects_cache;
}
//--(kivio.wanderley 31.01.2011)
// if ( access_has_global_level( config_get( 'private_project_threshold' ), $p_user_id ) ) {
$t_projects = project_hierarchy_get_subprojects( ALL_PROJECTS, $p_show_disabled );
// } else {
// $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;
// $t_enabled_clause = $p_show_disabled ? '' : 'p.enabled = 1 AND';
//
// $query = "SELECT p.id, p.name, ph.parent_id
// FROM $t_project_table p
// LEFT JOIN $t_project_user_list_table u
// ON p.id=u.project_id AND u.user_id=$c_user_id
// LEFT JOIN $t_project_hierarchy_table ph
// ON ph.child_id = p.id
// WHERE $t_enabled_clause
// ( 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 );
//
// $t_projects[ $row['id'] ] = ( $row['parent_id'] === NULL ) ? 0 : $row['parent_id'];
// }
//
// # prune out children where the parents are already listed. Make the list
// # first, then prune to avoid pruning a parent before the child is found.
// $t_prune = array();
// foreach ( $t_projects as $t_id => $t_parent ) {
// if ( ( $t_parent !== 0 ) && isset( $t_projects[$t_parent] ) ) {
// $t_prune[] = $t_id;
// }
// }
// foreach ( $t_prune as $t_id ) {
// unset( $t_projects[$t_id] );
// }
// $t_projects = array_keys( $t_projects );
// }
//--
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, $p_show_disabled = false ) {
global $g_user_accessible_subprojects_cache;
if ( null !== $g_user_accessible_subprojects_cache
&& auth_get_current_user_id() == $p_user_id
&& false == $p_show_disabled ) {
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_enabled_clause = $p_show_disabled ? '' : 'p.enabled = 1 AND';
$t_public = VS_PUBLIC;
$t_private = VS_PRIVATE;
//--(kivio.wanderley 31.01.2011)
// if ( access_has_global_level( config_get( 'private_project_threshold' ), $p_user_id ) || access_has_any_project(MANAGER, $p_user_id ) ) {
$query = "SELECT DISTINCT p.id, p.name, ph.parent_id
FROM $t_project_table p
LEFT JOIN $t_project_hierarchy_table ph
ON ph.child_id = p.id
WHERE $t_enabled_clause
ph.parent_id IS NOT NULL
ORDER BY p.name";
// } else {
// $query = "SELECT DISTINCT p.id, p.name, ph.parent_id
// FROM $t_project_table p
// LEFT JOIN $t_project_user_list_table u
// ON p.id = u.project_id AND u.user_id='$c_user_id'
// LEFT JOIN $t_project_hierarchy_table ph
// ON ph.child_id = p.id
// WHERE $t_enabled_clause
// 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;
}
if ( !isset( $t_projects[ $p_project_id ] ) ) {
$t_projects[ $p_project_id ] = array();
}
return $t_projects[ $p_project_id ];
}
/* Fim da customiza��o 07/10/2010
*/
# --------------------
function user_get_all_accessible_subprojects( $p_user_id, $p_project_id ) {
# @@@ (thraxisp) Should all top level projects be a sub-project of ALL_PROJECTS implicitly?
# affects how news and some summaries are generated
$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 ) {
$c_user_id = db_prepare_int($p_user_id);
$c_project_id = db_prepare_int($p_project_id);
$t_bug_table = config_get('mantis_bug_table');
$t_where_prj = helper_project_specific_where( $p_project_id, $p_user_id ) . " AND";
$t_resolved = config_get('bug_resolved_status_threshold');
$query = "SELECT COUNT(*)
FROM $t_bug_table
WHERE $t_where_prj
status<'$t_resolved' AND
handler_id='$c_user_id'";
$result = db_query( $query );
return db_result( $result );
}
# --------------------
# return the number of open reported bugs by a user in a project
function user_get_reported_open_bug_count( $p_user_id, $p_project_id=ALL_PROJECTS ) {
$c_user_id = db_prepare_int($p_user_id);
$c_project_id = db_prepare_int($p_project_id);
$t_bug_table = config_get('mantis_bug_table');
$t_where_prj = helper_project_specific_where( $p_project_id, $p_user_id ) . " AND";
$t_resolved = config_get('bug_resolved_status_threshold');
$query = "SELECT COUNT(*)
FROM $t_bug_table
WHERE $t_where_prj
status<'$t_resolved' AND
reporter_id='$c_user_id'";
$result = db_query( $query );
return db_result( $result );
}
# --------------------
# return a profile row
function user_get_profile_row( $p_user_id, $p_profile_id ) {
$c_user_id = db_prepare_int( $p_user_id );
$c_profile_id = db_prepare_int( $p_profile_id );
$t_user_profile_table = config_get( 'mantis_user_profile_table' );
$query = "SELECT *
FROM $t_user_profile_table
WHERE id='$c_profile_id' AND
user_id='$c_user_id'";
$result = db_query( $query );
if ( 0 == db_num_rows( $result ) ) {
trigger_error( ERROR_USER_PROFILE_NOT_FOUND, ERROR );
}
$row = db_fetch_array( $result );
return $row;
}
# --------------------
# Get failed login attempts
function user_is_login_request_allowed( $p_user_id ) {
$t_max_failed_login_count = config_get( 'max_failed_login_count' );
$t_failed_login_count = user_get_field( $p_user_id, 'failed_login_count' );
return ( $t_failed_login_count < $t_max_failed_login_count
|| OFF == $t_max_failed_login_count);
}
# --------------------
# Get 'lost password' in progress attempts
function user_is_lost_password_request_allowed( $p_user_id ) {
if( OFF == config_get( 'lost_password_feature' ) ) {
return false;
}
$t_max_lost_password_in_progress_count = config_get( 'max_lost_password_in_progress_count' );
$t_lost_password_in_progress_count = user_get_field( $p_user_id, 'lost_password_request_count' );
return ( $t_lost_password_in_progress_count < $t_max_lost_password_in_progress_count
|| OFF == $t_max_lost_password_in_progress_count );
}
# --------------------
# return the bug filter parameters for the specified user
function user_get_bug_filter( $p_user_id, $p_project_id = null ) {
if ( null === $p_project_id ) {
$t_project_id = helper_get_current_project();
} else {
$t_project_id = $p_project_id;
}
$t_view_all_cookie_id = filter_db_get_project_current( $t_project_id, $p_user_id );
$t_view_all_cookie = filter_db_get_filter( $t_view_all_cookie_id, $p_user_id );
$t_cookie_detail = explode( '#', $t_view_all_cookie, 2 );
if ( !isset( $t_cookie_detail[1] ) ) {
return false;
}
$t_filter = unserialize( $t_cookie_detail[1] );
$t_filter = filter_ensure_valid_filter( $t_filter );
return $t_filter;
}
#===================================
# Data Modification
#===================================
# --------------------
# Update the last_visited field to be now
function user_update_last_visit( $p_user_id ) {
$c_user_id = db_prepare_int( $p_user_id );
$t_user_table = config_get( 'mantis_user_table' );
$query = "UPDATE $t_user_table
SET last_visit= " . db_now() . "
WHERE id='$c_user_id'";
db_query( $query );
user_clear_cache( $p_user_id );
# db_query() errors on failure so:
return true;
}
# --------------------
# Increment the number of times the user has logegd in
# This function is only called from the login.php script
function user_increment_login_count( $p_user_id ) {
$c_user_id = db_prepare_int( $p_user_id );
$t_user_table = config_get( 'mantis_user_table' );
$query = "UPDATE $t_user_table
SET login_count=login_count+1
WHERE id='$c_user_id'";
db_query( $query );
user_clear_cache( $p_user_id );
#db_query() errors on failure so:
return true;
}
# --------------------
# Reset to zero the failed login attempts
function user_reset_failed_login_count_to_zero( $p_user_id ) {
$c_user_id = db_prepare_int( $p_user_id );
$t_user_table = config_get( 'mantis_user_table' );
$query = "UPDATE $t_user_table
SET failed_login_count=0
WHERE id='$c_user_id'";
db_query( $query );
user_clear_cache( $p_user_id );
return true;
}
# --------------------
# Increment the failed login count by 1
function user_increment_failed_login_count( $p_user_id ) {
$c_user_id = db_prepare_int( $p_user_id );
$t_user_table = config_get( 'mantis_user_table' );
$query = "UPDATE $t_user_table
SET failed_login_count=failed_login_count+1
WHERE id='$c_user_id'";
db_query( $query );
user_clear_cache( $p_user_id );
return true;
}
# --------------------
# Reset to zero the 'lost password' in progress attempts
function user_reset_lost_password_in_progress_count_to_zero( $p_user_id ) {
$c_user_id = db_prepare_int( $p_user_id );
$t_user_table = config_get( 'mantis_user_table' );
$query = "UPDATE $t_user_table
SET lost_password_request_count=0
WHERE id='$c_user_id'";
db_query( $query );
user_clear_cache( $p_user_id );
return true;
}
# --------------------
# Increment the failed login count by 1
function user_increment_lost_password_in_progress_count( $p_user_id ) {
$c_user_id = db_prepare_int( $p_user_id );
$t_user_table = config_get( 'mantis_user_table' );
$query = "UPDATE $t_user_table
SET lost_password_request_count=lost_password_request_count+1
WHERE id='$c_user_id'";
db_query( $query );
user_clear_cache( $p_user_id );
return true;
}
# --------------------
# Set a user field
function user_set_field( $p_user_id, $p_field_name, $p_field_value ) {
$c_user_id = db_prepare_int( $p_user_id );
$c_field_name = db_prepare_string( $p_field_name );
$c_field_value = db_prepare_string( $p_field_value );
if ( $p_field_name != "protected" ) {
user_ensure_unprotected( $p_user_id );
}
$t_user_table = config_get( 'mantis_user_table' );
$query = "UPDATE $t_user_table
SET $c_field_name='$c_field_value'
WHERE id='$c_user_id'";
db_query( $query );
user_clear_cache( $p_user_id );
#db_query() errors on failure so:
return true;
}
# --------------------
# Set the user's default project
function user_set_default_project( $p_user_id, $p_project_id ) {
return user_pref_set_pref( $p_user_id, 'default_project', (int)$p_project_id );
}
# --------------------
# Set the user's password to the given string, encoded as appropriate
function user_set_password( $p_user_id, $p_password, $p_allow_protected=false ) {
$c_user_id = db_prepare_int( $p_user_id );
if ( !$p_allow_protected ) {
user_ensure_unprotected( $p_user_id );
}
$t_password = auth_process_plain_password( $p_password );
$t_user_table = config_get( 'mantis_user_table' );
$query = "UPDATE $t_user_table
SET password='$t_password'
WHERE id='$c_user_id'";
db_query( $query );
#db_query() errors on failure so:
return true;
}
# --------------------
# Set the user's email to the given string after checking that it is a valid email
function user_set_email( $p_user_id, $p_email ) {
email_ensure_valid( $p_email );
return user_set_field( $p_user_id, 'email', $p_email );
}
# --------------------
# Set the user's realname to the given string after checking validity
function user_set_realname( $p_user_id, $p_realname ) {
# @@@ TODO: ensure_realname_valid( $p_realname );
return user_set_field( $p_user_id, 'realname', $p_realname );
}
# --------------------
# Set the user's username to the given string after checking that it is valid
function user_set_name( $p_user_id, $p_username ) {
user_ensure_name_valid( $p_username );
user_ensure_name_unique( $p_username );
return user_set_field( $p_user_id, 'username', $p_username );
}
# --------------------
# Reset the user's password
# Take into account the 'send_reset_password' setting
# - if it is ON, generate a random password and send an email
# (unless the second parameter is false)
# - if it is OFF, set the password to blank
# Return false if the user is protected, true if the password was
# successfully reset
function user_reset_password( $p_user_id, $p_send_email=true ) {
$t_protected = user_get_field( $p_user_id, 'protected' );
# Go with random password and email it to the user
if ( ON == $t_protected ) {
return false;
}
# @@@ do we want to force blank password instead of random if
# email notifications are turned off?
# How would we indicate that we had done this with a return value?
# Should we just have two functions? (user_reset_password_random()
# and user_reset_password() )?
if ( ( ON == config_get( 'send_reset_password' ) ) && ( ON == config_get( 'enable_email_notification' ) ) ) {
# Create random password
$t_email = user_get_field( $p_user_id, 'email' );
$t_password = auth_generate_random_password( $t_email );
$t_password2 = auth_process_plain_password( $t_password );
user_set_field( $p_user_id, 'password', $t_password2 );
# Send notification email
if ( $p_send_email ) {
$t_confirm_hash = auth_generate_confirm_hash( $p_user_id );
email_send_confirm_hash_url( $p_user_id, $t_confirm_hash );
}
} else {
# use blank password, no emailing
$t_password = auth_process_plain_password( '' );
user_set_field( $p_user_id, 'password', $t_password );
# reset the failed login count because in this mode there is no emailing
user_reset_failed_login_count_to_zero( $p_user_id );
}
return true;
}
?> | ||||
| duplicate of | 0009586 | new | Impossible to differentiate between two sub projects of different project |
|
On attached files there is the "print_api.php". So im using version 1.0.6 but this problem is still on 1.2.3. Replace the functions "print_project_option_list" and "print_subproject_option_list" on this file for the same file on your version. And add on this file the function "check_selected2". And there is the "user_api.php" file with some commented lines. Hope this helps anyone. |
|
related to
child of
duplicate of