// Watergad: multiproject instance addition # check to see if project exists by name function project_is_name_unique_h( $p_name, $parent_id ) { $t_project_table = db_get_table( 'mantis_project_table' ); $t_mantis_project_hierarchy_table = db_get_table( 'mantis_project_hierarchy_table' ); $query = "SELECT COUNT(*) FROM $t_project_table p LEFT JOIN $t_mantis_project_hierarchy_table h ON p.id=h.child_id WHERE name=" . db_param() . " AND (h.parent_id = " . db_param() . " OR (h.parent_id IS NULL AND null IS NULL))"; // $result = db_query_bound( $query, Array( $p_name ) ); $result = db_query_bound( $query, Array( $p_name, $parent_id ) ); if( 0 == db_result( $result ) ) { return true; } else { return false; } } // Watergad: multiproject instance addition # check to see if project exists by id # if it doesn't exist then error # otherwise let execution continue undisturbed function project_ensure_name_unique_h( $p_name, $parent_id ) { if( !project_is_name_unique_h( $p_name, $parent_id ) ) { trigger_error( ERROR_PROJECT_NAME_NOT_UNIQUE, ERROR ); } } // Watergad: multiproject instance addition # Create a new project function project_create_h( $p_name, $parent_id, $p_description, $p_status, $p_view_state = VS_PUBLIC, $p_file_path = '', $p_enabled = true, $p_inherit_global = true ) { // Watergad: parent_id set with nvl of '0' so returning it to the null value if necessary. Stupid hard-coded tweak. if( $parent_id == 0 ) $parent_id = null; $c_enabled = db_prepare_bool( $p_enabled ); $c_inherit_global = db_prepare_bool( $p_inherit_global ); if( is_blank( $p_name ) ) { trigger_error( ERROR_PROJECT_NAME_INVALID, ERROR ); } // project_ensure_name_unique( $p_name ); // Watergad: we use our multiproject analog here project_ensure_name_unique_h( $p_name, $parent_id ); if( !is_blank( $p_file_path ) ) { # Make sure file path has trailing slash $p_file_path = terminate_directory_path( $p_file_path ); file_ensure_valid_upload_path( $p_file_path ); } $t_project_table = db_get_table( 'mantis_project_table' ); $query = "INSERT INTO $t_project_table ( name, status, enabled, view_state, file_path, description, inherit_global ) VALUES ( " . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ')'; db_query_bound( $query, Array( $p_name, (int) $p_status, $c_enabled, (int) $p_view_state, $p_file_path, $p_description, $c_inherit_global ) ); # return the id of the new project return db_insert_id( $t_project_table ); }