Jump to content

Weird problem with PHP


JR10

Recommended Posts

I'm facing a weird problem,

I included 2 files, the mta_sdk.php and another one,

When I use mta::doReturn it doesn't work, and the script returns nil,

But if I remove the second include, not mta_sdk.php, it works.

I did try something else like executing a function defined in the included php, and it worked,

So the problem is not in the included php itself.

Doesn't work:

<?php 
  
    include "../mta_sdk/mta_sdk.php" ; 
    include "../file/test.php" ; 
     
    mta::doReturn ( "true" ); 
     
?> 

Works:

<?php 
  
    include "../mta_sdk/mta_sdk.php" ; 
     
    mta::doReturn ( "true" ); 
     
?> 

Link to comment

Yes, didn't work.

It's weird, when I use mta::doReturn before including, it works.

Doesn't work:

<?php 
  
    include "../mta_sdk/mta_sdk.php" ; 
    include "../file/test.php" ; 
    
    mta::doReturn ( "true" ); 
    
?> 

Works:

<?php 
  
    include "../mta_sdk/mta_sdk.php" ; 
    mta::doReturn ( "true" ); 
    include "../file/test.php" ; 
    
?> 

Link to comment

Sorry for double posting.

I tried changing the included file, and it worked.

So the problem is in the included file.

Here it is:

<?php 
# MantisConnect - A webservice interface to Mantis Bug Tracker
# Copyright (C) 2004-2011  Victor Boctor - [email protected]
# This program is distributed under dual licensing.  These include
# GPL and a commercial licenses.  Victor Boctor reserves the right to
# change the license of future releases.
# See docs/ folder for more details
 
# set up error_handler() as the new default error handling function
set_error_handler( 'mc_error_handler' );
 
# override some MantisBT configurations
$g_show_detailed_errors = OFF;
$g_stop_on_errors = ON;
$g_display_errors = array(
    E_WARNING => 'halt',
    E_NOTICE => 'halt',
    E_USER_ERROR => 'halt',
    E_USER_WARNING => 'halt',
    E_USER_NOTICE => 'halt',
);
 
/**
 * Get the MantisConnect webservice version.
 */
function mc_version() {
    return MANTIS_VERSION;
}
 
# Checks if MantisBT installation is marked as offline by the administrator.
# true: offline, false: online
function mci_is_mantis_offline() {
    $t_offline_file = dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'mantis_offline.php';
    return file_exists( $t_offline_file );
}
 
# return user_id if successful, otherwise false.
function mci_check_login( $p_username, $p_password ) {
    if( mci_is_mantis_offline() ) {
        return false;
    }
 
    # if no user name supplied, then attempt to login as anonymous user.
    if( is_blank( $p_username ) ) {
        $t_anon_allowed = config_get( 'allow_anonymous_login' );
        if( OFF == $t_anon_allowed ) {
            return false;
        }
 
        $p_username = config_get( 'anonymous_account' );
 
        # do not use password validation.
        $p_password = null;
    }
 
    if( false === auth_attempt_script_login( $p_username, $p_password ) ) {
        return false;
    }
 
    return auth_get_current_user_id();
}
 
function mci_has_readonly_access( $p_user_id, $p_project_id = ALL_PROJECTS ) {
    $t_access_level = user_get_access_level( $p_user_id, $p_project_id );
    return( $t_access_level >= config_get( 'mc_readonly_access_level_threshold' ) );
}
 
function mci_has_readwrite_access( $p_user_id, $p_project_id = ALL_PROJECTS ) {
    $t_access_level = user_get_access_level( $p_user_id, $p_project_id );
    return( $t_access_level >= config_get( 'mc_readwrite_access_level_threshold' ) );
}
 
function mci_has_access( $p_access_level, $p_user_id, $p_project_id = ALL_PROJECTS ) {
    $t_access_level = user_get_access_level( $p_user_id, $p_project_id );
    return( $t_access_level >= (int) $p_access_level );
}
 
function mci_has_administrator_access( $p_user_id, $p_project_id = ALL_PROJECTS ) {
    $t_access_level = user_get_access_level( $p_user_id, $p_project_id );
    return( $t_access_level >= config_get( 'mc_admin_access_level_threshold' ) );
}
 
function mci_get_project_id( $p_project ) {
    if( (int) $p_project['id'] != 0 ) {
        $t_project_id = (int) $p_project['id'];
    } else {
        $t_project_id = project_get_id_by_name( $p_project['name'] );
    }
 
    return $t_project_id;
}
 
function mci_get_project_status_id( $p_status ) {
    return mci_get_enum_id_from_objectref( 'project_status', $p_status );
}
 
function mci_get_project_view_state_id( $p_view_state ) {
    return mci_get_enum_id_from_objectref( 'project_view_state', $p_view_state );
}
 
function mci_get_user_id( $p_user ) {
    $t_user_id = 0;
 
    if ( isset( $p_user['id'] ) && (int) $p_user['id'] != 0 ) {
        $t_user_id = (int) $p_user['id'];
    } elseif ( isset( $p_user['name'] ) ) {
        $t_user_id = user_get_id_by_name( $p_user['name'] );
    }
 
    return $t_user_id;
}
 
function mci_get_user_lang( $p_user_id ) {
    $t_lang = user_pref_get_pref( $p_user_id, 'language' );
    if( $t_lang == 'auto' ) {
        $t_lang = config_get( 'fallback_language' );
    }
    return $t_lang;
}
 
function mci_get_status_id( $p_status ) {
    return mci_get_enum_id_from_objectref( 'status', $p_status );
}
 
function mci_get_severity_id( $p_severity ) {
    return mci_get_enum_id_from_objectref( 'severity', $p_severity );
}
 
function mci_get_priority_id( $p_priority ) {
 
    return mci_get_enum_id_from_objectref( 'priority', $p_priority );
}
 
function mci_get_reproducibility_id( $p_reproducibility ) {
    return mci_get_enum_id_from_objectref( 'reproducibility', $p_reproducibility );
}
 
function mci_get_resolution_id( $p_resolution ) {
    return mci_get_enum_id_from_objectref( 'resolution', $p_resolution );
}
 
function mci_get_projection_id( $p_projection ) {
    return mci_get_enum_id_from_objectref( 'projection', $p_projection );
}
 
function mci_get_eta_id( $p_eta ) {
    return mci_get_enum_id_from_objectref( 'eta', $p_eta );
}
 
function mci_get_view_state_id( $p_view_state ) {
    return mci_get_enum_id_from_objectref( 'view_state', $p_view_state );
}
 
# Get null on empty value.
#
# @param Object $p_value  The value
# @return Object  The value if not empty; null otherwise.
#
function mci_null_if_empty( $p_value ) {
    if( !is_blank( $p_value ) ) {
        return $p_value;
    }
 
    return null;
}
 
/**
 * Gets the url for MantisBT.
 *
 * @return MantisBT URL terminated by a /.
 */
function mci_get_mantis_path() {
   
    return config_get( 'path' );
}
 
# Given a enum string and num, return the appropriate localized string
function mci_get_enum_element( $p_enum_name, $p_val, $p_lang ) {
    $t_enum_string = config_get( $p_enum_name . '_enum_string' );
    $t_localized_enum_string = lang_get( $p_enum_name . '_enum_string', $p_lang );
 
    return MantisEnum::getLocalizedLabel( $t_enum_string, $t_localized_enum_string, $p_val );
}
 
# Gets the sub-projects that are accessible to the specified user / project.
function mci_user_get_accessible_subprojects( $p_user_id, $p_parent_project_id, $p_lang = null ) {
    if( $p_lang === null ) {
        $t_lang = mci_get_user_lang( $p_user_id );
    } else {
        $t_lang = $p_lang;
    }
 
    $t_result = array();
    foreach( user_get_accessible_subprojects( $p_user_id, $p_parent_project_id ) as $t_subproject_id ) {
        $t_subproject_row = project_cache_row( $t_subproject_id );
        $t_subproject = array();
        $t_subproject['id'] = $t_subproject_id;
        $t_subproject['name'] = $t_subproject_row['name'];
        $t_subproject['status'] = mci_enum_get_array_by_id( $t_subproject_row['status'], 'project_status', $t_lang );
        $t_subproject['enabled'] = $t_subproject_row['enabled'];
        $t_subproject['view_state'] = mci_enum_get_array_by_id( $t_subproject_row['view_state'], 'project_view_state', $t_lang );
        $t_subproject['access_min'] = mci_enum_get_array_by_id( $t_subproject_row['access_min'], 'access_levels', $t_lang );
        $t_subproject['file_path'] = array_key_exists( 'file_path', $t_subproject_row ) ? $t_subproject_row['file_path'] : "";
        $t_subproject['description'] = array_key_exists( 'description', $t_subproject_row ) ? $t_subproject_row['description'] : "";
        $t_subproject['subprojects'] = mci_user_get_accessible_subprojects( $p_user_id, $t_subproject_id, $t_lang );
        $t_result[] = $t_subproject;
    }
 
    return $t_result;
}
 
function translate_category_name_to_id( $p_category_name, $p_project_id ) {
    if ( !isset( $p_category_name ) ) {
        return 0;
    }
 
    $t_cat_array = category_get_all_rows( $p_project_id );
    foreach( $t_cat_array as $t_category_row ) {
        if( $t_category_row['name'] == $p_category_name ) {
            return $t_category_row['id'];
        }
    }
    return 0;
}
 
/**
 * Basically this is a copy of core/filter_api.php#filter_db_get_available_queries().
 * The only difference is that the result of this function is not an array of filter
 * names but an array of filter structures.
 */
function mci_filter_db_get_available_queries( $p_project_id = null, $p_user_id = null ) {
    $t_filters_table = db_get_table( 'mantis_filters_table' );
    $t_overall_query_arr = array();
 
    if( null === $p_project_id ) {
        $t_project_id = helper_get_current_project();
    } else {
        $t_project_id = db_prepare_int( $p_project_id );
    }
 
    if( null === $p_user_id ) {
        $t_user_id = auth_get_current_user_id();
    } else {
        $t_user_id = db_prepare_int( $p_user_id );
    }
 
    # If the user doesn't have access rights to stored queries, just return
    if( !access_has_project_level( config_get( 'stored_query_use_threshold' ) ) ) {
        return $t_overall_query_arr;
    }
 
    # Get the list of available queries. By sorting such that public queries are
Link to comment

Well I tried out your PHP script on my server (just the "test.php"), and I get an error

Fatal error: Call to undefined function config_get() in /home/whocares/public_html/MTA/test.php on line 370

So it's either just me missing an include or whatever, or it's also on your side :D

As far as my PHP knowledge goes, I think this should work.

Link to comment

I've made a new PHP file called "test.php" and put just a mta::doReturn in there, and it worked, it returned what it was supposed to. Funny thing is, I have this same code in the non-working script (with all other stuff commented out), and it doesn't return anything from there. WTF?

Link to comment
  • 3 months later...
I'm facing a weird problem,

I included 2 files, the mta_sdk.php and another one,

When I use mta::doReturn it doesn't work, and the script returns nil,

But if I remove the second include, not mta_sdk.php, it works.

I did try something else like executing a function defined in the included php, and it worked,

So the problem is not in the included php itself.

Doesn't work:

<?php 
  
    include "../mta_sdk/mta_sdk.php" ; 
    include "../file/test.php" ; 
     
    mta::doReturn ( "true" ); 
     
?> 

Works:

<?php 
  
    include "../mta_sdk/mta_sdk.php" ; 
     
    mta::doReturn ( "true" ); 
     
?> 

Hi, i'm late? xD

JR10, use require function. It's the same thing than Include but it's better :D

When you include another code in the PHP file than the SDK, put the include line in last.

Like that:

<?php  
 require "../test.php"; 
 require "../mta_sdk.php"; 
  
 mta::doReturn(true); 
  
?> 

The true is the same true than on MTA, you don't must put it in string.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...