function display_bug_id($p_event, $p_text)
 {
     $p_bug_id = (int) $p_text;
     if (!bug_exists($p_bug_id)) {
         return $p_text;
     }
     $bug = bug_get($p_bug_id);
     $project = $bug->__get("project_id");
     if ($project != plugin_config_get('project_id')) {
         return $p_text;
     }
     $p_field_id = plugin_config_get('field_id');
     $prefix = plugin_config_get('prefix');
     $has_parent = false;
     $t_bugs_ids = relationship_get_all_src($p_bug_id);
     foreach ($t_bugs_ids as $t_relaship) {
         if ($t_relaship->type == BUG_BLOCKS) {
             $has_parent = true;
             break;
         }
     }
     $t_bugs_ids = relationship_get_all_dest($p_bug_id);
     foreach ($t_bugs_ids as $t_relaship) {
         if ($t_relaship->type == BUG_DEPENDANT) {
             $has_parent = true;
             break;
         }
     }
     $prefix_two = plugin_config_get('prefix_two');
     if ($has_parent) {
         $prefix = $prefix_two;
     }
     $p_def = custom_field_get_definition($p_field_id);
     $t_custom_field_value = custom_field_get_value($p_field_id, $p_bug_id);
     global $g_custom_field_type_definition;
     if (isset($g_custom_field_type_definition[$p_def['type']]['#function_string_value'])) {
         return $prefix . call_user_func($g_custom_field_type_definition[$p_def['type']]['#function_string_value'], $t_custom_field_value);
     }
     return $prefix . $t_custom_field_value;
 }
Exemple #2
0
/**
 * Return a single database field from a custom field definition row for the field
 * if the database field does not exist, display a warning and return ''
 * @param integer $p_field_id   Custom field identifier.
 * @param integer $p_field_name Custom field name.
 * @return string
 * @access public
 */
function custom_field_get_field($p_field_id, $p_field_name)
{
    $t_row = custom_field_get_definition($p_field_id);
    if (isset($t_row[$p_field_name])) {
        return $t_row[$p_field_name];
    } else {
        error_parameters($p_field_name);
        trigger_error(ERROR_DB_FIELD_NOT_FOUND, WARNING);
        return '';
    }
}
Exemple #3
0
/**
 * Gets the formatted value for the specified issue id, project and custom field.
 * @param $p_issue_id The issue id.
 * @param $p_project_id The project id.
 * @param $p_custom_field The custom field name (without 'custom_' prefix).
 * @returns The custom field value.
 */
function excel_format_custom_field($p_issue_id, $p_project_id, $p_custom_field)
{
    $t_field_id = custom_field_get_id_from_name($p_custom_field);
    if ($t_field_id === false) {
        return excel_prepare_string('@' . $p_custom_field . '@');
    }
    if (custom_field_is_linked($t_field_id, $p_project_id)) {
        $t_def = custom_field_get_definition($t_field_id);
        return excel_prepare_string(string_custom_field_value($t_def, $t_field_id, $p_issue_id));
    }
    // field is not linked to project
    return excel_prepare_string('');
}
/**
 * Allows the validation of a custom field value without setting it
 * or needing a bug to exist.
 * @param integer $p_field_id Custom field identifier.
 * @param string  $p_value    Custom field value.
 * @return boolean
 * @access public
 */
function custom_field_validate($p_field_id, $p_value)
{
    $t_row = custom_field_get_definition($p_field_id);
    $t_name = $t_row['name'];
    $t_type = $t_row['type'];
    $t_possible_values = $t_row['possible_values'];
    $t_valid_regexp = $t_row['valid_regexp'];
    $t_length_min = $t_row['length_min'];
    $t_length_max = $t_row['length_max'];
    $t_default_value = $t_row['default_value'];
    $t_valid = true;
    $t_length = utf8_strlen($p_value);
    switch ($t_type) {
        case CUSTOM_FIELD_TYPE_STRING:
        case CUSTOM_FIELD_TYPE_TEXTAREA:
            # Empty fields are valid
            if ($t_length == 0) {
                break;
            }
            # Regular expression string validation
            if (!is_blank($t_valid_regexp)) {
                $t_valid &= preg_match('/' . $t_valid_regexp . '/', $p_value);
            }
            # Check the length of the string
            $t_valid &= 0 == $t_length_min || $t_length >= $t_length_min;
            $t_valid &= 0 == $t_length_max || $t_length <= $t_length_max;
            break;
        case CUSTOM_FIELD_TYPE_NUMERIC:
            # Empty fields are valid
            if ($t_length == 0) {
                break;
            }
            $t_valid &= is_numeric($p_value);
            # Check the length of the number
            $t_valid &= 0 == $t_length_min || $t_length >= $t_length_min;
            $t_valid &= 0 == $t_length_max || $t_length <= $t_length_max;
            break;
        case CUSTOM_FIELD_TYPE_FLOAT:
            # Empty fields are valid
            if ($t_length == 0) {
                break;
            }
            # Allow both integer and float numbers
            $t_valid &= is_numeric($p_value) || is_float($p_value);
            # Check the length of the number
            $t_valid &= 0 == $t_length_min || $t_length >= $t_length_min;
            $t_valid &= 0 == $t_length_max || $t_length <= $t_length_max;
            break;
        case CUSTOM_FIELD_TYPE_DATE:
            # gpc_get_cf for date returns the value from strtotime
            # For 32 bit systems, supported range will be 13 Dec 1901 20:45:54 UTC to 19 Jan 2038 03:14:07 UTC
            $t_valid &= $p_value !== false;
            break;
        case CUSTOM_FIELD_TYPE_CHECKBOX:
        case CUSTOM_FIELD_TYPE_MULTILIST:
            # Checkbox fields can hold a null value (when no checkboxes are ticked)
            if ($p_value === '') {
                break;
            }
            # If checkbox field value is not null then we need to validate it
            $t_values = explode('|', $p_value);
            $t_possible_values = custom_field_prepare_possible_values($t_row['possible_values']);
            $t_possible_values = explode('|', $t_possible_values);
            $t_invalid_values = array_diff($t_values, $t_possible_values);
            $t_valid &= count($t_invalid_values) == 0;
            break;
        case CUSTOM_FIELD_TYPE_ENUM:
        case CUSTOM_FIELD_TYPE_LIST:
        case CUSTOM_FIELD_TYPE_RADIO:
            # List fields can be empty (when they are not shown on the
            # form, or shown with no default values and never clicked)
            if (is_blank($p_value)) {
                break;
            }
            # If list field value is not empty then we need to validate it
            $t_possible_values = custom_field_prepare_possible_values($t_row['possible_values']);
            $t_values_arr = explode('|', $t_possible_values);
            $t_valid &= in_array($p_value, $t_values_arr);
            break;
        case CUSTOM_FIELD_TYPE_EMAIL:
            if ($p_value !== '') {
                $t_valid &= email_is_valid($p_value);
            }
            break;
        default:
            break;
    }
    return (bool) $t_valid;
}
			<th class="category"><?php 
echo lang_get('custom_field_type');
?>
</th>
			<th class="category"><?php 
echo lang_get('custom_field_possible_values');
?>
</th>
			<th class="category"><?php 
echo lang_get('custom_field_default_value');
?>
</th>
		</tr><?php 
$t_custom_fields = custom_field_get_ids();
foreach ($t_custom_fields as $t_field_id) {
    $t_desc = custom_field_get_definition($t_field_id);
    ?>
		<tr>
			<td>
				<a href="manage_custom_field_edit_page.php?field_id=<?php 
    echo $t_field_id;
    ?>
"><?php 
    echo custom_field_get_display_name($t_desc['name']);
    ?>
</a>
			</td>
			<td><?php 
    echo count(custom_field_get_project_ids($t_field_id));
    ?>
</td>
Exemple #6
0
/**
 * Get set of bug rows from given filter
 * @todo Had to make all these parameters required because we can't use call-time pass by reference anymore.
 * I really preferred not having to pass all the params in if you didn't want to, but I wanted to get
 * rid of the errors for now.  If we can think of a better way later (maybe return an object) that would be great.
 *
 * @param integer &$p_page_number  Page number of the page you want to see (set to the actual page on return).
 * @param integer &$p_per_page     The number of bugs to see per page (set to actual on return)
 *                                 -1   indicates you want to see all bugs
 *                                 null indicates you want to use the value specified in the filter.
 * @param integer &$p_page_count   You don't need to give a value here, the number of pages will be stored here on return.
 * @param integer &$p_bug_count    You don't need to give a value here, the number of bugs will be stored here on return.
 * @param mixed   $p_custom_filter Custom Filter to use.
 * @param integer $p_project_id    Project id to use in filtering.
 * @param integer $p_user_id       User id to use as current user when filtering.
 * @param boolean $p_show_sticky   True/false - get sticky issues only.
 * @return boolean|array
 */
function filter_get_bug_rows(&$p_page_number, &$p_per_page, &$p_page_count, &$p_bug_count, $p_custom_filter = null, $p_project_id = null, $p_user_id = null, $p_show_sticky = null)
{
    log_event(LOG_FILTERING, 'START NEW FILTER QUERY');
    $t_limit_reporters = config_get('limit_reporters');
    $t_report_bug_threshold = config_get('report_bug_threshold');
    $t_where_param_count = 0;
    $t_current_user_id = auth_get_current_user_id();
    if ($p_user_id === null || $p_user_id === 0) {
        $t_user_id = $t_current_user_id;
    } else {
        $t_user_id = $p_user_id;
    }
    $c_user_id = (int) $t_user_id;
    if (null === $p_project_id) {
        # @@@ If project_id is not specified, then use the project id(s) in the filter if set, otherwise, use current project.
        $t_project_id = helper_get_current_project();
    } else {
        $t_project_id = $p_project_id;
    }
    if ($p_custom_filter === null) {
        # Prefer current_user_get_bug_filter() over user_get_filter() when applicable since it supports
        # cookies set by previous version of the code.
        if ($t_user_id == $t_current_user_id) {
            $t_filter = current_user_get_bug_filter();
        } else {
            $t_filter = user_get_bug_filter($t_user_id, $t_project_id);
        }
    } else {
        $t_filter = $p_custom_filter;
    }
    # if filter isn't return above, create a new filter from an empty array.
    if (false === $t_filter) {
        $t_filter = array();
    }
    $t_filter = filter_ensure_valid_filter($t_filter);
    $t_view_type = $t_filter['_view_type'];
    # project query clauses must be AND-ed always, irrespective of how the filter
    # clauses are requested by the user ( all matching -> AND, any matching -> OR )
    $t_where_clauses = array();
    $t_project_where_clauses = array('{project}.enabled = ' . db_param());
    $t_where_params = array(1);
    $t_select_clauses = array('{bug}.*');
    $t_from_clauses = array('{bug}');
    $t_join_clauses = array(' JOIN {project} ON {project}.id = {bug}.project_id');
    # normalize the project filtering into an array $t_project_ids
    if ('simple' == $t_view_type) {
        log_event(LOG_FILTERING, 'Simple Filter');
        $t_project_ids = array($t_project_id);
        $t_include_sub_projects = true;
    } else {
        log_event(LOG_FILTERING, 'Advanced Filter');
        if (!is_array($t_filter[FILTER_PROPERTY_PROJECT_ID])) {
            $t_project_ids = array((int) $t_filter[FILTER_PROPERTY_PROJECT_ID]);
        } else {
            $t_project_ids = array_map('intval', $t_filter[FILTER_PROPERTY_PROJECT_ID]);
        }
        $t_include_sub_projects = count($t_project_ids) == 1 && ($t_project_ids[0] == META_FILTER_CURRENT || $t_project_ids[0] == ALL_PROJECTS);
    }
    log_event(LOG_FILTERING, 'project_ids = @P' . implode(', @P', $t_project_ids));
    log_event(LOG_FILTERING, 'include sub-projects = ' . ($t_include_sub_projects ? '1' : '0'));
    # if the array has ALL_PROJECTS, then reset the array to only contain ALL_PROJECTS.
    # replace META_FILTER_CURRENT with the actualy current project id.
    $t_all_projects_found = false;
    $t_new_project_ids = array();
    foreach ($t_project_ids as $t_pid) {
        if ($t_pid == META_FILTER_CURRENT) {
            $t_pid = $t_project_id;
        }
        if ($t_pid == ALL_PROJECTS) {
            $t_all_projects_found = true;
            log_event(LOG_FILTERING, 'all projects selected');
            break;
        }
        # filter out inaccessible projects.
        if (!project_exists($t_pid) || !access_has_project_level(config_get('view_bug_threshold', null, $t_user_id, $t_pid), $t_pid, $t_user_id)) {
            log_event(LOG_FILTERING, 'Invalid or inaccessible project: ' . $t_pid);
            continue;
        }
        $t_new_project_ids[] = $t_pid;
    }
    $t_projects_query_required = true;
    if ($t_all_projects_found) {
        if (user_is_administrator($t_user_id)) {
            log_event(LOG_FILTERING, 'all projects + administrator, hence no project filter.');
            $t_projects_query_required = false;
        } else {
            $t_project_ids = user_get_accessible_projects($t_user_id);
        }
    } else {
        $t_project_ids = $t_new_project_ids;
    }
    if ($t_projects_query_required) {
        # expand project ids to include sub-projects
        if ($t_include_sub_projects) {
            $t_top_project_ids = $t_project_ids;
            foreach ($t_top_project_ids as $t_pid) {
                log_event(LOG_FILTERING, 'Getting sub-projects for project id @P' . $t_pid);
                $t_subproject_ids = user_get_all_accessible_subprojects($t_user_id, $t_pid);
                if (!$t_subproject_ids) {
                    continue;
                }
                $t_project_ids = array_merge($t_project_ids, $t_subproject_ids);
            }
            $t_project_ids = array_unique($t_project_ids);
        }
        # if no projects are accessible, then return an empty array.
        if (count($t_project_ids) == 0) {
            log_event(LOG_FILTERING, 'no accessible projects');
            return array();
        }
        log_event(LOG_FILTERING, 'project_ids after including sub-projects = @P' . implode(', @P', $t_project_ids));
        # this array is to be populated with project ids for which we only want to show public issues.  This is due to the limited
        # access of the current user.
        $t_public_only_project_ids = array();
        # this array is populated with project ids that the current user has full access to.
        $t_private_and_public_project_ids = array();
        $t_limited_projects = array();
        foreach ($t_project_ids as $t_pid) {
            # limit reporters to visible projects
            if (ON === $t_limit_reporters && !access_has_project_level(config_get('report_bug_threshold', null, $t_user_id, $t_pid) + 1, $t_pid, $t_user_id)) {
                array_push($t_limited_projects, '({bug}.project_id=' . $t_pid . ' AND ({bug}.reporter_id=' . $t_user_id . ') )');
            } else {
                $t_access_required_to_view_private_bugs = config_get('private_bug_threshold', null, null, $t_pid);
                if (access_has_project_level($t_access_required_to_view_private_bugs, $t_pid, $t_user_id)) {
                    $t_private_and_public_project_ids[] = $t_pid;
                } else {
                    $t_public_only_project_ids[] = $t_pid;
                }
            }
        }
        log_event(LOG_FILTERING, 'project_ids (with public/private access) = @P' . implode(', @P', $t_private_and_public_project_ids));
        log_event(LOG_FILTERING, 'project_ids (with public access) = @P' . implode(', @P', $t_public_only_project_ids));
        $t_count_private_and_public_project_ids = count($t_private_and_public_project_ids);
        if ($t_count_private_and_public_project_ids == 1) {
            $t_private_and_public_query = '( {bug}.project_id = ' . $t_private_and_public_project_ids[0] . ' )';
        } else {
            if ($t_count_private_and_public_project_ids > 1) {
                $t_private_and_public_query = '( {bug}.project_id in (' . implode(', ', $t_private_and_public_project_ids) . ') )';
            } else {
                $t_private_and_public_query = null;
            }
        }
        $t_count_public_only_project_ids = count($t_public_only_project_ids);
        $t_public_view_state_check = '( ( {bug}.view_state = ' . VS_PUBLIC . ' ) OR ( {bug}.reporter_id = ' . $t_user_id . ') )';
        if ($t_count_public_only_project_ids == 1) {
            $t_public_only_query = '( ( {bug}.project_id = ' . $t_public_only_project_ids[0] . ' ) AND ' . $t_public_view_state_check . ')';
        } else {
            if ($t_count_public_only_project_ids > 1) {
                $t_public_only_query = '( ( {bug}.project_id in (' . implode(', ', $t_public_only_project_ids) . ') ) AND ' . $t_public_view_state_check . ')';
            } else {
                $t_public_only_query = null;
            }
        }
        # both queries can't be null, so we either have one of them or both.
        if ($t_private_and_public_query === null) {
            $t_project_query = $t_public_only_query;
        } else {
            if ($t_public_only_query === null) {
                $t_project_query = $t_private_and_public_query;
            } else {
                $t_project_query = '( ' . $t_public_only_query . ' OR ' . $t_private_and_public_query . ' )';
            }
        }
        if (!empty($t_limited_projects)) {
            foreach ($t_limited_projects as $t_string) {
                if ($t_project_query == "") {
                    $t_project_query = " ( {$t_string} ) ";
                } else {
                    $t_project_query = " ( {$t_project_query} OR ( {$t_string} ) )";
                }
            }
        }
        log_event(LOG_FILTERING, 'project query = ' . $t_project_query);
        array_push($t_project_where_clauses, $t_project_query);
    }
    # date filter
    if ('on' == $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] && is_numeric($t_filter[FILTER_PROPERTY_START_MONTH]) && is_numeric($t_filter[FILTER_PROPERTY_START_DAY]) && is_numeric($t_filter[FILTER_PROPERTY_START_YEAR]) && is_numeric($t_filter[FILTER_PROPERTY_END_MONTH]) && is_numeric($t_filter[FILTER_PROPERTY_END_DAY]) && is_numeric($t_filter[FILTER_PROPERTY_END_YEAR])) {
        $t_start_string = $t_filter[FILTER_PROPERTY_START_YEAR] . '-' . $t_filter[FILTER_PROPERTY_START_MONTH] . '-' . $t_filter[FILTER_PROPERTY_START_DAY] . ' 00:00:00';
        $t_end_string = $t_filter[FILTER_PROPERTY_END_YEAR] . '-' . $t_filter[FILTER_PROPERTY_END_MONTH] . '-' . $t_filter[FILTER_PROPERTY_END_DAY] . ' 23:59:59';
        $t_where_params[] = strtotime($t_start_string);
        $t_where_params[] = strtotime($t_end_string);
        array_push($t_project_where_clauses, '({bug}.date_submitted BETWEEN ' . db_param() . ' AND ' . db_param() . ' )');
    }
    # view state
    $t_view_state = (int) $t_filter[FILTER_PROPERTY_VIEW_STATE];
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_VIEW_STATE])) {
        $t_view_state_query = '({bug}.view_state=' . db_param() . ')';
        log_event(LOG_FILTERING, 'view_state query = ' . $t_view_state_query);
        $t_where_params[] = $t_view_state;
        array_push($t_where_clauses, $t_view_state_query);
    } else {
        log_event(LOG_FILTERING, 'no view_state query');
    }
    # reporter
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_REPORTER_ID])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_REPORTER_ID] as $t_filter_member) {
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, '0');
            } else {
                $c_reporter_id = (int) $t_filter_member;
                if (filter_field_is_myself($c_reporter_id)) {
                    array_push($t_clauses, $c_user_id);
                } else {
                    array_push($t_clauses, $c_reporter_id);
                }
            }
        }
        if (1 < count($t_clauses)) {
            $t_reporter_query = '( {bug}.reporter_id in (' . implode(', ', $t_clauses) . ') )';
        } else {
            $t_reporter_query = '( {bug}.reporter_id=' . $t_clauses[0] . ' )';
        }
        log_event(LOG_FILTERING, 'reporter query = ' . $t_reporter_query);
        array_push($t_where_clauses, $t_reporter_query);
    } else {
        log_event(LOG_FILTERING, 'no reporter query');
    }
    # handler
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_HANDLER_ID])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_HANDLER_ID] as $t_filter_member) {
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, 0);
            } else {
                $c_handler_id = (int) $t_filter_member;
                if (filter_field_is_myself($c_handler_id)) {
                    array_push($t_clauses, $c_user_id);
                } else {
                    array_push($t_clauses, $c_handler_id);
                }
            }
        }
        if (1 < count($t_clauses)) {
            $t_handler_query = '( {bug}.handler_id in (' . implode(', ', $t_clauses) . ') )';
        } else {
            $t_handler_query = '( {bug}.handler_id=' . $t_clauses[0] . ' )';
        }
        log_event(LOG_FILTERING, 'handler query = ' . $t_handler_query);
        array_push($t_where_clauses, $t_handler_query);
    } else {
        log_event(LOG_FILTERING, 'no handler query');
    }
    # category
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_CATEGORY_ID])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_CATEGORY_ID] as $t_filter_member) {
            if (!filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, $t_filter_member);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, '( {bug}.category_id in ( SELECT id FROM {category} WHERE name in (' . implode(', ', $t_where_tmp) . ') ) )');
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, '( {bug}.category_id in ( SELECT id FROM {category} WHERE name=' . db_param() . ') )');
        }
    }
    # severity
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_SEVERITY])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_SEVERITY] as $t_filter_member) {
            $c_show_severity = (int) $t_filter_member;
            array_push($t_clauses, $c_show_severity);
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, '( {bug}.severity in (' . implode(', ', $t_where_tmp) . ') )');
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, '( {bug}.severity=' . db_param() . ' )');
        }
    }
    # show / hide status
    # take a list of all available statuses then remove the ones that we want hidden, then make sure
    # the ones we want shown are still available
    $t_desired_statuses = array();
    $t_available_statuses = MantisEnum::getValues(config_get('status_enum_string'));
    if ('simple' == $t_filter['_view_type']) {
        # simple filtering: if showing any, restrict by the hide status value, otherwise ignore the hide
        $t_this_status = $t_filter[FILTER_PROPERTY_STATUS][0];
        $t_this_hide_status = isset($t_filter[FILTER_PROPERTY_HIDE_STATUS][0]) ? $t_filter[FILTER_PROPERTY_HIDE_STATUS][0] : null;
        if (filter_field_is_any($t_this_status)) {
            foreach ($t_available_statuses as $t_this_available_status) {
                if ($t_this_hide_status > $t_this_available_status) {
                    $t_desired_statuses[] = $t_this_available_status;
                }
            }
        } else {
            $t_desired_statuses[] = $t_this_status;
        }
    } else {
        # advanced filtering: ignore the hide
        if (filter_field_is_any($t_filter[FILTER_PROPERTY_STATUS])) {
            $t_desired_statuses = array();
        } else {
            foreach ($t_filter[FILTER_PROPERTY_STATUS] as $t_this_status) {
                $t_desired_statuses[] = $t_this_status;
            }
        }
    }
    if (count($t_desired_statuses) > 0) {
        $t_clauses = array();
        foreach ($t_desired_statuses as $t_filter_member) {
            $c_show_status = (int) $t_filter_member;
            array_push($t_clauses, $c_show_status);
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, '( {bug}.status in (' . implode(', ', $t_where_tmp) . ') )');
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, '( {bug}.status=' . db_param() . ' )');
        }
    }
    # resolution
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_RESOLUTION])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_RESOLUTION] as $t_filter_member) {
            $c_show_resolution = (int) $t_filter_member;
            array_push($t_clauses, $c_show_resolution);
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, '( {bug}.resolution in (' . implode(', ', $t_where_tmp) . ') )');
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, '( {bug}.resolution=' . db_param() . ' )');
        }
    }
    # priority
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_PRIORITY])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_PRIORITY] as $t_filter_member) {
            $c_show_priority = (int) $t_filter_member;
            array_push($t_clauses, $c_show_priority);
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, '( {bug}.priority in (' . implode(', ', $t_where_tmp) . ') )');
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, '( {bug}.priority=' . db_param() . ' )');
        }
    }
    # product build
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_BUILD])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_BUILD] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, '');
            } else {
                $c_show_build = $t_filter_member;
                array_push($t_clauses, $c_show_build);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, '( {bug}.build in (' . implode(', ', $t_where_tmp) . ') )');
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, '( {bug}.build=' . db_param() . ' )');
        }
    }
    # product version
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_VERSION])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_VERSION] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, '');
            } else {
                $c_show_version = $t_filter_member;
                array_push($t_clauses, $c_show_version);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, '( {bug}.version in (' . implode(', ', $t_where_tmp) . ') )');
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, '( {bug}.version=' . db_param() . ' )');
        }
    }
    # profile
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_PROFILE_ID])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_PROFILE_ID] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, '0');
            } else {
                $c_show_profile = (int) $t_filter_member;
                array_push($t_clauses, $c_show_profile);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, '( {bug}.profile_id in (' . implode(', ', $t_where_tmp) . ') )');
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, '( {bug}.profile_id=' . db_param() . ' )');
        }
    }
    # platform
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_PLATFORM])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_PLATFORM] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, '');
            } else {
                $c_platform = $t_filter_member;
                array_push($t_clauses, $c_platform);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, '( {bug}.platform in (' . implode(', ', $t_where_tmp) . ') )');
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, '( {bug}.platform = ' . db_param() . ' )');
        }
    }
    # Operating System (os)
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_OS])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_OS] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, '');
            } else {
                $c_os = $t_filter_member;
                array_push($t_clauses, $c_os);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, '( {bug}.os in (' . implode(', ', $t_where_tmp) . ') )');
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, '( {bug}.os = ' . db_param() . ' )');
        }
    }
    # Operating System Build (os_build)
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_OS_BUILD])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_OS_BUILD] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, '');
            } else {
                $c_os_build = $t_filter_member;
                array_push($t_clauses, $c_os_build);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, '( {bug}.os_build in (' . implode(', ', $t_where_tmp) . ') )');
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, '( {bug}.os_build = ' . db_param() . ' )');
        }
    }
    # fixed in version
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_FIXED_IN_VERSION])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_FIXED_IN_VERSION] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, '');
            } else {
                $c_fixed_in_version = $t_filter_member;
                array_push($t_clauses, $c_fixed_in_version);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, '( {bug}.fixed_in_version in (' . implode(', ', $t_where_tmp) . ') )');
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, '( {bug}.fixed_in_version=' . db_param() . ' )');
        }
    }
    # target version
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_TARGET_VERSION])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_TARGET_VERSION] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, '');
            } else {
                $c_target_version = $t_filter_member;
                array_push($t_clauses, $c_target_version);
            }
        }
        # echo var_dump( $t_clauses ); exit;
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, '( {bug}.target_version in (' . implode(', ', $t_where_tmp) . ') )');
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, '( {bug}.target_version=' . db_param() . ' )');
        }
    }
    # users monitoring a bug
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_MONITOR_USER_ID])) {
        $t_clauses = array();
        $t_table_name = 'user_monitor';
        array_push($t_join_clauses, 'LEFT JOIN {bug_monitor} ' . $t_table_name . ' ON ' . $t_table_name . '.bug_id = {bug}.id');
        foreach ($t_filter[FILTER_PROPERTY_MONITOR_USER_ID] as $t_filter_member) {
            $c_user_monitor = (int) $t_filter_member;
            if (filter_field_is_myself($c_user_monitor)) {
                array_push($t_clauses, $c_user_id);
            } else {
                array_push($t_clauses, $c_user_monitor);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, '( ' . $t_table_name . '.user_id in (' . implode(', ', $t_where_tmp) . ') )');
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, '( ' . $t_table_name . '.user_id=' . db_param() . ' )');
        }
    }
    # bug relationship
    $t_any_found = false;
    $c_rel_type = $t_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE];
    $c_rel_bug = $t_filter[FILTER_PROPERTY_RELATIONSHIP_BUG];
    if (-1 == $c_rel_type || 0 == $c_rel_bug) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        # use the complementary type
        $t_comp_type = relationship_get_complementary_type($c_rel_type);
        $t_clauses = array();
        $t_table_dst = 'rel_dst';
        $t_table_src = 'rel_src';
        array_push($t_join_clauses, 'LEFT JOIN {bug_relationship} ' . $t_table_dst . ' ON ' . $t_table_dst . '.destination_bug_id = {bug}.id');
        array_push($t_join_clauses, 'LEFT JOIN {bug_relationship} ' . $t_table_src . ' ON ' . $t_table_src . '.source_bug_id = {bug}.id');
        # get reverse relationships
        $t_where_params[] = $t_comp_type;
        $t_where_params[] = $c_rel_bug;
        $t_where_params[] = $c_rel_type;
        $t_where_params[] = $c_rel_bug;
        array_push($t_clauses, '(' . $t_table_dst . '.relationship_type=' . db_param() . ' AND ' . $t_table_dst . '.source_bug_id=' . db_param() . ')');
        array_push($t_clauses, '(' . $t_table_src . '.relationship_type=' . db_param() . ' AND ' . $t_table_src . '.destination_bug_id=' . db_param() . ')');
        array_push($t_where_clauses, '(' . implode(' OR ', $t_clauses) . ')');
    }
    # tags
    $c_tag_string = trim($t_filter[FILTER_PROPERTY_TAG_STRING]);
    $c_tag_select = trim($t_filter[FILTER_PROPERTY_TAG_SELECT]);
    if (is_blank($c_tag_string) && !is_blank($c_tag_select) && $c_tag_select != 0) {
        $t_tag = tag_get($c_tag_select);
        $c_tag_string = $t_tag['name'];
    }
    if (!is_blank($c_tag_string)) {
        $t_tags = tag_parse_filters($c_tag_string);
        if (count($t_tags)) {
            $t_tags_all = array();
            $t_tags_any = array();
            $t_tags_none = array();
            foreach ($t_tags as $t_tag_row) {
                switch ($t_tag_row['filter']) {
                    case 1:
                        $t_tags_all[] = $t_tag_row;
                        break;
                    case 0:
                        $t_tags_any[] = $t_tag_row;
                        break;
                    case -1:
                        $t_tags_none[] = $t_tag_row;
                        break;
                }
            }
            if (0 < $t_filter[FILTER_PROPERTY_TAG_SELECT] && tag_exists($t_filter[FILTER_PROPERTY_TAG_SELECT])) {
                $t_tags_any[] = tag_get($t_filter[FILTER_PROPERTY_TAG_SELECT]);
            }
            if (count($t_tags_all)) {
                $t_clauses = array();
                foreach ($t_tags_all as $t_tag_row) {
                    array_push($t_clauses, '{bug}.id IN ( SELECT bug_id FROM {bug_tag} WHERE {bug_tag}.tag_id = ' . $t_tag_row['id'] . ')');
                }
                array_push($t_where_clauses, '(' . implode(' AND ', $t_clauses) . ')');
            }
            if (count($t_tags_any)) {
                $t_clauses = array();
                foreach ($t_tags_any as $t_tag_row) {
                    array_push($t_clauses, '{bug_tag}.tag_id = ' . $t_tag_row['id']);
                }
                array_push($t_where_clauses, '{bug}.id IN ( SELECT bug_id FROM {bug_tag} WHERE ( ' . implode(' OR ', $t_clauses) . ') )');
            }
            if (count($t_tags_none)) {
                $t_clauses = array();
                foreach ($t_tags_none as $t_tag_row) {
                    array_push($t_clauses, '{bug_tag}.tag_id = ' . $t_tag_row['id']);
                }
                array_push($t_where_clauses, '{bug}.id NOT IN ( SELECT bug_id FROM {bug_tag} WHERE ( ' . implode(' OR ', $t_clauses) . ') )');
            }
        }
    }
    # note user id
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_NOTE_USER_ID])) {
        $t_bugnote_table_alias = 'mbnt';
        $t_clauses = array();
        array_push($t_join_clauses, 'LEFT JOIN {bugnote} ' . $t_bugnote_table_alias . ' ON {bug}.id = ' . $t_bugnote_table_alias . '.bug_id');
        foreach ($t_filter[FILTER_PROPERTY_NOTE_USER_ID] as $t_filter_member) {
            $c_note_user_id = (int) $t_filter_member;
            if (filter_field_is_myself($c_note_user_id)) {
                array_push($t_clauses, $c_user_id);
            } else {
                array_push($t_clauses, $c_note_user_id);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, '( ' . $t_bugnote_table_alias . '.reporter_id in (' . implode(', ', $t_where_tmp) . ') )');
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, '( ' . $t_bugnote_table_alias . '.reporter_id=' . db_param() . ' )');
        }
    }
    # plugin filters
    $t_plugin_filters = filter_get_plugin_filters();
    foreach ($t_plugin_filters as $t_field_name => $t_filter_object) {
        if (!filter_field_is_any($t_filter[$t_field_name]) || $t_filter_object->type == FILTER_TYPE_BOOLEAN) {
            $t_filter_query = $t_filter_object->query($t_filter[$t_field_name]);
            if (is_array($t_filter_query)) {
                if (isset($t_filter_query['join'])) {
                    array_push($t_join_clauses, $t_filter_query['join']);
                }
                if (isset($t_filter_query['where'])) {
                    array_push($t_where_clauses, $t_filter_query['where']);
                }
                if (isset($t_filter_query['params']) && is_array($t_filter_query['params'])) {
                    $t_where_params = array_merge($t_where_params, $t_filter_query['params']);
                }
            }
        }
    }
    # custom field filters
    if (ON == config_get('filter_by_custom_fields')) {
        # custom field filtering
        # @@@ At the moment this gets the linked fields relating to the current project
        #     It should get the ones relating to the project in the filter or all projects
        #     if multiple projects.
        $t_custom_fields = custom_field_get_linked_ids($t_project_id);
        foreach ($t_custom_fields as $t_cfid) {
            $t_field_info = custom_field_cache_row($t_cfid, true);
            if (!$t_field_info['filter_by']) {
                continue;
                # skip this custom field it shouldn't be filterable
            }
            $t_field = $t_filter['custom_fields'][$t_cfid];
            $t_custom_where_clause = '';
            # Ignore all custom filters that are not set, or that are set to '' or "any"
            if (!filter_field_is_any($t_field)) {
                $t_def = custom_field_get_definition($t_cfid);
                $t_table_name = '{custom_field_string}_' . $t_cfid;
                # We need to filter each joined table or the result query will explode in dimensions
                # Each custom field will result in a exponential growth like Number_of_Issues^Number_of_Custom_Fields
                # and only after this process ends (if it is able to) the result query will be filtered
                # by the WHERE clause and by the DISTINCT clause
                $t_cf_join_clause = 'LEFT JOIN {custom_field_string} ' . $t_table_name . ' ON {bug}.id = ' . $t_table_name . '.bug_id AND ' . $t_table_name . '.field_id = ' . $t_cfid;
                if ($t_def['type'] == CUSTOM_FIELD_TYPE_DATE) {
                    # Define the value field with type cast to integer
                    $t_value_field = 'CAST(COALESCE(NULLIF(' . $t_table_name . '.value, \'\'), \'0\') AS DECIMAL)';
                    switch ($t_field[0]) {
                        # Closing parenthesis intentionally omitted, will be added later on
                        case CUSTOM_FIELD_DATE_ANY:
                            break;
                        case CUSTOM_FIELD_DATE_NONE:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '( ' . $t_table_name . '.bug_id is null OR ' . $t_value_field . ' = 0 ';
                            break;
                        case CUSTOM_FIELD_DATE_BEFORE:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '( ' . $t_value_field . ' != 0 AND ' . $t_value_field . ' < ' . $t_field[2];
                            break;
                        case CUSTOM_FIELD_DATE_AFTER:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '( ' . $t_value_field . ' > ' . ($t_field[1] + 1);
                            break;
                        default:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '( ' . $t_value_field . ' BETWEEN ' . $t_field[1] . ' AND ' . $t_field[2];
                            break;
                    }
                } else {
                    array_push($t_join_clauses, $t_cf_join_clause);
                    $t_filter_array = array();
                    foreach ($t_field as $t_filter_member) {
                        $t_filter_member = stripslashes($t_filter_member);
                        if (filter_field_is_none($t_filter_member)) {
                            # coerce filter value if selecting META_FILTER_NONE so it will match empty fields
                            $t_filter_member = '';
                            # but also add those _not_ present in the custom field string table
                            array_push($t_filter_array, '{bug}.id NOT IN (SELECT bug_id FROM {custom_field_string} WHERE field_id=' . $t_cfid . ')');
                        }
                        switch ($t_def['type']) {
                            case CUSTOM_FIELD_TYPE_CHECKBOX:
                            case CUSTOM_FIELD_TYPE_MULTILIST:
                                $t_where_params[] = '%|' . $t_filter_member . '|%';
                                array_push($t_filter_array, db_helper_like($t_table_name . '.value'));
                                break;
                            case CUSTOM_FIELD_TYPE_TEXTAREA:
                                $t_where_params[] = '%' . $t_filter_member . '%';
                                array_push($t_filter_array, db_helper_like($t_table_name . '.text'));
                                break;
                            default:
                                $t_where_params[] = $t_filter_member;
                                array_push($t_filter_array, $t_table_name . '.value = ' . db_param());
                        }
                    }
                    $t_custom_where_clause .= '(' . implode(' OR ', $t_filter_array);
                }
                if (!is_blank($t_custom_where_clause)) {
                    array_push($t_where_clauses, $t_custom_where_clause . ')');
                }
            }
        }
    }
    # Text search
    if (!is_blank($t_filter[FILTER_PROPERTY_SEARCH])) {
        # break up search terms by spacing or quoting
        preg_match_all("/-?([^'\"\\s]+|\"[^\"]+\"|'[^']+')/", $t_filter[FILTER_PROPERTY_SEARCH], $t_matches, PREG_SET_ORDER);
        # organize terms without quoting, paying attention to negation
        $t_search_terms = array();
        foreach ($t_matches as $t_match) {
            $t_search_terms[trim($t_match[1], "\\'\"")] = $t_match[0][0] == '-';
        }
        # build a big where-clause and param list for all search terms, including negations
        $t_first = true;
        $t_textsearch_where_clause = '( ';
        foreach ($t_search_terms as $t_search_term => $t_negate) {
            if (!$t_first) {
                $t_textsearch_where_clause .= ' AND ';
            }
            if ($t_negate) {
                $t_textsearch_where_clause .= 'NOT ';
            }
            $c_search = '%' . $t_search_term . '%';
            $t_textsearch_where_clause .= '( ' . db_helper_like('{bug}.summary') . ' OR ' . db_helper_like('{bug_text}.description') . ' OR ' . db_helper_like('{bug_text}.steps_to_reproduce') . ' OR ' . db_helper_like('{bug_text}.additional_information') . ' OR ' . db_helper_like('{bugnote_text}.note');
            $t_where_params[] = $c_search;
            $t_where_params[] = $c_search;
            $t_where_params[] = $c_search;
            $t_where_params[] = $c_search;
            $t_where_params[] = $c_search;
            if (is_numeric($t_search_term)) {
                # PostgreSQL on 64-bit OS hack (see #14014)
                if (PHP_INT_MAX > 0x7fffffff && db_is_pgsql()) {
                    $t_search_max = 0x7fffffff;
                } else {
                    $t_search_max = PHP_INT_MAX;
                }
                # Note: no need to test negative values, '-' sign has been removed
                if ($t_search_term <= $t_search_max) {
                    $c_search_int = (int) $t_search_term;
                    $t_textsearch_where_clause .= ' OR {bug}.id = ' . db_param();
                    $t_textsearch_where_clause .= ' OR {bugnote}.id = ' . db_param();
                    $t_where_params[] = $c_search_int;
                    $t_where_params[] = $c_search_int;
                }
            }
            $t_textsearch_where_clause .= ' )';
            $t_first = false;
        }
        $t_textsearch_where_clause .= ' )';
        # add text query elements to arrays
        if (!$t_first) {
            $t_join_clauses[] = 'JOIN {bug_text} ON {bug}.bug_text_id = {bug_text}.id';
            $t_join_clauses[] = 'LEFT JOIN {bugnote} ON {bug}.id = {bugnote}.bug_id';
            # Outer join required otherwise we don't retrieve issues without notes
            $t_join_clauses[] = 'LEFT JOIN {bugnote_text} ON {bugnote}.bugnote_text_id = {bugnote_text}.id';
            $t_where_clauses[] = $t_textsearch_where_clause;
        }
    }
    # End text search
    # Determine join operator
    if ($t_filter[FILTER_PROPERTY_MATCH_TYPE] == FILTER_MATCH_ANY) {
        $t_join_operator = ' OR ';
    } else {
        $t_join_operator = ' AND ';
    }
    log_event(LOG_FILTERING, 'Join operator : ' . $t_join_operator);
    $t_query_clauses['select'] = $t_select_clauses;
    $t_query_clauses['from'] = $t_from_clauses;
    $t_query_clauses['join'] = $t_join_clauses;
    $t_query_clauses['where'] = $t_where_clauses;
    $t_query_clauses['where_values'] = $t_where_params;
    $t_query_clauses['project_where'] = $t_project_where_clauses;
    $t_query_clauses['operator'] = $t_join_operator;
    $t_query_clauses = filter_get_query_sort_data($t_filter, $p_show_sticky, $t_query_clauses);
    # assigning to $p_* for this function writes the values back in case the caller wants to know
    # Get the total number of bugs that meet the criteria.
    $p_bug_count = filter_get_bug_count($t_query_clauses);
    if (0 == $p_bug_count) {
        return array();
    }
    $p_per_page = filter_per_page($t_filter, $p_bug_count, $p_per_page);
    $p_page_count = filter_page_count($p_bug_count, $p_per_page);
    $p_page_number = filter_valid_page_number($p_page_number, $p_page_count);
    $t_offset = filter_offset($p_page_number, $p_per_page);
    $t_query_clauses = filter_unique_query_clauses($t_query_clauses);
    $t_select_string = 'SELECT DISTINCT ' . implode(', ', $t_query_clauses['select']);
    $t_from_string = ' FROM ' . implode(', ', $t_query_clauses['from']);
    $t_order_string = ' ORDER BY ' . implode(', ', $t_query_clauses['order']);
    $t_join_string = count($t_query_clauses['join']) > 0 ? implode(' ', $t_query_clauses['join']) : ' ';
    $t_where_string = ' WHERE ' . implode(' AND ', $t_query_clauses['project_where']);
    if (count($t_query_clauses['where']) > 0) {
        $t_where_string .= ' AND ( ';
        $t_where_string .= implode($t_join_operator, $t_query_clauses['where']);
        $t_where_string .= ' ) ';
    }
    $t_result = db_query($t_select_string . $t_from_string . $t_join_string . $t_where_string . $t_order_string, $t_query_clauses['where_values'], $p_per_page, $t_offset);
    $t_id_array_lastmod = array();
    while ($t_row = db_fetch_array($t_result)) {
        $t_id_array_lastmod[] = (int) $t_row['id'];
        $t_rows[] = $t_row;
    }
    return filter_cache_result($t_rows, $t_id_array_lastmod);
}
Exemple #7
0
$f_custom_field_id = gpc_get_int('custom_field_id', 0);
$f_bug_arr = gpc_get_int_array('bug_arr', array());
$f_bug_notetext = gpc_get_string('bugnote_text', '');
$f_bug_noteprivate = gpc_get_bool('private');
$t_form_name = 'bug_actiongroup_' . $f_action;
form_security_validate($t_form_name);
$t_custom_group_actions = config_get('custom_group_actions');
foreach ($t_custom_group_actions as $t_custom_group_action) {
    if ($f_action == $t_custom_group_action['action']) {
        require_once $t_custom_group_action['action_page'];
        exit;
    }
}
$t_failed_ids = array();
if (0 != $f_custom_field_id) {
    $t_custom_field_def = custom_field_get_definition($f_custom_field_id);
}
foreach ($f_bug_arr as $t_bug_id) {
    bug_ensure_exists($t_bug_id);
    $t_bug = bug_get($t_bug_id, true);
    if ($t_bug->project_id != helper_get_current_project()) {
        # in case the current project is not the same project of the bug we are viewing...
        # ... override the current project. This to avoid problems with categories and handlers lists etc.
        $g_project_override = $t_bug->project_id;
        # @todo (thraxisp) the next line goes away if the cache was smarter and used project
        config_flush_cache();
        # flush the config cache so that configs are refetched
    }
    $t_status = $t_bug->status;
    switch ($f_action) {
        case 'CLOSE':
/**
 * Get a list of bug group actions available to the current user for one or
 * more projects.
 * @param array $p_project_ids An array containing one or more project IDs.
 * @return array
 */
function bug_group_action_get_commands(array $p_project_ids = null)
{
    if ($p_project_ids === null || count($p_project_ids) == 0) {
        $p_project_ids = array(ALL_PROJECTS);
    }
    $t_commands = array();
    foreach ($p_project_ids as $t_project_id) {
        if (!isset($t_commands['MOVE']) && access_has_project_level(config_get('move_bug_threshold', null, null, $t_project_id), $t_project_id)) {
            $t_commands['MOVE'] = lang_get('actiongroup_menu_move');
        }
        if (!isset($t_commands['COPY']) && access_has_any_project(config_get('report_bug_threshold', null, null, $t_project_id))) {
            $t_commands['COPY'] = lang_get('actiongroup_menu_copy');
        }
        if (!isset($t_commands['ASSIGN']) && access_has_project_level(config_get('update_bug_assign_threshold', null, null, $t_project_id), $t_project_id)) {
            if (ON == config_get('auto_set_status_to_assigned', null, null, $t_project_id) && access_has_project_level(access_get_status_threshold(config_get('bug_assigned_status', null, null, $t_project_id), $t_project_id), $t_project_id)) {
                $t_commands['ASSIGN'] = lang_get('actiongroup_menu_assign');
            } else {
                $t_commands['ASSIGN'] = lang_get('actiongroup_menu_assign');
            }
        }
        if (!isset($t_commands['CLOSE']) && access_has_project_level(config_get('update_bug_status_threshold', null, null, $t_project_id), $t_project_id) && (access_has_project_level(access_get_status_threshold(config_get('bug_closed_status_threshold', null, null, $t_project_id), $t_project_id), $t_project_id) || access_has_project_level(config_get('allow_reporter_close', null, null, $t_project_id), $t_project_id))) {
            $t_commands['CLOSE'] = lang_get('actiongroup_menu_close');
        }
        if (!isset($t_commands['DELETE']) && access_has_project_level(config_get('delete_bug_threshold', null, null, $t_project_id), $t_project_id)) {
            $t_commands['DELETE'] = lang_get('actiongroup_menu_delete');
        }
        if (!isset($t_commands['RESOLVE']) && access_has_project_level(config_get('update_bug_status_threshold', null, null, $t_project_id), $t_project_id) && access_has_project_level(access_get_status_threshold(config_get('bug_resolved_status_threshold', null, null, $t_project_id), $t_project_id), $t_project_id)) {
            $t_commands['RESOLVE'] = lang_get('actiongroup_menu_resolve');
        }
        if (!isset($t_commands['SET_STICKY']) && access_has_project_level(config_get('set_bug_sticky_threshold', null, null, $t_project_id), $t_project_id)) {
            $t_commands['SET_STICKY'] = lang_get('actiongroup_menu_set_sticky');
        }
        if (!isset($t_commands['UP_PRIOR']) && access_has_project_level(config_get('update_bug_threshold', null, null, $t_project_id), $t_project_id)) {
            $t_commands['UP_PRIOR'] = lang_get('actiongroup_menu_update_priority');
        }
        if (!isset($t_commands['EXT_UPDATE_SEVERITY']) && access_has_project_level(config_get('update_bug_threshold', null, null, $t_project_id), $t_project_id)) {
            $t_commands['EXT_UPDATE_SEVERITY'] = lang_get('actiongroup_menu_update_severity');
        }
        if (!isset($t_commands['UP_STATUS']) && access_has_project_level(config_get('update_bug_status_threshold', null, null, $t_project_id), $t_project_id)) {
            $t_commands['UP_STATUS'] = lang_get('actiongroup_menu_update_status');
        }
        if (!isset($t_commands['UP_CATEGORY']) && access_has_project_level(config_get('update_bug_threshold', null, null, $t_project_id), $t_project_id)) {
            $t_commands['UP_CATEGORY'] = lang_get('actiongroup_menu_update_category');
        }
        if (!isset($t_commands['VIEW_STATUS']) && access_has_project_level(config_get('change_view_status_threshold', null, null, $t_project_id), $t_project_id)) {
            $t_commands['VIEW_STATUS'] = lang_get('actiongroup_menu_update_view_status');
        }
        if (!isset($t_commands['EXT_UPDATE_PRODUCT_BUILD']) && config_get('enable_product_build', null, null, $t_project_id) == ON && access_has_project_level(config_get('update_bug_threshold', null, null, $t_project_id), $t_project_id)) {
            $t_commands['EXT_UPDATE_PRODUCT_BUILD'] = lang_get('actiongroup_menu_update_product_build');
        }
        if (!isset($t_commands['EXT_ADD_NOTE']) && access_has_project_level(config_get('add_bugnote_threshold', null, null, $t_project_id), $t_project_id)) {
            $t_commands['EXT_ADD_NOTE'] = lang_get('actiongroup_menu_add_note');
        }
        if (!isset($t_commands['EXT_ATTACH_TAGS']) && access_has_project_level(config_get('tag_attach_threshold', null, null, $t_project_id), $t_project_id)) {
            $t_commands['EXT_ATTACH_TAGS'] = lang_get('actiongroup_menu_attach_tags');
        }
        if (!isset($t_commands['UP_FIXED_IN_VERSION']) && version_should_show_product_version($t_project_id) && access_has_project_level(config_get('update_bug_threshold', null, null, $t_project_id), $t_project_id)) {
            $t_commands['UP_FIXED_IN_VERSION'] = lang_get('actiongroup_menu_update_fixed_in_version');
        }
        if (!isset($t_commands['UP_TARGET_VERSION']) && version_should_show_product_version($t_project_id) && access_has_project_level(config_get('roadmap_update_threshold', null, null, $t_project_id), $t_project_id)) {
            $t_commands['UP_TARGET_VERSION'] = lang_get('actiongroup_menu_update_target_version');
        }
        $t_custom_field_ids = custom_field_get_linked_ids($t_project_id);
        foreach ($t_custom_field_ids as $t_custom_field_id) {
            if (!custom_field_has_write_access_to_project($t_custom_field_id, $t_project_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']));
            $t_commands[$t_command_id] = string_display($t_command_caption);
        }
    }
    $t_custom_group_actions = config_get('custom_group_actions');
    foreach ($t_custom_group_actions as $t_custom_group_action) {
        # use label if provided to get the localized text, otherwise fallback to action name.
        if (isset($t_custom_group_action['label'])) {
            $t_commands[$t_custom_group_action['action']] = lang_get_defaulted($t_custom_group_action['label']);
        } else {
            $t_commands[$t_custom_group_action['action']] = lang_get_defaulted($t_custom_group_action['action']);
        }
    }
    return $t_commands;
}
Exemple #9
0
/**
 * Gets the formatted value for the specified issue id, project and custom field.
 * @param integer $p_issue_id     The issue id.
 * @param integer $p_project_id   The project id.
 * @param string  $p_custom_field The custom field name (without 'custom_' prefix).
 * @return string The custom field value.
 */
function excel_format_custom_field($p_issue_id, $p_project_id, $p_custom_field)
{
    $t_field_id = custom_field_get_id_from_name($p_custom_field);
    if ($t_field_id === false) {
        return excel_prepare_string('@' . $p_custom_field . '@');
    }
    if (custom_field_is_linked($t_field_id, $p_project_id)) {
        $t_def = custom_field_get_definition($t_field_id);
        if ($t_def['type'] == CUSTOM_FIELD_TYPE_NUMERIC) {
            return excel_prepare_number(string_custom_field_value($t_def, $t_field_id, $p_issue_id));
        }
        return excel_prepare_string(string_custom_field_value($t_def, $t_field_id, $p_issue_id));
    }
    # field is not linked to project
    return excel_prepare_string('');
}
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'), 'EXT_ADD_NOTE' => lang_get('actiongroup_menu_add_note'), 'EXT_ATTACH_TAGS' => lang_get('actiongroup_menu_attach_tags'));
    $t_project_id = helper_get_current_project();
    if (ALL_PROJECTS != $t_project_id) {
        $t_user_id = auth_get_current_user_id();
        if (access_has_project_level(config_get('update_bug_threshold'), $t_project_id)) {
            $commands['UP_FIXED_IN_VERSION'] = lang_get('actiongroup_menu_update_fixed_in_version');
        }
        if (access_has_project_level(config_get('roadmap_update_threshold'), $t_project_id)) {
            $commands['UP_TARGET_VERSION'] = lang_get('actiongroup_menu_update_target_version');
        }
        $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] = string_display($t_command_caption);
        }
    }
    $t_custom_group_actions = config_get('custom_group_actions');
    foreach ($t_custom_group_actions as $t_custom_group_action) {
        # use label if provided to get the localized text, otherwise fallback to action name.
        if (isset($t_custom_group_action['label'])) {
            $commands[$t_custom_group_action['action']] = lang_get_defaulted($t_custom_group_action['label']);
        } else {
            $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>";
    }
}
/**
 * updates the status field
 * @return bool 
 * @access public
 * @see bug_update.php
 */
function kanban_ajax_request_bug_update_status()
{
    $p_bug_id = gpc_get_int('id');
    $p_new_status = gpc_get_int('new_status');
    $t_project_id = gpc_get_int('project_id');
    $c_bug_id = (int) $p_bug_id;
    $f_new_status = (int) $p_new_status;
    $t_bug_data = bug_get($c_bug_id, true);
    $f_update_mode = gpc_get_bool('update_mode', FALSE);
    # set if called from generic update page
    if (!(access_has_bug_level(access_get_status_threshold($f_new_status, $t_project_id), $c_bug_id) || access_has_bug_level(config_get('update_bug_threshold'), $c_bug_id) || bug_get_field($c_bug_id, 'reporter_id') == auth_get_current_user_id() && (ON == config_get('allow_reporter_reopen') || ON == config_get('allow_reporter_close')))) {
        access_denied();
    }
    # extract current extended information
    $t_old_bug_status = $t_bug_data->status;
    log_event(LOG_AJAX, "Old bug status {$t_old_bug_status} - trying update to new status {$f_new_status}...");
    $t_bug_data->reporter_id = gpc_get_int('reporter_id', $t_bug_data->reporter_id);
    $t_bug_data->handler_id = gpc_get_int('handler_id', $t_bug_data->handler_id);
    $t_bug_data->duplicate_id = gpc_get_int('duplicate_id', $t_bug_data->duplicate_id);
    $t_bug_data->priority = gpc_get_int('priority', $t_bug_data->priority);
    $t_bug_data->severity = gpc_get_int('severity', $t_bug_data->severity);
    $t_bug_data->reproducibility = gpc_get_int('reproducibility', $t_bug_data->reproducibility);
    $t_bug_data->status = gpc_get_int('new_status', $t_bug_data->status);
    $t_bug_data->resolution = gpc_get_int('resolution', $t_bug_data->resolution);
    $t_bug_data->projection = gpc_get_int('projection', $t_bug_data->projection);
    $t_bug_data->category_id = gpc_get_int('category_id', $t_bug_data->category_id);
    $t_bug_data->eta = gpc_get_int('eta', $t_bug_data->eta);
    $t_bug_data->os = gpc_get_string('os', $t_bug_data->os);
    $t_bug_data->os_build = gpc_get_string('os_build', $t_bug_data->os_build);
    $t_bug_data->platform = gpc_get_string('platform', $t_bug_data->platform);
    $t_bug_data->version = gpc_get_string('version', $t_bug_data->version);
    $t_bug_data->build = gpc_get_string('build', $t_bug_data->build);
    $t_bug_data->fixed_in_version = gpc_get_string('fixed_in_version', $t_bug_data->fixed_in_version);
    $t_bug_data->view_state = gpc_get_int('view_state', $t_bug_data->view_state);
    $t_bug_data->summary = gpc_get_string('summary', $t_bug_data->summary);
    $t_due_date = gpc_get_string('due_date', null);
    if (access_has_project_level(config_get('roadmap_update_threshold'), $t_bug_data->project_id)) {
        $t_bug_data->target_version = gpc_get_string('target_version', $t_bug_data->target_version);
    }
    if ($t_due_date !== null) {
        if (is_blank($t_due_date)) {
            $t_bug_data->due_date = 1;
        } else {
            $t_bug_data->due_date = strtotime($t_due_date);
        }
    }
    $t_bug_data->description = gpc_get_string('description', $t_bug_data->description);
    $t_bug_data->steps_to_reproduce = gpc_get_string('steps_to_reproduce', $t_bug_data->steps_to_reproduce);
    $t_bug_data->additional_information = gpc_get_string('additional_information', $t_bug_data->additional_information);
    $f_private = gpc_get_bool('private');
    $f_bugnote_text = gpc_get_string('bugnote_text', '');
    $f_time_tracking = gpc_get_string('time_tracking', '0:00');
    $f_close_now = gpc_get_string('close_now', false);
    # Handle auto-assigning
    if (config_get('bug_submit_status') == $t_bug_data->status && $t_bug_data->status == $t_old_bug_status && 0 != $t_bug_data->handler_id && ON == config_get('auto_set_status_to_assigned')) {
        $t_bug_data->status = config_get('bug_assigned_status');
    }
    helper_call_custom_function('issue_update_validate', array($c_bug_id, $t_bug_data, $f_bugnote_text));
    $t_resolved = config_get('bug_resolved_status_threshold');
    $t_closed = config_get('bug_closed_status_threshold');
    $t_custom_status_label = "update";
    # default info to check
    if ($t_bug_data->status == $t_resolved) {
        $t_custom_status_label = "resolved";
    }
    if ($t_bug_data->status == $t_closed) {
        $t_custom_status_label = "closed";
    }
    $t_related_custom_field_ids = custom_field_get_linked_ids($t_bug_data->project_id);
    foreach ($t_related_custom_field_ids as $t_id) {
        $t_def = custom_field_get_definition($t_id);
        # Only update the field if it would have been display for editing
        if (!(!$f_update_mode && $t_def['require_' . $t_custom_status_label] || !$f_update_mode && $t_def['display_' . $t_custom_status_label] && in_array($t_custom_status_label, array("resolved", "closed")) || $f_update_mode && $t_def['display_update'] || $f_update_mode && $t_def['require_update'])) {
            continue;
        }
        # Do not set custom field value if user has no write access.
        if (!custom_field_has_write_access($t_id, $c_bug_id)) {
            continue;
        }
        if ($t_def['require_' . $t_custom_status_label] && !gpc_isset_custom_field($t_id, $t_def['type'])) {
            error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
            trigger_error(ERROR_EMPTY_FIELD, ERROR);
        }
        # Only update the field if it is posted,
        #	or if it is empty, and the current value isn't the default
        if (!gpc_isset_custom_field($t_id, $t_def['type']) && custom_field_get_value($t_id, $c_bug_id) == $t_def['default_value']) {
            continue;
        }
        if (!custom_field_set_value($t_id, $c_bug_id, gpc_get_custom_field("custom_field_{$t_id}", $t_def['type'], NULL))) {
            error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
            log_event(LOG_AJAX, "Error setting new status: " . ERROR_CUSTOM_FIELD_INVALID_VALUE . "\nBugdata: " . print_r($t_bug_data, true) . " Line: " . __LINE__);
            trigger_error(ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR);
        }
    }
    $t_notify = true;
    $t_bug_note_set = false;
    if ($t_old_bug_status != $t_bug_data->status && FALSE == $f_update_mode) {
        # handle status transitions that come from pages other than bug_*update_page.php
        # this does the minimum to act on the bug and sends a specific message
        if ($t_bug_data->status >= $t_resolved && $t_bug_data->status < $t_closed && $t_old_bug_status < $t_resolved) {
            # bug_resolve updates the status, fixed_in_version, resolution, handler_id and bugnote and sends message
            bug_resolve($c_bug_id, $t_bug_data->resolution, $t_bug_data->fixed_in_version, $f_bugnote_text, $t_bug_data->duplicate_id, $t_bug_data->handler_id, $f_private, $f_time_tracking);
            $t_notify = false;
            $t_bug_note_set = true;
            if ($f_close_now) {
                bug_set_field($c_bug_id, 'status', $t_closed);
            }
            // update bug data with fields that may be updated inside bug_resolve(), otherwise changes will be overwritten
            // in bug_update() call below.
            $t_bug_data->handler_id = bug_get_field($c_bug_id, 'handler_id');
            $t_bug_data->status = bug_get_field($c_bug_id, 'status');
        } else {
            if ($t_bug_data->status >= $t_closed && $t_old_bug_status < $t_closed) {
                # bug_close updates the status and bugnote and sends message
                bug_close($c_bug_id, $f_bugnote_text, $f_private, $f_time_tracking);
                $t_notify = false;
                $t_bug_note_set = true;
            } else {
                if ($t_bug_data->status == config_get('bug_reopen_status') && $t_old_bug_status >= $t_resolved) {
                    bug_set_field($c_bug_id, 'handler_id', $t_bug_data->handler_id);
                    # fix: update handler_id before calling bug_reopen
                    # bug_reopen updates the status and bugnote and sends message
                    bug_reopen($c_bug_id, $f_bugnote_text, $f_time_tracking, $f_private);
                    $t_notify = false;
                    $t_bug_note_set = true;
                    // update bug data with fields that may be updated inside bug_resolve(), otherwise changes will be overwritten
                    // in bug_update() call below.
                    $t_bug_data->status = bug_get_field($c_bug_id, 'status');
                    $t_bug_data->resolution = bug_get_field($c_bug_id, 'resolution');
                }
            }
        }
    }
    # Plugin support
    $t_new_bug_data = event_signal('EVENT_UPDATE_BUG', $t_bug_data, $c_bug_id);
    if (!is_null($t_new_bug_data)) {
        $t_bug_data = $t_new_bug_data;
    }
    # Add a bugnote if there is one
    if (false == $t_bug_note_set) {
        bugnote_add($c_bug_id, $f_bugnote_text, $f_time_tracking, $f_private, 0, '', NULL, FALSE);
    }
    # Update the bug entry, notify if we haven't done so already
    $t_bug_data->update(true, false == $t_notify);
    helper_call_custom_function('issue_update_notify', array($c_bug_id));
    return true;
}
Exemple #12
0
function filter_get_bug_rows(&$p_page_number, &$p_per_page, &$p_page_count, &$p_bug_count, $p_custom_filter = null, $p_project_id = null, $p_user_id = null, $p_show_sticky = null)
{
    $t_bug_table = config_get('mantis_bug_table');
    $t_bug_text_table = config_get('mantis_bug_text_table');
    $t_bugnote_table = config_get('mantis_bugnote_table');
    $t_custom_field_string_table = config_get('mantis_custom_field_string_table');
    $t_bugnote_text_table = config_get('mantis_bugnote_text_table');
    $t_project_table = config_get('mantis_project_table');
    $t_bug_monitor_table = config_get('mantis_bug_monitor_table');
    $t_limit_reporters = config_get('limit_reporters');
    $t_bug_relationship_table = config_get('mantis_bug_relationship_table');
    $t_report_bug_threshold = config_get('report_bug_threshold');
    $t_current_user_id = auth_get_current_user_id();
    if (null === $p_user_id) {
        $t_user_id = $t_current_user_id;
    } else {
        $t_user_id = $p_user_id;
    }
    $c_user_id = db_prepare_int($t_user_id);
    if (null === $p_project_id) {
        $t_project_id = helper_get_current_project();
    } else {
        $t_project_id = $p_project_id;
    }
    if ($p_custom_filter === null) {
        # Prefer current_user_get_bug_filter() over user_get_filter() when applicable since it supports
        # cookies set by previous version of the code.
        if ($t_user_id == $t_current_user_id) {
            $t_filter = current_user_get_bug_filter();
        } else {
            $t_filter = user_get_bug_filter($t_user_id, $t_project_id);
        }
    } else {
        $t_filter = $p_custom_filter;
    }
    $t_filter = filter_ensure_valid_filter($t_filter);
    if (false === $t_filter) {
        return false;
        # signify a need to create a cookie
        #@@@ error instead?
    }
    $t_where_clauses = array("{$t_project_table}.enabled = 1", "{$t_project_table}.id = {$t_bug_table}.project_id");
    $t_select_clauses = array("{$t_bug_table}.*");
    $t_join_clauses = array();
    $t_from_clauses = array();
    if (ALL_PROJECTS == $t_project_id) {
        if (!user_is_administrator($t_user_id)) {
            $t_topprojects = $t_projects = user_get_accessible_projects($t_user_id);
            foreach ($t_topprojects as $t_project) {
                $t_projects = array_merge($t_projects, user_get_all_accessible_subprojects($t_user_id, $t_project));
            }
            $t_projects = array_unique($t_projects);
            if (0 == count($t_projects)) {
                return array();
                # no accessible projects, return an empty array
            } else {
                if (1 == count($t_projects)) {
                    $t_project = $t_projects[0];
                    array_push($t_where_clauses, "( {$t_bug_table}.project_id={$t_project} )");
                } else {
                    array_push($t_where_clauses, "( {$t_bug_table}.project_id in (" . implode(', ', $t_projects) . ") )");
                }
            }
        }
    } else {
        access_ensure_project_level(VIEWER, $t_project_id, $t_user_id);
        $t_projects = user_get_all_accessible_subprojects($t_user_id, $t_project_id);
        $t_projects[] = $t_project_id;
        $t_projects = array_unique($t_projects);
        if (1 == count($t_projects)) {
            $t_project = $t_projects[0];
            array_push($t_where_clauses, "( {$t_bug_table}.project_id={$t_project} )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.project_id in (" . implode(', ', $t_projects) . ") )");
        }
    }
    # private bug selection
    if (!access_has_project_level(config_get('private_bug_threshold'), $t_project_id, $t_user_id)) {
        $t_public = VS_PUBLIC;
        $t_private = VS_PRIVATE;
        switch ($t_filter['view_state']) {
            case VS_PUBLIC:
                array_push($t_where_clauses, "({$t_bug_table}.view_state='{$t_public}')");
                break;
            case VS_PRIVATE:
                array_push($t_where_clauses, "({$t_bug_table}.view_state='{$t_private}' AND {$t_bug_table}.reporter_id='{$t_user_id}')");
                break;
            case META_FILTER_ANY:
            default:
                array_push($t_where_clauses, "({$t_bug_table}.view_state='{$t_public}' OR {$t_bug_table}.reporter_id='{$t_user_id}')");
                break;
        }
    } else {
        $t_view_state = db_prepare_int($t_filter['view_state']);
        if ($t_filter['view_state'] !== META_FILTER_ANY && !is_blank($t_filter['view_state'])) {
            array_push($t_where_clauses, "({$t_bug_table}.view_state='{$t_view_state}')");
        }
    }
    # reporter
    $t_any_found = false;
    foreach ($t_filter['reporter_id'] as $t_filter_member) {
        if (META_FILTER_ANY === $t_filter_member || 0 === $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['reporter_id']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['reporter_id'] as $t_filter_member) {
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "0");
            } else {
                $c_reporter_id = db_prepare_int($t_filter_member);
                if (META_FILTER_MYSELF == $c_reporter_id) {
                    array_push($t_clauses, $c_user_id);
                } else {
                    array_push($t_clauses, $c_reporter_id);
                }
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.reporter_id in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.reporter_id={$t_clauses['0']} )");
        }
    }
    # limit reporter
    # @@@ thraxisp - access_has_project_level checks greater than or equal to,
    #   this assumed that there aren't any holes above REPORTER where the limit would apply
    #
    if (ON === $t_limit_reporters && !access_has_project_level(REPORTER + 1, $t_project_id, $t_user_id)) {
        $c_reporter_id = $c_user_id;
        array_push($t_where_clauses, "({$t_bug_table}.reporter_id='{$c_reporter_id}')");
    }
    # handler
    $t_any_found = false;
    foreach ($t_filter['handler_id'] as $t_filter_member) {
        if (META_FILTER_ANY === $t_filter_member || 0 === $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['handler_id']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['handler_id'] as $t_filter_member) {
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, 0);
            } else {
                $c_handler_id = db_prepare_int($t_filter_member);
                if (META_FILTER_MYSELF == $c_handler_id) {
                    array_push($t_clauses, $c_user_id);
                } else {
                    array_push($t_clauses, $c_handler_id);
                }
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.handler_id in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.handler_id={$t_clauses['0']} )");
        }
    }
    # category
    $t_any_found = false;
    foreach ($t_filter['show_category'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member && is_numeric($t_filter_member)) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['show_category']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['show_category'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "''");
            } else {
                $c_show_category = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_show_category}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.category in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.category={$t_clauses['0']} )");
        }
    }
    # severity
    $t_any_found = false;
    foreach ($t_filter['show_severity'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member || 0 === $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['show_severity']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['show_severity'] as $t_filter_member) {
            $c_show_severity = db_prepare_int($t_filter_member);
            array_push($t_clauses, $c_show_severity);
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.severity in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.severity={$t_clauses['0']} )");
        }
    }
    # show / hide status
    # take a list of all available statuses then remove the ones that we want hidden, then make sure
    # the ones we want shown are still available
    $t_status_arr = explode_enum_string(config_get('status_enum_string'));
    $t_available_statuses = array();
    $t_desired_statuses = array();
    foreach ($t_status_arr as $t_this_status) {
        $t_this_status_arr = explode_enum_arr($t_this_status);
        $t_available_statuses[] = $t_this_status_arr[0];
    }
    if ('simple' == $t_filter['_view_type']) {
        # simple filtering: if showing any, restrict by the hide status value, otherwise ignore the hide
        $t_any_found = false;
        $t_this_status = $t_filter['show_status'][0];
        $t_this_hide_status = $t_filter['hide_status'][0];
        if (META_FILTER_ANY == $t_this_status || is_blank($t_this_status) || 0 === $t_this_status) {
            $t_any_found = true;
        }
        if ($t_any_found) {
            foreach ($t_available_statuses as $t_this_available_status) {
                if ($t_this_hide_status > $t_this_available_status) {
                    $t_desired_statuses[] = $t_this_available_status;
                }
            }
        } else {
            $t_desired_statuses[] = $t_this_status;
        }
    } else {
        # advanced filtering: ignore the hide
        $t_any_found = false;
        foreach ($t_filter['show_status'] as $t_this_status) {
            $t_desired_statuses[] = $t_this_status;
            if (META_FILTER_ANY == $t_this_status || is_blank($t_this_status) || 0 === $t_this_status) {
                $t_any_found = true;
            }
        }
        if ($t_any_found) {
            $t_desired_statuses = array();
        }
    }
    if (count($t_desired_statuses) > 0) {
        $t_clauses = array();
        foreach ($t_desired_statuses as $t_filter_member) {
            $c_show_status = db_prepare_int($t_filter_member);
            array_push($t_clauses, $c_show_status);
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.status in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.status={$t_clauses['0']} )");
        }
    }
    # resolution
    $t_any_found = false;
    foreach ($t_filter['show_resolution'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['show_resolution']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['show_resolution'] as $t_filter_member) {
            $c_show_resolution = db_prepare_int($t_filter_member);
            array_push($t_clauses, $c_show_resolution);
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.resolution in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.resolution={$t_clauses['0']} )");
        }
    }
    # priority
    $t_any_found = false;
    foreach ($t_filter['show_priority'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member || 0 === $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['show_priority']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['show_priority'] as $t_filter_member) {
            $c_show_priority = db_prepare_int($t_filter_member);
            array_push($t_clauses, $c_show_priority);
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.priority in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.priority={$t_clauses['0']} )");
        }
    }
    # product build
    $t_any_found = false;
    foreach ($t_filter['show_build'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member && is_numeric($t_filter_member)) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['show_build']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['show_build'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "''");
            } else {
                $c_show_build = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_show_build}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.build in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.build={$t_clauses['0']} )");
        }
    }
    # product version
    $t_any_found = false;
    foreach ($t_filter['show_version'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member && is_numeric($t_filter_member)) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['show_version']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['show_version'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "''");
            } else {
                $c_show_version = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_show_version}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.version in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.version={$t_clauses['0']} )");
        }
    }
    # profile
    $t_any_found = false;
    foreach ($t_filter['show_profile'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member && is_numeric($t_filter_member)) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['show_profile']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['show_profile'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "0");
            } else {
                $c_show_profile = db_prepare_int($t_filter_member);
                array_push($t_clauses, "{$c_show_profile}");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.profile_id in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.profile_id={$t_clauses['0']} )");
        }
    }
    # date filter
    if ('on' == $t_filter['do_filter_by_date'] && is_numeric($t_filter['start_month']) && is_numeric($t_filter['start_day']) && is_numeric($t_filter['start_year']) && is_numeric($t_filter['end_month']) && is_numeric($t_filter['end_day']) && is_numeric($t_filter['end_year'])) {
        $t_start_string = db_prepare_string($t_filter['start_year'] . "-" . $t_filter['start_month'] . "-" . $t_filter['start_day'] . " 00:00:00");
        $t_end_string = db_prepare_string($t_filter['end_year'] . "-" . $t_filter['end_month'] . "-" . $t_filter['end_day'] . " 23:59:59");
        array_push($t_where_clauses, "({$t_bug_table}.date_submitted BETWEEN '{$t_start_string}' AND '{$t_end_string}' )");
    }
    # fixed in version
    $t_any_found = false;
    foreach ($t_filter['fixed_in_version'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member && is_numeric($t_filter_member)) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['fixed_in_version']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['fixed_in_version'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "''");
            } else {
                $c_fixed_in_version = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_fixed_in_version}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.fixed_in_version in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.fixed_in_version={$t_clauses['0']} )");
        }
    }
    # users monitoring a bug
    $t_any_found = false;
    foreach ($t_filter['user_monitor'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member || 0 === $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['user_monitor']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        $t_table_name = 'user_monitor';
        array_push($t_from_clauses, $t_bug_monitor_table);
        array_push($t_join_clauses, "LEFT JOIN {$t_bug_monitor_table} {$t_table_name} ON {$t_table_name}.bug_id = {$t_bug_table}.id");
        foreach ($t_filter['user_monitor'] as $t_filter_member) {
            $c_user_monitor = db_prepare_int($t_filter_member);
            if (META_FILTER_MYSELF == $c_user_monitor) {
                array_push($t_clauses, $c_user_id);
            } else {
                array_push($t_clauses, $c_user_monitor);
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_table_name}.user_id in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_table_name}.user_id={$t_clauses['0']} )");
        }
    }
    # bug relationship
    $t_any_found = false;
    $c_rel_type = $t_filter['relationship_type'];
    $c_rel_bug = $t_filter['relationship_bug'];
    if (-1 == $c_rel_type || 0 == $c_rel_bug) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        # use the complementary type
        $c_rel_type = relationship_get_complementary_type($c_rel_type);
        $t_clauses = array();
        $t_table_name = 'relationship';
        array_push($t_from_clauses, $t_bug_relationship_table);
        array_push($t_join_clauses, "LEFT JOIN {$t_bug_relationship_table} {$t_table_name} ON {$t_table_name}.destination_bug_id = {$t_bug_table}.id");
        // get reverse relationships
        if ($c_rel_type == 1) {
            array_push($t_join_clauses, "LEFT JOIN {$t_bug_relationship_table} {$t_table_name}" . "2 ON {$t_table_name}" . "2.source_bug_id = {$t_bug_table}.id");
        }
        array_push($t_clauses, "({$t_table_name}.relationship_type='{$c_rel_type}' AND {$t_table_name}.source_bug_id='{$c_rel_bug}')");
        // get reverse relationships
        if ($c_rel_type == 1) {
            array_push($t_clauses, "({$t_table_name}" . "2.relationship_type='{$c_rel_type}' AND {$t_table_name}" . "2.destination_bug_id='{$c_rel_bug}')");
        }
        array_push($t_where_clauses, '(' . implode(' OR ', $t_clauses) . ')');
    }
    # custom field filters
    if (ON == config_get('filter_by_custom_fields')) {
        # custom field filtering
        $t_custom_fields = custom_field_get_linked_ids($t_project_id);
        foreach ($t_custom_fields as $t_cfid) {
            $t_first_time = true;
            $t_custom_where_clause = '';
            # Ignore all custom filters that are not set, or that are set to '' or "any"
            $t_any_found = false;
            foreach ($t_filter['custom_fields'][$t_cfid] as $t_filter_member) {
                if (META_FILTER_ANY == $t_filter_member && is_numeric($t_filter_member)) {
                    $t_any_found = true;
                }
            }
            if (!isset($t_filter['custom_fields'][$t_cfid])) {
                $t_any_found = true;
            }
            if (!$t_any_found) {
                $t_def = custom_field_get_definition($t_cfid);
                $t_table_name = $t_custom_field_string_table . '_' . $t_cfid;
                # We need to filter each joined table or the result query will explode in dimensions
                # Each custom field will result in a exponential growth like Number_of_Issues^Number_of_Custom_Fields
                # and only after this process ends (if it is able to) the result query will be filtered
                # by the WHERE clause and by the DISTINCT clause
                $t_cf_join_clause = "LEFT JOIN {$t_custom_field_string_table} {$t_table_name} ON {$t_table_name}.bug_id = {$t_bug_table}.id AND {$t_table_name}.field_id = {$t_cfid} ";
                if ($t_def['type'] == CUSTOM_FIELD_TYPE_DATE) {
                    switch ($t_filter['custom_fields'][$t_cfid][0]) {
                        case CUSTOM_FIELD_DATE_ANY:
                            break;
                        case CUSTOM_FIELD_DATE_NONE:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '(( ' . $t_table_name . '.bug_id is null) OR ( ' . $t_table_name . '.value = 0)';
                            break;
                        case CUSTOM_FIELD_DATE_BEFORE:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '(( ' . $t_table_name . '.value != 0 AND (' . $t_table_name . '.value+0) < ' . $t_filter['custom_fields'][$t_cfid][2] . ')';
                            break;
                        case CUSTOM_FIELD_DATE_AFTER:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '(( ' . $t_table_name . '.field_id = ' . $t_cfid . ' AND (' . $t_table_name . '.value+0) > ' . ($t_filter['custom_fields'][$t_cfid][1] + 1) . ')';
                            break;
                        default:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '(( ' . $t_table_name . '.field_id = ' . $t_cfid . ' AND (' . $t_table_name . '.value+0) BETWEEN ' . $t_filter['custom_fields'][$t_cfid][1] . ' AND ' . $t_filter['custom_fields'][$t_cfid][2] . ')';
                            break;
                    }
                } else {
                    array_push($t_join_clauses, $t_cf_join_clause);
                    foreach ($t_filter['custom_fields'][$t_cfid] as $t_filter_member) {
                        $t_filter_member = stripslashes($t_filter_member);
                        if (META_FILTER_NONE === $t_filter_member) {
                            # coerce filter value if selecting META_FILTER_NONE
                            $t_filter_member = '';
                        }
                        if ($t_first_time) {
                            $t_first_time = false;
                            $t_custom_where_clause = '(';
                        } else {
                            $t_custom_where_clause .= ' OR ';
                        }
                        $t_custom_where_clause .= "{$t_table_name}.value ";
                        switch ($t_def['type']) {
                            case CUSTOM_FIELD_TYPE_MULTILIST:
                            case CUSTOM_FIELD_TYPE_CHECKBOX:
                                $t_custom_where_clause .= "LIKE '%|";
                                $t_custom_where_clause_closing = "|%'";
                                break;
                            default:
                                $t_custom_where_clause .= "= '";
                                $t_custom_where_clause_closing = "'";
                        }
                        $t_custom_where_clause .= db_prepare_string($t_filter_member);
                        $t_custom_where_clause .= $t_custom_where_clause_closing;
                    }
                }
                if (!is_blank($t_custom_where_clause)) {
                    array_push($t_where_clauses, $t_custom_where_clause . ')');
                }
            }
        }
    }
    $t_textsearch_where_clause = '';
    $t_textsearch_wherejoin_clause = '';
    # Simple Text Search - Thanks to Alan Knowles
    if (!is_blank($t_filter['search'])) {
        $c_search = db_prepare_string($t_filter['search']);
        $c_search_int = db_prepare_int($t_filter['search']);
        $t_textsearch_where_clause = "((summary LIKE '%{$c_search}%')\n\t\t\t\t\t\t\t OR ({$t_bug_text_table}.description LIKE '%{$c_search}%')\n\t\t\t\t\t\t\t OR ({$t_bug_text_table}.steps_to_reproduce LIKE '%{$c_search}%')\n\t\t\t\t\t\t\t OR ({$t_bug_text_table}.additional_information LIKE '%{$c_search}%')\n\t\t\t\t\t\t\t OR ({$t_bug_table}.id = '{$c_search_int}'))";
        $t_textsearch_wherejoin_clause = "((summary LIKE '%{$c_search}%')\n\t\t\t\t\t\t\t OR ({$t_bug_text_table}.description LIKE '%{$c_search}%')\n\t\t\t\t\t\t\t OR ({$t_bug_text_table}.steps_to_reproduce LIKE '%{$c_search}%')\n\t\t\t\t\t\t\t OR ({$t_bug_text_table}.additional_information LIKE '%{$c_search}%')\n\t\t\t\t\t\t\t OR ({$t_bug_table}.id LIKE '%{$c_search}%')\n\t\t\t\t\t\t\t OR ({$t_bugnote_text_table}.note LIKE '%{$c_search}%'))";
        array_push($t_where_clauses, "({$t_bug_text_table}.id = {$t_bug_table}.bug_text_id)");
        $t_from_clauses = array($t_bug_text_table, $t_project_table, $t_bug_table);
    } else {
        $t_from_clauses = array($t_project_table, $t_bug_table);
    }
    $t_select = implode(', ', array_unique($t_select_clauses));
    $t_from = 'FROM ' . implode(', ', array_unique($t_from_clauses));
    $t_join = implode(' ', $t_join_clauses);
    if (count($t_where_clauses) > 0) {
        $t_where = 'WHERE ' . implode(' AND ', $t_where_clauses);
    } else {
        $t_where = '';
    }
    # Possibly do two passes. First time, grab the IDs of issues that match the filters. Second time, grab the IDs of issues that
    # have bugnotes that match the text search if necessary.
    $t_id_array = array();
    for ($i = 0; $i < 2; $i++) {
        $t_id_where = $t_where;
        $t_id_join = $t_join;
        if ($i == 0) {
            if (!is_blank($t_id_where) && !is_blank($t_textsearch_where_clause)) {
                $t_id_where = $t_id_where . ' AND ' . $t_textsearch_where_clause;
            }
        } else {
            if (!is_blank($t_textsearch_wherejoin_clause)) {
                $t_id_where = $t_id_where . ' AND ' . $t_textsearch_wherejoin_clause;
                $t_id_join = $t_id_join . " INNER JOIN {$t_bugnote_table} ON {$t_bugnote_table}.bug_id = {$t_bug_table}.id";
                $t_id_join = $t_id_join . " INNER JOIN {$t_bugnote_text_table} ON {$t_bugnote_text_table}.id = {$t_bugnote_table}.bugnote_text_id";
            }
        }
        $query = "SELECT DISTINCT {$t_bug_table}.id AS id\n\t\t\t\t\t\t{$t_from}\n\t\t\t\t\t\t{$t_id_join}\n\t\t\t\t\t\t{$t_id_where}";
        if ($i == 0 || !is_blank($t_textsearch_wherejoin_clause)) {
            $result = db_query($query);
            $row_count = db_num_rows($result);
            for ($j = 0; $j < $row_count; $j++) {
                $row = db_fetch_array($result);
                $t_id_array[] = db_prepare_int($row['id']);
            }
        }
    }
    $t_id_array = array_unique($t_id_array);
    if (count($t_id_array) > 0) {
        $t_where = "WHERE {$t_bug_table}.id in (" . implode(", ", $t_id_array) . ")";
    } else {
        $t_where = "WHERE 1 != 1";
    }
    $t_from = 'FROM ' . $t_bug_table;
    # Get the total number of bugs that meet the criteria.
    $bug_count = count($t_id_array);
    # write the value back in case the caller wants to know
    $p_bug_count = $bug_count;
    if (null === $p_per_page) {
        $p_per_page = (int) $t_filter['per_page'];
    } else {
        if (-1 == $p_per_page) {
            $p_per_page = $bug_count;
        }
    }
    # Guard against silly values of $f_per_page.
    if (0 == $p_per_page) {
        $p_per_page = 1;
    }
    $p_per_page = (int) abs($p_per_page);
    # Use $bug_count and $p_per_page to determine how many pages
    # to split this list up into.
    # For the sake of consistency have at least one page, even if it
    # is empty.
    $t_page_count = ceil($bug_count / $p_per_page);
    if ($t_page_count < 1) {
        $t_page_count = 1;
    }
    # write the value back in case the caller wants to know
    $p_page_count = $t_page_count;
    # Make sure $p_page_number isn't past the last page.
    if ($p_page_number > $t_page_count) {
        $p_page_number = $t_page_count;
    }
    # Make sure $p_page_number isn't before the first page
    if ($p_page_number < 1) {
        $p_page_number = 1;
    }
    # Now add the rest of the criteria i.e. sorting, limit.
    # if sort is blank then default the sort and direction.  This is to fix the
    # symptoms of #3953.  Note that even if the main problem is fixed, we may
    # have to keep this code for a while to handle filters saved with this blank field.
    if (is_blank($t_filter['sort'])) {
        $t_filter['sort'] = 'last_updated';
        $t_filter['dir'] = 'DESC';
    }
    $t_order_array = array();
    $t_sort_fields = split(',', $t_filter['sort']);
    $t_dir_fields = split(',', $t_filter['dir']);
    if ('on' == $t_filter['sticky_issues'] && NULL !== $p_show_sticky) {
        $t_order_array[] = "sticky DESC";
    }
    for ($i = 0; $i < count($t_sort_fields); $i++) {
        $c_sort = db_prepare_string($t_sort_fields[$i]);
        if (!in_array($t_sort_fields[$i], array_slice($t_sort_fields, $i + 1))) {
            # if sorting by a custom field
            if (strpos($c_sort, 'custom_') === 0) {
                $t_custom_field = substr($c_sort, strlen('custom_'));
                $t_custom_field_id = custom_field_get_id_from_name($t_custom_field);
                $t_join .= " LEFT JOIN {$t_custom_field_string_table} ON ( ( {$t_custom_field_string_table}.bug_id = {$t_bug_table}.id ) AND ( {$t_custom_field_string_table}.field_id = {$t_custom_field_id} ) )";
                $c_sort = "{$t_custom_field_string_table}.value";
                $t_select_clauses[] = "{$t_custom_field_string_table}.value";
            }
            if ('DESC' == $t_dir_fields[$i]) {
                $c_dir = 'DESC';
            } else {
                $c_dir = 'ASC';
            }
            $t_order_array[] = "{$c_sort} {$c_dir}";
        }
    }
    # add basic sorting if necessary
    if (!in_array('last_updated', $t_sort_fields)) {
        $t_order_array[] = 'last_updated DESC';
    }
    if (!in_array('date_submitted', $t_sort_fields)) {
        $t_order_array[] = 'date_submitted DESC';
    }
    $t_order = " ORDER BY " . implode(', ', $t_order_array);
    $t_select = implode(', ', array_unique($t_select_clauses));
    $query2 = "SELECT DISTINCT {$t_select}\n\t\t\t\t\t{$t_from}\n\t\t\t\t\t{$t_join}\n\t\t\t\t\t{$t_where}\n\t\t\t\t\t{$t_order}";
    # Figure out the offset into the db query
    #
    # for example page number 1, per page 5:
    #     t_offset = 0
    # for example page number 2, per page 5:
    #     t_offset = 5
    $c_per_page = db_prepare_int($p_per_page);
    $c_page_number = db_prepare_int($p_page_number);
    $t_offset = ($c_page_number - 1) * $c_per_page;
    # perform query
    $result2 = db_query($query2, $c_per_page, $t_offset);
    $row_count = db_num_rows($result2);
    $rows = array();
    for ($i = 0; $i < $row_count; $i++) {
        $row = db_fetch_array($result2);
        $row['date_submitted'] = db_unixtimestamp($row['date_submitted']);
        $row['last_updated'] = db_unixtimestamp($row['last_updated']);
        array_push($rows, $row);
        bug_add_to_cache($row);
    }
    return $rows;
}
Exemple #13
0
 function format_value($bug, $field_name)
 {
     $values = array('id' => function ($bug) {
         return sprintf('%s <%s>', $bug->id, string_get_bug_view_url_with_fqdn($bug->id));
     }, 'project_id' => function ($bug) {
         return project_get_name($bug->project_id);
     }, 'reporter_id' => function ($bug) {
         return '@' . user_get_name($bug->reporter_id);
     }, 'handler_id' => function ($bug) {
         return empty($bug->handler_id) ? plugin_lang_get('no_user') : '@' . user_get_name($bug->handler_id);
     }, 'duplicate_id' => function ($bug) {
         return sprintf('%s <%s>', $bug->duplicate_id, string_get_bug_view_url_with_fqdn($bug->duplicate_id));
     }, 'priority' => function ($bug) {
         return get_enum_element('priority', $bug->priority);
     }, 'severity' => function ($bug) {
         return get_enum_element('severity', $bug->severity);
     }, 'reproducibility' => function ($bug) {
         return get_enum_element('reproducibility', $bug->reproducibility);
     }, 'status' => function ($bug) {
         return get_enum_element('status', $bug->status);
     }, 'resolution' => function ($bug) {
         return get_enum_element('resolution', $bug->resolution);
     }, 'projection' => function ($bug) {
         return get_enum_element('projection', $bug->projection);
     }, 'category_id' => function ($bug) {
         return category_full_name($bug->category_id, false);
     }, 'eta' => function ($bug) {
         return get_enum_element('eta', $bug->eta);
     }, 'view_state' => function ($bug) {
         return $bug->view_state == VS_PRIVATE ? lang_get('private') : lang_get('public');
     }, 'sponsorship_total' => function ($bug) {
         return sponsorship_format_amount($bug->sponsorship_total);
     }, 'os' => function ($bug) {
         return $bug->os;
     }, 'os_build' => function ($bug) {
         return $bug->os_build;
     }, 'platform' => function ($bug) {
         return $bug->platform;
     }, 'version' => function ($bug) {
         return $bug->version;
     }, 'fixed_in_version' => function ($bug) {
         return $bug->fixed_in_version;
     }, 'target_version' => function ($bug) {
         return $bug->target_version;
     }, 'build' => function ($bug) {
         return $bug->build;
     }, 'summary' => function ($bug) {
         return HipChatPlugin::clean_summary(bug_format_summary($bug->id, SUMMARY_FIELD));
     }, 'last_updated' => function ($bug) {
         return date(config_get('short_date_format'), $bug->last_updated);
     }, 'date_submitted' => function ($bug) {
         return date(config_get('short_date_format'), $bug->date_submitted);
     }, 'due_date' => function ($bug) {
         return date(config_get('short_date_format'), $bug->due_date);
     }, 'description' => function ($bug) {
         return string_display_links($bug->description);
     }, 'steps_to_reproduce' => function ($bug) {
         return string_display_links($bug->steps_to_reproduce);
     }, 'additional_information' => function ($bug) {
         return string_display_links($bug->additional_information);
     });
     // Discover custom fields.
     $t_related_custom_field_ids = custom_field_get_linked_ids($bug->project_id);
     foreach ($t_related_custom_field_ids as $t_id) {
         $t_def = custom_field_get_definition($t_id);
         $values['custom_' . $t_def['name']] = function ($bug) use($t_id) {
             return custom_field_get_value($t_id, $bug->id);
         };
     }
     if (isset($values[$field_name])) {
         $func = $values[$field_name];
         return $func($bug);
     } else {
         return sprintf(plugin_lang_get('unknown_field'), $field_name);
     }
 }
Exemple #14
0
 function save_bug($p_project_id, $p_user_id)
 {
     require 'ProfileAcraExt.php';
     $t_project_id = $p_project_id;
     global $g_cache_current_user_id;
     $g_cache_current_user_id = $p_user_id;
     $t_bug_data = new BugData();
     $t_bug_data->project_id = $t_project_id;
     $t_bug_data->reporter_id = $p_user_id;
     $t_bug_data->build = gpc_get_string('APP_VERSION_CODE', '');
     $t_bug_data->platform = "Android";
     $t_bug_data->os = gpc_get_string('ANDROID_VERSION', '');
     //gpc_get_string( 'os', '' );
     $t_os_build = gpc_get_string('BUILD', '');
     if (preg_match('/DISPLAY\\s*=\\s*(.*)/', $t_os_build, $t_match)) {
         var_dump($t_match);
         $t_os_build = $t_match[1];
     } else {
         $t_os_build = gpc_get_string('ANDROID_VERSION', '');
     }
     $t_bug_data->os_build = $t_os_build;
     //gpc_get_string( 'os_build', '' );
     $t_bug_data->version = gpc_get_string('APP_VERSION_NAME', '');
     $t_bug_data->profile_id = profile_create_unique(ALL_USERS, $t_bug_data->platform, $t_bug_data->os, $t_bug_data->os_build, "");
     $t_bug_data->handler_id = gpc_get_int('handler_id', 0);
     $t_bug_data->view_state = gpc_get_int('view_state', config_get('default_bug_view_status', 'VS_PRIVATE', 'acra_reporter'));
     $t_bug_data->category_id = $this->get_category_id($p_project_id);
     //gpc_get_int( 'category_id', 0 );
     $t_bug_data->reproducibility = 10;
     //gpc_get_int( 'reproducibility', config_get( 'default_bug_reproducibility' ) );
     $t_bug_data->severity = CRASH;
     //gpc_get_int( 'severity', config_get( 'default_bug_severity' ) );
     $t_bug_data->priority = HIGH;
     //gpc_get_int( 'priority', config_get( 'default_bug_priority' ) );
     $t_bug_data->projection = gpc_get_int('projection', config_get('default_bug_projection'));
     $t_bug_data->eta = gpc_get_int('eta', config_get('default_bug_eta'));
     $t_bug_data->resolution = OPEN;
     //gpc_get_string('resolution', config_get( 'default_bug_resolution' ) );
     $t_bug_data->status = NEW_;
     //gpc_get_string( 'status', config_get( 'bug_submit_status' ) );
     $t_bug_data->description = gpc_get_string('STACK_TRACE');
     //gpc_get_string( 'description' );
     $t_bug_data->summary = get_bug_summary_by_version(gpc_get_string('APP_VERSION_NAME', ''), $t_bug_data->description, $t_project_id);
     $t_bug_data->steps_to_reproduce = gpc_get_string('LOGCAT', "");
     $t_bug_data->additional_information = gpc_get_string('CRASH_CONFIGURATION', "");
     $t_bug_data->due_date = gpc_get_string('USER_CRASH_DATE', '');
     if (is_blank($t_bug_data->due_date)) {
         $t_bug_data->due_date = date_get_null();
     }
     $f_files = gpc_get_file('ufile', null);
     /** @todo (thraxisp) Note that this always returns a structure */
     $f_report_stay = gpc_get_bool('report_stay', false);
     $f_copy_notes_from_parent = gpc_get_bool('copy_notes_from_parent', false);
     helper_call_custom_function('issue_create_validate', array($t_bug_data));
     # Validate the custom fields before adding the bug.
     $t_related_custom_field_ids = custom_field_get_linked_ids($t_bug_data->project_id);
     foreach ($t_related_custom_field_ids as $t_id) {
         $t_def = custom_field_get_definition($t_id);
         # Produce an error if the field is required but wasn't posted
         if (!gpc_isset_custom_field($t_id, $t_def['type']) && $t_def['require_report']) {
             error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
             trigger_error(ERROR_EMPTY_FIELD, ERROR);
         }
         if (!custom_field_validate($t_id, gpc_get_custom_field("custom_field_{$t_id}", $t_def['type'], NULL))) {
             error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
             trigger_error(ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR);
         }
     }
     # Allow plugins to pre-process bug data
     $t_bug_data = event_signal('EVENT_REPORT_BUG_DATA', $t_bug_data);
     # Ensure that resolved bugs have a handler
     if ($t_bug_data->handler_id == NO_USER && $t_bug_data->status >= config_get('bug_resolved_status_threshold')) {
         $t_bug_data->handler_id = $this->get_user_id();
     }
     # Create the bug
     $t_bug_id = $t_bug_data->create();
     # Mark the added issue as visited so that it appears on the last visited list.
     last_visited_issue($t_bug_id);
     # Handle the file upload
     if ($f_files != null) {
         $t_files = helper_array_transpose($f_files);
         if ($t_files != null) {
             foreach ($t_files as $t_file) {
                 if (!empty($t_file['name'])) {
                     file_add($t_bug_id, $t_file, 'bug');
                 }
             }
         }
     }
     # Handle custom field submission
     foreach ($t_related_custom_field_ids as $t_id) {
         # Do not set custom field value if user has no write access
         if (!custom_field_has_write_access($t_id, $t_bug_id)) {
             continue;
         }
         $t_def = custom_field_get_definition($t_id);
         if (!custom_field_set_value($t_id, $t_bug_id, gpc_get_custom_field("custom_field_{$t_id}", $t_def['type'], $t_def['default_value']), false)) {
             error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name')));
             trigger_error(ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR);
         }
     }
     $f_master_bug_id = gpc_get_int('m_id', 0);
     $f_rel_type = gpc_get_int('rel_type', -1);
     if ($f_master_bug_id > 0) {
         # it's a child generation... let's create the relationship and add some lines in the history
         # update master bug last updated
         bug_update_date($f_master_bug_id);
         # Add log line to record the cloning action
         history_log_event_special($t_bug_id, BUG_CREATED_FROM, '', $f_master_bug_id);
         history_log_event_special($f_master_bug_id, BUG_CLONED_TO, '', $t_bug_id);
         if ($f_rel_type >= 0) {
             # Add the relationship
             relationship_add($t_bug_id, $f_master_bug_id, $f_rel_type);
             # Add log line to the history (both issues)
             history_log_event_special($f_master_bug_id, BUG_ADD_RELATIONSHIP, relationship_get_complementary_type($f_rel_type), $t_bug_id);
             history_log_event_special($t_bug_id, BUG_ADD_RELATIONSHIP, $f_rel_type, $f_master_bug_id);
             # update relationship target bug last updated
             bug_update_date($t_bug_id);
             # Send the email notification
             email_relationship_added($f_master_bug_id, $t_bug_id, relationship_get_complementary_type($f_rel_type));
         }
         # copy notes from parent
         if ($f_copy_notes_from_parent) {
             $t_parent_bugnotes = bugnote_get_all_bugnotes($f_master_bug_id);
             foreach ($t_parent_bugnotes as $t_parent_bugnote) {
                 $t_private = $t_parent_bugnote->view_state == VS_PRIVATE;
                 bugnote_add($t_bug_id, $t_parent_bugnote->note, $t_parent_bugnote->time_tracking, $t_private, $t_parent_bugnote->note_type, $t_parent_bugnote->note_attr, $t_parent_bugnote->reporter_id, FALSE, FALSE);
             }
         }
     }
     helper_call_custom_function('issue_create_notify', array($t_bug_id));
     # Allow plugins to post-process bug data with the new bug ID
     event_signal('EVENT_REPORT_BUG', array($t_bug_data, $t_bug_id));
     email_new_bug($t_bug_id);
     // log status and resolution changes if they differ from the default
     if ($t_bug_data->status != config_get('bug_submit_status')) {
         history_log_event($t_bug_id, 'status', config_get('bug_submit_status'));
     }
     if ($t_bug_data->resolution != config_get('default_bug_resolution')) {
         history_log_event($t_bug_id, 'resolution', config_get('default_bug_resolution'));
     }
     return $t_bug_id;
 }
Exemple #15
0
/**
 * Get the custom field values associated with the specified issue id.
 *
 * @param integer $p_issue_id Issue id to get the custom field values for.
 *
 * @return null if no custom field defined for the project that contains the issue, or if no custom
 *              fields are accessible to the current user.
 */
function mci_issue_get_custom_fields($p_issue_id)
{
    $t_project_id = bug_get_field($p_issue_id, 'project_id');
    $t_custom_fields = array();
    $t_related_custom_field_ids = custom_field_get_linked_ids($t_project_id);
    foreach ($t_related_custom_field_ids as $t_id) {
        $t_def = custom_field_get_definition($t_id);
        if (custom_field_has_read_access($t_id, $p_issue_id)) {
            # user has not access to read this custom field.
            $t_value = custom_field_get_value($t_id, $p_issue_id);
            if ($t_value === false) {
                continue;
            }
            # return a blank string if the custom field value is undefined
            if ($t_value === null) {
                $t_value = '';
            }
            $t_custom_field_value = array();
            $t_custom_field_value['field'] = array();
            $t_custom_field_value['field']['id'] = $t_id;
            $t_custom_field_value['field']['name'] = $t_def['name'];
            $t_custom_field_value['value'] = $t_value;
            $t_custom_fields[] = $t_custom_field_value;
        }
    }
    return count($t_custom_fields) == 0 ? null : $t_custom_fields;
}
Exemple #16
0
function ERP_custom_function_print_custom_fields($p_name, $p_sel_value)
{
    # Custom Fields
    $t_custom_fields = custom_field_get_ids();
    foreach ($t_custom_fields as $t_field_id) {
        $t_def = custom_field_get_definition($t_field_id);
        echo '<tr ' . helper_alternate_class() . '><td class="category">';
        ERP_print_documentation_link($p_name);
        echo ': ' . string_display(lang_get_defaulted($t_def['name'])) . '</td>';
        echo '<td class="center" colspan="2">';
        ERP_print_custom_field_input(is_array($p_sel_value) && isset($p_sel_value[$t_field_id]) ? $p_sel_value[$t_field_id] : NULL, $t_def);
        echo '</td></tr>';
    }
}
Exemple #17
0
/**
 * Print the value of the custom field (if the field is applicable to the project of
 * the specified issue and the current user has read access to it.
 * see custom_function_default_print_column_title() for rules about column names.
 * @param string  $p_column         Name of field to show in the column.
 * @param BugData $p_bug            Bug object.
 * @param integer $p_columns_target See COLUMNS_TARGET_* in constant_inc.php.
 * @return void
 */
function custom_function_default_print_column_value($p_column, BugData $p_bug, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE)
{
    if (COLUMNS_TARGET_CSV_PAGE == $p_columns_target) {
        $t_column_start = '';
        $t_column_end = '';
        $t_column_empty = '';
    } else {
        $t_column_start = '<td class="column-%s">';
        $t_column_end = '</td>';
        $t_column_empty = '&#160;';
    }
    $t_custom_field = column_get_custom_field_name($p_column);
    if ($t_custom_field !== null) {
        printf($t_column_start, 'custom-' . $t_custom_field);
        $t_field_id = custom_field_get_id_from_name($t_custom_field);
        if ($t_field_id === false) {
            echo '@', $t_custom_field, '@';
        } else {
            $t_issue_id = $p_bug->id;
            $t_project_id = $p_bug->project_id;
            if (custom_field_is_linked($t_field_id, $t_project_id)) {
                $t_def = custom_field_get_definition($t_field_id);
                print_custom_field_value($t_def, $t_field_id, $t_issue_id);
            } else {
                # field is not linked to project
                echo $t_column_empty;
            }
        }
        echo $t_column_end;
    } else {
        $t_plugin_columns = columns_get_plugin_columns();
        if ($p_columns_target != COLUMNS_TARGET_CSV_PAGE) {
            $t_function = 'print_column_' . $p_column;
        } else {
            $t_function = 'csv_format_' . $p_column;
        }
        if (function_exists($t_function)) {
            if ($p_columns_target != COLUMNS_TARGET_CSV_PAGE) {
                $t_function($p_bug, $p_columns_target);
            } else {
                $t_function($p_bug);
            }
        } else {
            if (isset($t_plugin_columns[$p_column])) {
                $t_column_object = $t_plugin_columns[$p_column];
                print_column_plugin($t_column_object, $p_bug, $p_columns_target);
            } else {
                printf($t_column_start, $p_column);
                if (isset($p_bug->{$p_column})) {
                    echo string_display_line($p_bug->{$p_column}) . $t_column_end;
                } else {
                    echo '@' . $p_column . '@' . $t_column_end;
                }
            }
        }
    }
}
/**
 * @todo Had to make all these parameters required because we can't use
 *  call-time pass by reference anymore.  I really preferred not having
 *  to pass all the params in if you didn't want to, but I wanted to get
 *  rid of the errors for now.  If we can think of a better way later
 *  (maybe return an object) that would be great.
 *
 * @param int $p_page_number the page you want to see (set to the actual page on return)
 * @param int $p_per_page the number of bugs to see per page (set to actual on return)
 *      -1   indicates you want to see all bugs
 *      null indicates you want to use the value specified in the filter
 * @param int $p_page_count you don't need to give a value here, the number of pages will be stored here on return
 * @param int $p_bug_count you don't need to give a value here, the number of bugs will be stored here on return
 * @param mixed $p_custom_filter Filter to use.
 * @param int $p_project_id project id to use in filtering.
 * @param int $p_user_id user id to use as current user when filtering.
 * @param bool $p_show_sticky get sticky issues only.
 */
function filter_get_bug_rows(&$p_page_number, &$p_per_page, &$p_page_count, &$p_bug_count, $p_custom_filter = null, $p_project_id = null, $p_user_id = null, $p_show_sticky = null)
{
    log_event(LOG_FILTERING, 'START NEW FILTER QUERY');
    $t_bug_table = db_get_table('mantis_bug_table');
    $t_bug_text_table = db_get_table('mantis_bug_text_table');
    $t_bugnote_table = db_get_table('mantis_bugnote_table');
    $t_category_table = db_get_table('mantis_category_table');
    $t_custom_field_string_table = db_get_table('mantis_custom_field_string_table');
    $t_bugnote_text_table = db_get_table('mantis_bugnote_text_table');
    $t_project_table = db_get_table('mantis_project_table');
    $t_bug_monitor_table = db_get_table('mantis_bug_monitor_table');
    $t_limit_reporters = config_get('limit_reporters');
    $t_bug_relationship_table = db_get_table('mantis_bug_relationship_table');
    $t_report_bug_threshold = config_get('report_bug_threshold');
    $t_where_param_count = 0;
    $t_current_user_id = auth_get_current_user_id();
    if (null === $p_user_id) {
        $t_user_id = $t_current_user_id;
    } else {
        $t_user_id = $p_user_id;
    }
    $c_user_id = db_prepare_int($t_user_id);
    if (null === $p_project_id) {
        # @@@ If project_id is not specified, then use the project id(s) in the filter if set, otherwise, use current project.
        $t_project_id = helper_get_current_project();
    } else {
        $t_project_id = $p_project_id;
    }
    if ($p_custom_filter === null) {
        # Prefer current_user_get_bug_filter() over user_get_filter() when applicable since it supports
        # cookies set by previous version of the code.
        if ($t_user_id == $t_current_user_id) {
            $t_filter = current_user_get_bug_filter();
        } else {
            $t_filter = user_get_bug_filter($t_user_id, $t_project_id);
        }
    } else {
        $t_filter = $p_custom_filter;
    }
    $t_filter = filter_ensure_valid_filter($t_filter);
    if (false === $t_filter) {
        return false;
        # signify a need to create a cookie
        # @@@ error instead?
    }
    $t_view_type = $t_filter['_view_type'];
    $t_where_clauses = array("{$t_project_table}.enabled = " . db_param(), "{$t_project_table}.id = {$t_bug_table}.project_id");
    $t_where_params = array(1);
    $t_select_clauses = array("{$t_bug_table}.*");
    $t_join_clauses = array();
    $t_from_clauses = array();
    // normalize the project filtering into an array $t_project_ids
    if ('simple' == $t_view_type) {
        log_event(LOG_FILTERING, 'Simple Filter');
        $t_project_ids = array($t_project_id);
        $t_include_sub_projects = true;
    } else {
        log_event(LOG_FILTERING, 'Advanced Filter');
        if (!is_array($t_filter[FILTER_PROPERTY_PROJECT_ID])) {
            $t_project_ids = array(db_prepare_int($t_filter[FILTER_PROPERTY_PROJECT_ID]));
        } else {
            $t_project_ids = array_map('db_prepare_int', $t_filter[FILTER_PROPERTY_PROJECT_ID]);
        }
        $t_include_sub_projects = count($t_project_ids) == 1 && ($t_project_ids[0] == META_FILTER_CURRENT || $t_project_ids[0] == ALL_PROJECTS);
    }
    log_event(LOG_FILTERING, 'project_ids = @P' . implode(', @P', $t_project_ids));
    log_event(LOG_FILTERING, 'include sub-projects = ' . ($t_include_sub_projects ? '1' : '0'));
    // if the array has ALL_PROJECTS, then reset the array to only contain ALL_PROJECTS.
    // replace META_FILTER_CURRENT with the actualy current project id.
    $t_all_projects_found = false;
    $t_new_project_ids = array();
    foreach ($t_project_ids as $t_pid) {
        if ($t_pid == META_FILTER_CURRENT) {
            $t_pid = $t_project_id;
        }
        if ($t_pid == ALL_PROJECTS) {
            $t_all_projects_found = true;
            log_event(LOG_FILTERING, 'all projects selected');
            break;
        }
        // filter out inaccessible projects.
        if (!access_has_project_level(VIEWER, $t_pid, $t_user_id)) {
            continue;
        }
        $t_new_project_ids[] = $t_pid;
    }
    $t_projects_query_required = true;
    if ($t_all_projects_found) {
        if (user_is_administrator($t_user_id)) {
            log_event(LOG_FILTERING, 'all projects + administrator, hence no project filter.');
            $t_projects_query_required = false;
        } else {
            $t_project_ids = user_get_accessible_projects($t_user_id);
        }
    } else {
        $t_project_ids = $t_new_project_ids;
    }
    if ($t_projects_query_required) {
        // expand project ids to include sub-projects
        if ($t_include_sub_projects) {
            $t_top_project_ids = $t_project_ids;
            foreach ($t_top_project_ids as $t_pid) {
                log_event(LOG_FILTERING, 'Getting sub-projects for project id @P' . $t_pid);
                $t_subproject_ids = user_get_all_accessible_subprojects($t_user_id, $t_pid);
                if (!$t_subproject_ids) {
                    continue;
                }
                $t_project_ids = array_merge($t_project_ids, $t_subproject_ids);
            }
            $t_project_ids = array_unique($t_project_ids);
        }
        // if no projects are accessible, then return an empty array.
        if (count($t_project_ids) == 0) {
            log_event(LOG_FILTERING, 'no accessible projects');
            return array();
        }
        log_event(LOG_FILTERING, 'project_ids after including sub-projects = @P' . implode(', @P', $t_project_ids));
        // this array is to be populated with project ids for which we only want to show public issues.  This is due to the limited
        // access of the current user.
        $t_public_only_project_ids = array();
        // this array is populated with project ids that the current user has full access to.
        $t_private_and_public_project_ids = array();
        foreach ($t_project_ids as $t_pid) {
            $t_access_required_to_view_private_bugs = config_get('private_bug_threshold', null, null, $t_pid);
            if (access_has_project_level($t_access_required_to_view_private_bugs, $t_pid, $t_user_id)) {
                $t_private_and_public_project_ids[] = $t_pid;
            } else {
                $t_public_only_project_ids[] = $t_pid;
            }
        }
        log_event(LOG_FILTERING, 'project_ids (with public/private access) = @P' . implode(', @P', $t_private_and_public_project_ids));
        log_event(LOG_FILTERING, 'project_ids (with public access) = @P' . implode(', @P', $t_public_only_project_ids));
        $t_count_private_and_public_project_ids = count($t_private_and_public_project_ids);
        if ($t_count_private_and_public_project_ids == 1) {
            $t_private_and_public_query = "( {$t_bug_table}.project_id = " . $t_private_and_public_project_ids[0] . " )";
        } else {
            if ($t_count_private_and_public_project_ids > 1) {
                $t_private_and_public_query = "( {$t_bug_table}.project_id in (" . implode(', ', $t_private_and_public_project_ids) . ") )";
            } else {
                $t_private_and_public_query = null;
            }
        }
        $t_count_public_only_project_ids = count($t_public_only_project_ids);
        $t_public_view_state_check = "( ( {$t_bug_table}.view_state = " . VS_PUBLIC . " ) OR ( {$t_bug_table}.reporter_id = {$t_user_id} ) )";
        if ($t_count_public_only_project_ids == 1) {
            $t_public_only_query = "( ( {$t_bug_table}.project_id = " . $t_public_only_project_ids[0] . " ) AND {$t_public_view_state_check} )";
        } else {
            if ($t_count_public_only_project_ids > 1) {
                $t_public_only_query = "( ( {$t_bug_table}.project_id in (" . implode(', ', $t_public_only_project_ids) . ") ) AND {$t_public_view_state_check} )";
            } else {
                $t_public_only_query = null;
            }
        }
        // both queries can't be null, so we either have one of them or both.
        if ($t_private_and_public_query === null) {
            $t_project_query = $t_public_only_query;
        } else {
            if ($t_public_only_query === null) {
                $t_project_query = $t_private_and_public_query;
            } else {
                $t_project_query = "( {$t_public_only_query} OR {$t_private_and_public_query} )";
            }
        }
        log_event(LOG_FILTERING, 'project query = ' . $t_project_query);
        array_push($t_where_clauses, $t_project_query);
    }
    # view state
    $t_view_state = db_prepare_int($t_filter[FILTER_PROPERTY_VIEW_STATE_ID]);
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_VIEW_STATE_ID])) {
        $t_view_state_query = "({$t_bug_table}.view_state=" . db_param() . ')';
        log_event(LOG_FILTERING, 'view_state query = ' . $t_view_state_query);
        $t_where_params[] = $t_view_state;
        array_push($t_where_clauses, $t_view_state_query);
    } else {
        log_event(LOG_FILTERING, 'no view_state query');
    }
    # reporter
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_REPORTER_ID])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_REPORTER_ID] as $t_filter_member) {
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, "0");
            } else {
                $c_reporter_id = db_prepare_int($t_filter_member);
                if (filter_field_is_myself($c_reporter_id)) {
                    array_push($t_clauses, $c_user_id);
                } else {
                    array_push($t_clauses, $c_reporter_id);
                }
            }
        }
        if (1 < count($t_clauses)) {
            $t_reporter_query = "( {$t_bug_table}.reporter_id in (" . implode(', ', $t_clauses) . ") )";
        } else {
            $t_reporter_query = "( {$t_bug_table}.reporter_id={$t_clauses['0']} )";
        }
        log_event(LOG_FILTERING, 'reporter query = ' . $t_reporter_query);
        array_push($t_where_clauses, $t_reporter_query);
    } else {
        log_event(LOG_FILTERING, 'no reporter query');
    }
    # limit reporter
    # @@@ thraxisp - access_has_project_level checks greater than or equal to,
    #   this assumed that there aren't any holes above REPORTER where the limit would apply
    #
    if (ON === $t_limit_reporters && !access_has_project_level(REPORTER + 1, $t_project_id, $t_user_id)) {
        $c_reporter_id = $c_user_id;
        $t_where_params[] = $c_reporter_id;
        array_push($t_where_clauses, "({$t_bug_table}.reporter_id=" . db_param() . ')');
    }
    # handler
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_HANDLER_ID])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_HANDLER_ID] as $t_filter_member) {
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, 0);
            } else {
                $c_handler_id = db_prepare_int($t_filter_member);
                if (filter_field_is_myself($c_handler_id)) {
                    array_push($t_clauses, $c_user_id);
                } else {
                    array_push($t_clauses, $c_handler_id);
                }
            }
        }
        if (1 < count($t_clauses)) {
            $t_handler_query = "( {$t_bug_table}.handler_id in (" . implode(', ', $t_clauses) . ") )";
        } else {
            $t_handler_query = "( {$t_bug_table}.handler_id={$t_clauses['0']} )";
        }
        log_event(LOG_FILTERING, 'handler query = ' . $t_handler_query);
        array_push($t_where_clauses, $t_handler_query);
    } else {
        log_event(LOG_FILTERING, 'no handler query');
    }
    # category
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_CATEGORY])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_CATEGORY] as $t_filter_member) {
            if (!filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, $t_filter_member);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, "( {$t_bug_table}.category_id in ( SELECT id FROM {$t_category_table} WHERE name in (" . implode(', ', $t_where_tmp) . ") ) )");
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, "( {$t_bug_table}.category_id in ( SELECT id FROM {$t_category_table} WHERE name=" . db_param() . ") )");
        }
    }
    # severity
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_SEVERITY_ID])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_SEVERITY_ID] as $t_filter_member) {
            $c_show_severity = db_prepare_int($t_filter_member);
            array_push($t_clauses, $c_show_severity);
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, "( {$t_bug_table}.severity in (" . implode(', ', $t_where_tmp) . ") )");
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, "( {$t_bug_table}.severity=" . db_param() . " )");
        }
    }
    # show / hide status
    # take a list of all available statuses then remove the ones that we want hidden, then make sure
    # the ones we want shown are still available
    $t_desired_statuses = array();
    $t_available_statuses = MantisEnum::getValues(config_get('status_enum_string'));
    if ('simple' == $t_filter['_view_type']) {
        # simple filtering: if showing any, restrict by the hide status value, otherwise ignore the hide
        $t_any_found = false;
        $t_this_status = $t_filter[FILTER_PROPERTY_STATUS_ID][0];
        $t_this_hide_status = $t_filter[FILTER_PROPERTY_HIDE_STATUS_ID][0];
        if (filter_field_is_any($t_this_status)) {
            foreach ($t_available_statuses as $t_this_available_status) {
                if ($t_this_hide_status > $t_this_available_status) {
                    $t_desired_statuses[] = $t_this_available_status;
                }
            }
        } else {
            $t_desired_statuses[] = $t_this_status;
        }
    } else {
        # advanced filtering: ignore the hide
        if (filter_field_is_any($t_filter[FILTER_PROPERTY_STATUS_ID])) {
            $t_desired_statuses = array();
        } else {
            foreach ($t_filter[FILTER_PROPERTY_STATUS_ID] as $t_this_status) {
                $t_desired_statuses[] = $t_this_status;
            }
        }
    }
    if (count($t_desired_statuses) > 0) {
        $t_clauses = array();
        foreach ($t_desired_statuses as $t_filter_member) {
            $c_show_status = db_prepare_int($t_filter_member);
            array_push($t_clauses, $c_show_status);
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, "( {$t_bug_table}.status in (" . implode(', ', $t_where_tmp) . ") )");
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, "( {$t_bug_table}.status=" . db_param() . " )");
        }
    }
    # resolution
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_RESOLUTION_ID])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_RESOLUTION_ID] as $t_filter_member) {
            $c_show_resolution = db_prepare_int($t_filter_member);
            array_push($t_clauses, $c_show_resolution);
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, "( {$t_bug_table}.resolution in (" . implode(', ', $t_where_tmp) . ") )");
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, "( {$t_bug_table}.resolution=" . db_param() . " )");
        }
    }
    # priority
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_PRIORITY_ID])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_PRIORITY_ID] as $t_filter_member) {
            $c_show_priority = db_prepare_int($t_filter_member);
            array_push($t_clauses, $c_show_priority);
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, "( {$t_bug_table}.priority in (" . implode(', ', $t_where_tmp) . ") )");
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, "( {$t_bug_table}.priority=" . db_param() . " )");
        }
    }
    # product build
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_PRODUCT_BUILD])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_PRODUCT_BUILD] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, '');
            } else {
                $c_show_build = db_prepare_string($t_filter_member);
                array_push($t_clauses, $c_show_build);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, "( {$t_bug_table}.build in (" . implode(', ', $t_where_tmp) . ") )");
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, "( {$t_bug_table}.build=" . db_param() . " )");
        }
    }
    # product version
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_PRODUCT_VERSION])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_PRODUCT_VERSION] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, '');
            } else {
                $c_show_version = db_prepare_string($t_filter_member);
                array_push($t_clauses, $c_show_version);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, "( {$t_bug_table}.version in (" . implode(', ', $t_where_tmp) . ") )");
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, "( {$t_bug_table}.version=" . db_param() . " )");
        }
    }
    # profile
    if (!filter_field_is_any($t_filter['show_profile'])) {
        $t_clauses = array();
        foreach ($t_filter['show_profile'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, "0");
            } else {
                $c_show_profile = db_prepare_int($t_filter_member);
                array_push($t_clauses, "{$c_show_profile}");
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, "( {$t_bug_table}.profile_id in (" . implode(', ', $t_where_tmp) . ") )");
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, "( {$t_bug_table}.profile_id=" . db_param() . " )");
        }
    }
    # platform
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_PLATFORM])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_PLATFORM] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, '');
            } else {
                $c_platform = db_prepare_string($t_filter_member);
                array_push($t_clauses, $c_platform);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, "( {$t_bug_table}.platform in (" . implode(', ', $t_where_tmp) . ") )");
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, "( {$t_bug_table}.platform = " . db_param() . " )");
        }
    }
    # os
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_OS])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_OS] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, '');
            } else {
                $c_os = db_prepare_string($t_filter_member);
                array_push($t_clauses, $c_os);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, "( {$t_bug_table}.os in (" . implode(', ', $t_where_tmp) . ") )");
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, "( {$t_bug_table}.os = " . db_param() . " )");
        }
    }
    # os_build
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_OS_BUILD])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_OS_BUILD] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, '');
            } else {
                $c_os_build = db_prepare_string($t_filter_member);
                array_push($t_clauses, $c_os_build);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, "( {$t_bug_table}.os_build in (" . implode(', ', $t_where_tmp) . ") )");
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, "( {$t_bug_table}.os_build = " . db_param() . " )");
        }
    }
    # date filter
    if ('on' == $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] && is_numeric($t_filter[FILTER_PROPERTY_START_MONTH]) && is_numeric($t_filter[FILTER_PROPERTY_START_DAY]) && is_numeric($t_filter[FILTER_PROPERTY_START_YEAR]) && is_numeric($t_filter[FILTER_PROPERTY_END_MONTH]) && is_numeric($t_filter[FILTER_PROPERTY_END_DAY]) && is_numeric($t_filter[FILTER_PROPERTY_END_YEAR])) {
        $t_start_string = $t_filter[FILTER_PROPERTY_START_YEAR] . "-" . $t_filter[FILTER_PROPERTY_START_MONTH] . "-" . $t_filter[FILTER_PROPERTY_START_DAY] . " 00:00:00";
        $t_end_string = $t_filter[FILTER_PROPERTY_END_YEAR] . "-" . $t_filter[FILTER_PROPERTY_END_MONTH] . "-" . $t_filter[FILTER_PROPERTY_END_DAY] . " 23:59:59";
        $t_where_params[] = strtotime($t_start_string);
        $t_where_params[] = strtotime($t_end_string);
        array_push($t_where_clauses, "({$t_bug_table}.date_submitted BETWEEN " . db_param() . " AND " . db_param() . " )");
    }
    # fixed in version
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_FIXED_IN_VERSION])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_FIXED_IN_VERSION] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, '');
            } else {
                $c_fixed_in_version = db_prepare_string($t_filter_member);
                array_push($t_clauses, $c_fixed_in_version);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, "( {$t_bug_table}.fixed_in_version in (" . implode(', ', $t_where_tmp) . ") )");
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, "( {$t_bug_table}.fixed_in_version=" . db_param() . " )");
        }
    }
    # target version
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_TARGET_VERSION])) {
        $t_clauses = array();
        foreach ($t_filter[FILTER_PROPERTY_TARGET_VERSION] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (filter_field_is_none($t_filter_member)) {
                array_push($t_clauses, '');
            } else {
                $c_target_version = db_prepare_string($t_filter_member);
                array_push($t_clauses, $c_target_version);
            }
        }
        # echo var_dump( $t_clauses ); exit;
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, "( {$t_bug_table}.target_version in (" . implode(', ', $t_where_tmp) . ") )");
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, "( {$t_bug_table}.target_version=" . db_param() . " )");
        }
    }
    # users monitoring a bug
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_MONITOR_USER_ID])) {
        $t_clauses = array();
        $t_table_name = 'user_monitor';
        array_push($t_join_clauses, "LEFT JOIN {$t_bug_monitor_table} {$t_table_name} ON {$t_table_name}.bug_id = {$t_bug_table}.id");
        foreach ($t_filter[FILTER_PROPERTY_MONITOR_USER_ID] as $t_filter_member) {
            $c_user_monitor = db_prepare_int($t_filter_member);
            if (filter_field_is_myself($c_user_monitor)) {
                array_push($t_clauses, $c_user_id);
            } else {
                array_push($t_clauses, $c_user_monitor);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, "( {$t_table_name}.user_id in (" . implode(', ', $t_where_tmp) . ") )");
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, "( {$t_table_name}.user_id=" . db_param() . " )");
        }
    }
    # bug relationship
    $t_any_found = false;
    $c_rel_type = $t_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE];
    $c_rel_bug = $t_filter[FILTER_PROPERTY_RELATIONSHIP_BUG];
    if (-1 == $c_rel_type || 0 == $c_rel_bug) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        # use the complementary type
        $t_comp_type = relationship_get_complementary_type($c_rel_type);
        $t_clauses = array();
        $t_table_name = 'relationship';
        array_push($t_join_clauses, "LEFT JOIN {$t_bug_relationship_table} {$t_table_name} ON {$t_table_name}.destination_bug_id = {$t_bug_table}.id");
        array_push($t_join_clauses, "LEFT JOIN {$t_bug_relationship_table} {$t_table_name}2 ON {$t_table_name}2.source_bug_id = {$t_bug_table}.id");
        // get reverse relationships
        $t_where_params[] = $t_comp_type;
        $t_where_params[] = $c_rel_bug;
        $t_where_params[] = $c_rel_type;
        $t_where_params[] = $c_rel_bug;
        array_push($t_clauses, "({$t_table_name}.relationship_type=" . db_param() . " AND {$t_table_name}.source_bug_id=" . db_param() . ')');
        array_push($t_clauses, "({$t_table_name}" . "2.relationship_type=" . db_param() . " AND {$t_table_name}" . "2.destination_bug_id=" . db_param() . ')');
        array_push($t_where_clauses, '(' . implode(' OR ', $t_clauses) . ')');
    }
    # tags
    $c_tag_string = trim($t_filter[FILTER_PROPERTY_TAG_STRING]);
    $c_tag_select = trim($t_filter[FILTER_PROPERTY_TAG_SELECT]);
    if (is_blank($c_tag_string) && !is_blank($c_tag_select) && $c_tag_select != 0) {
        $t_tag = tag_get($c_tag_select);
        $c_tag_string = $t_tag['name'];
    }
    if (!is_blank($c_tag_string)) {
        $t_tags = tag_parse_filters($c_tag_string);
        if (count($t_tags)) {
            $t_tags_all = array();
            $t_tags_any = array();
            $t_tags_none = array();
            foreach ($t_tags as $t_tag_row) {
                switch ($t_tag_row['filter']) {
                    case 1:
                        $t_tags_all[] = $t_tag_row;
                        break;
                    case 0:
                        $t_tags_any[] = $t_tag_row;
                        break;
                    case -1:
                        $t_tags_none[] = $t_tag_row;
                        break;
                }
            }
            if (0 < $t_filter[FILTER_PROPERTY_TAG_SELECT] && tag_exists($t_filter[FILTER_PROPERTY_TAG_SELECT])) {
                $t_tags_any[] = tag_get($t_filter[FILTER_PROPERTY_TAG_SELECT]);
            }
            $t_bug_tag_table = db_get_table('mantis_bug_tag_table');
            if (count($t_tags_all)) {
                $t_clauses = array();
                foreach ($t_tags_all as $t_tag_row) {
                    array_push($t_clauses, "{$t_bug_table}.id IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE {$t_bug_tag_table}.tag_id = {$t_tag_row['id']} )");
                }
                array_push($t_where_clauses, '(' . implode(' AND ', $t_clauses) . ')');
            }
            if (count($t_tags_any)) {
                $t_clauses = array();
                foreach ($t_tags_any as $t_tag_row) {
                    array_push($t_clauses, "{$t_bug_tag_table}.tag_id = {$t_tag_row['id']}");
                }
                array_push($t_where_clauses, "{$t_bug_table}.id IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE ( " . implode(' OR ', $t_clauses) . ') )');
            }
            if (count($t_tags_none)) {
                $t_clauses = array();
                foreach ($t_tags_none as $t_tag_row) {
                    array_push($t_clauses, "{$t_bug_tag_table}.tag_id = {$t_tag_row['id']}");
                }
                array_push($t_where_clauses, "{$t_bug_table}.id NOT IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE ( " . implode(' OR ', $t_clauses) . ') )');
            }
        }
    }
    # note user id
    if (!filter_field_is_any($t_filter[FILTER_PROPERTY_NOTE_USER_ID])) {
        $t_bugnote_table_alias = 'mbnt';
        $t_clauses = array();
        array_push($t_from_clauses, "{$t_bugnote_table}  {$t_bugnote_table_alias}");
        array_push($t_where_clauses, "( {$t_bug_table}.id = {$t_bugnote_table_alias}.bug_id )");
        foreach ($t_filter[FILTER_PROPERTY_NOTE_USER_ID] as $t_filter_member) {
            $c_note_user_id = db_prepare_int($t_filter_member);
            if (filter_field_is_myself($c_note_user_id)) {
                array_push($t_clauses, $c_user_id);
            } else {
                array_push($t_clauses, $c_note_user_id);
            }
        }
        if (1 < count($t_clauses)) {
            $t_where_tmp = array();
            foreach ($t_clauses as $t_clause) {
                $t_where_tmp[] = db_param();
                $t_where_params[] = $t_clause;
            }
            array_push($t_where_clauses, "( {$t_bugnote_table_alias}.reporter_id in (" . implode(', ', $t_where_tmp) . ") )");
        } else {
            $t_where_params[] = $t_clauses[0];
            array_push($t_where_clauses, "( {$t_bugnote_table_alias}.reporter_id=" . db_param() . " )");
        }
    }
    # plugin filters
    $t_plugin_filters = filter_get_plugin_filters();
    foreach ($t_plugin_filters as $t_field_name => $t_filter_object) {
        if (!filter_field_is_any($t_filter[$t_field_name]) || $t_filter_object->type == FILTER_TYPE_BOOLEAN) {
            $t_filter_query = $t_filter_object->query($t_filter[$t_field_name]);
            if (is_array($t_filter_query)) {
                if (isset($t_filter_query['join'])) {
                    array_push($t_join_clauses, $t_filter_query['join']);
                }
                if (isset($t_filter_query['where'])) {
                    array_push($t_where_clauses, $t_filter_query['where']);
                }
                if (isset($t_filter_query['params']) && is_array($t_filter_query['params'])) {
                    $t_where_params = array_merge($t_where_params, $t_filter_query['params']);
                }
            }
        }
    }
    # custom field filters
    if (ON == config_get('filter_by_custom_fields')) {
        # custom field filtering
        # @@@ At the moment this gets the linked fields relating to the current project
        #     It should get the ones relating to the project in the filter or all projects
        #     if multiple projects.
        $t_custom_fields = custom_field_get_linked_ids($t_project_id);
        foreach ($t_custom_fields as $t_cfid) {
            $t_field_info = custom_field_cache_row($t_cfid, true);
            if (!$t_field_info['filter_by']) {
                continue;
                # skip this custom field it shouldn't be filterable
            }
            $t_custom_where_clause = '';
            # Ignore all custom filters that are not set, or that are set to '' or "any"
            if (!filter_field_is_any($t_filter['custom_fields'][$t_cfid])) {
                $t_def = custom_field_get_definition($t_cfid);
                $t_table_name = $t_custom_field_string_table . '_' . $t_cfid;
                # We need to filter each joined table or the result query will explode in dimensions
                # Each custom field will result in a exponential growth like Number_of_Issues^Number_of_Custom_Fields
                # and only after this process ends (if it is able to) the result query will be filtered
                # by the WHERE clause and by the DISTINCT clause
                $t_cf_join_clause = "LEFT JOIN {$t_custom_field_string_table} {$t_table_name} ON {$t_bug_table}.id = {$t_table_name}.bug_id AND {$t_table_name}.field_id = {$t_cfid}";
                if ($t_def['type'] == CUSTOM_FIELD_TYPE_DATE) {
                    switch ($t_filter['custom_fields'][$t_cfid][0]) {
                        case CUSTOM_FIELD_DATE_ANY:
                            break;
                        case CUSTOM_FIELD_DATE_NONE:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '(( ' . $t_table_name . '.bug_id is null) OR ( ' . $t_table_name . '.value = 0)';
                            break;
                        case CUSTOM_FIELD_DATE_BEFORE:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '(( ' . $t_table_name . '.value != 0 AND (' . $t_table_name . '.value+0) < ' . $t_filter['custom_fields'][$t_cfid][2] . ')';
                            break;
                        case CUSTOM_FIELD_DATE_AFTER:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '( (' . $t_table_name . '.value+0) > ' . ($t_filter['custom_fields'][$t_cfid][1] + 1);
                            break;
                        default:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '( (' . $t_table_name . '.value+0) BETWEEN ' . $t_filter['custom_fields'][$t_cfid][1] . ' AND ' . $t_filter['custom_fields'][$t_cfid][2];
                            break;
                    }
                } else {
                    array_push($t_join_clauses, $t_cf_join_clause);
                    $t_filter_array = array();
                    foreach ($t_filter['custom_fields'][$t_cfid] as $t_filter_member) {
                        $t_filter_member = stripslashes($t_filter_member);
                        if (filter_field_is_none($t_filter_member)) {
                            # coerce filter value if selecting META_FILTER_NONE so it will match empty fields
                            $t_filter_member = '';
                            # but also add those _not_ present in the custom field string table
                            array_push($t_filter_array, "{$t_bug_table}.id NOT IN (SELECT bug_id FROM {$t_custom_field_string_table} WHERE field_id={$t_cfid})");
                        }
                        switch ($t_def['type']) {
                            case CUSTOM_FIELD_TYPE_CHECKBOX:
                            case CUSTOM_FIELD_TYPE_MULTILIST:
                                if ($t_filter_member != '') {
                                    $t_filter_member = '%|' . $t_filter_member . '|%';
                                }
                                $t_where_params[] = $t_filter_member;
                                array_push($t_filter_array, db_helper_like("{$t_table_name}.value"));
                                break;
                            default:
                                $t_where_params[] = $t_filter_member;
                                array_push($t_filter_array, "{$t_table_name}.value = " . db_param());
                        }
                    }
                    $t_custom_where_clause .= '(' . implode(' OR ', $t_filter_array);
                }
                if (!is_blank($t_custom_where_clause)) {
                    array_push($t_where_clauses, $t_custom_where_clause . ')');
                }
            }
        }
    }
    # Text search
    if (!is_blank($t_filter[FILTER_PROPERTY_FREE_TEXT])) {
        # break up search terms by spacing or quoting
        preg_match_all("/-?([^'\"\\s]+|\"[^\"]+\"|'[^']+')/", $t_filter[FILTER_PROPERTY_FREE_TEXT], $t_matches, PREG_SET_ORDER);
        # organize terms without quoting, paying attention to negation
        $t_search_terms = array();
        foreach ($t_matches as $t_match) {
            $t_search_terms[trim($t_match[1], "\\'\"")] = $t_match[0][0] == '-';
        }
        # build a big where-clause and param list for all search terms, including negations
        $t_first = true;
        $t_textsearch_where_clause = "( ";
        foreach ($t_search_terms as $t_search_term => $t_negate) {
            if (!$t_first) {
                $t_textsearch_where_clause .= ' AND ';
            }
            if ($t_negate) {
                $t_textsearch_where_clause .= 'NOT ';
            }
            $c_search = '%' . $t_search_term . '%';
            $t_textsearch_where_clause .= '( ' . db_helper_like('summary') . ' OR ' . db_helper_like("{$t_bug_text_table}.description") . ' OR ' . db_helper_like("{$t_bug_text_table}.steps_to_reproduce") . ' OR ' . db_helper_like("{$t_bug_text_table}.additional_information") . ' OR ' . db_helper_like("{$t_bugnote_text_table}.note");
            $t_where_params[] = $c_search;
            $t_where_params[] = $c_search;
            $t_where_params[] = $c_search;
            $t_where_params[] = $c_search;
            $t_where_params[] = $c_search;
            if (is_numeric($t_search_term)) {
                // PostgreSQL on 64-bit OS hack (see #14014)
                if (PHP_INT_MAX > 0x7fffffff && db_is_pgsql()) {
                    $t_search_max = 0x7fffffff;
                } else {
                    $t_search_max = PHP_INT_MAX;
                }
                // Note: no need to test negative values, '-' sign has been removed
                if ($t_search_term <= $t_search_max) {
                    $c_search_int = (int) $t_search_term;
                    $t_textsearch_where_clause .= " OR {$t_bug_table}.id = " . db_param();
                    $t_textsearch_where_clause .= " OR {$t_bugnote_table}.id = " . db_param();
                    $t_where_params[] = $c_search_int;
                    $t_where_params[] = $c_search_int;
                }
            }
            $t_textsearch_where_clause .= ' )';
            $t_first = false;
        }
        $t_textsearch_where_clause .= ' )';
        # add text query elements to arrays
        if (!$t_first) {
            $t_from_clauses[] = "{$t_bug_text_table}";
            $t_where_clauses[] = "{$t_bug_table}.bug_text_id = {$t_bug_text_table}.id";
            $t_where_clauses[] = $t_textsearch_where_clause;
            $t_join_clauses[] = " LEFT JOIN {$t_bugnote_table} ON {$t_bug_table}.id = {$t_bugnote_table}.bug_id";
            $t_join_clauses[] = " LEFT JOIN {$t_bugnote_text_table} ON {$t_bugnote_table}.bugnote_text_id = {$t_bugnote_text_table}.id";
        }
    }
    # End text search
    $t_from_clauses[] = $t_project_table;
    $t_from_clauses[] = $t_bug_table;
    $t_query_clauses['select'] = $t_select_clauses;
    $t_query_clauses['from'] = $t_from_clauses;
    $t_query_clauses['join'] = $t_join_clauses;
    $t_query_clauses['where'] = $t_where_clauses;
    $t_query_clauses['where_values'] = $t_where_params;
    $t_query_clauses = filter_get_query_sort_data($t_filter, $p_show_sticky, $t_query_clauses);
    # assigning to $p_* for this function writes the values back in case the caller wants to know
    # Get the total number of bugs that meet the criteria.
    $p_bug_count = filter_get_bug_count($t_query_clauses);
    if (0 == $p_bug_count) {
        return array();
    }
    $p_per_page = filter_per_page($t_filter, $p_bug_count, $p_per_page);
    $p_page_count = filter_page_count($p_bug_count, $p_per_page);
    $p_page_number = filter_valid_page_number($p_page_number, $p_page_count);
    $t_offset = filter_offset($p_page_number, $p_per_page);
    $t_query_clauses = filter_unique_query_clauses($t_query_clauses);
    $t_select_string = "SELECT DISTINCT " . implode(', ', $t_query_clauses['select']);
    $t_from_string = " FROM " . implode(', ', $t_query_clauses['from']);
    $t_order_string = " ORDER BY " . implode(', ', $t_query_clauses['order']);
    $t_join_string = count($t_query_clauses['join']) > 0 ? implode(' ', $t_query_clauses['join']) : '';
    $t_where_string = count($t_query_clauses['where']) > 0 ? 'WHERE ' . implode(' AND ', $t_query_clauses['where']) : '';
    $t_result = db_query_bound("{$t_select_string} {$t_from_string} {$t_join_string} {$t_where_string} {$t_order_string}", $t_query_clauses['where_values'], $p_per_page, $t_offset);
    $t_row_count = db_num_rows($t_result);
    $t_id_array_lastmod = array();
    for ($i = 0; $i < $t_row_count; $i++) {
        $t_row = db_fetch_array($t_result);
        $t_id_array_lastmod[] = (int) $t_row['id'];
        $t_rows[] = $t_row;
    }
    return filter_cache_result($t_rows, $t_id_array_lastmod);
}
Exemple #19
0
/**
 * Get the custom fields that belong to the specified project.
 *
 * @param string $p_username  The name of the user trying to access the versions.
 * @param string $p_password  The password of the user.
 * @param integer $p_project_id  The id of the project to retrieve the custom fields for.
 * @return Array  representing a CustomFieldDefinitionDataArray structure.
 */
function mc_project_get_custom_fields($p_username, $p_password, $p_project_id)
{
    $t_user_id = mci_check_login($p_username, $p_password);
    if ($t_user_id === false) {
        return mci_soap_fault_login_failed();
    }
    if (!project_exists($p_project_id)) {
        return new soap_fault('Client', '', "Project '{$p_project_id}' does not exist.");
    }
    if (!mci_has_readonly_access($t_user_id, $p_project_id)) {
        return mci_soap_fault_access_denied($t_user_id);
    }
    $t_result = array();
    $t_related_custom_field_ids = custom_field_get_linked_ids($p_project_id);
    foreach (custom_field_get_linked_ids($p_project_id) as $t_id) {
        $t_def = custom_field_get_definition($t_id);
        if (access_has_project_level($t_def['access_level_r'], $p_project_id)) {
            $t_result[] = array('field' => array('id' => $t_def['id'], 'name' => $t_def['name']), 'type' => $t_def['type'], 'default_value' => $t_def['default_value'], 'possible_values' => $t_def['possible_values'], 'valid_regexp' => $t_def['valid_regexp'], 'access_level_r' => $t_def['access_level_r'], 'access_level_rw' => $t_def['access_level_rw'], 'length_min' => $t_def['length_min'], 'length_max' => $t_def['length_max'], 'display_report' => $t_def['display_report'], 'display_update' => $t_def['display_update'], 'display_resolved' => $t_def['display_resolved'], 'display_closed' => $t_def['display_closed'], 'require_report' => $t_def['require_report'], 'require_update' => $t_def['require_update'], 'require_resolved' => $t_def['require_resolved'], 'require_closed' => $t_def['require_closed']);
        }
    }
    return $t_result;
}
function custom_function_override_print_column_value($p_column, $p_bug, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE)
{
    if (COLUMNS_TARGET_CSV_PAGE == $p_columns_target) {
        $t_column_start = '';
        $t_column_end = '';
        $t_column_empty = '';
    } else {
        $t_column_start = '<td class="center">';
        $t_column_end = '</td>';
        $t_column_empty = '&#160;';
    }
    $t_custom_field = column_get_custom_field_name($p_column);
    if ($t_custom_field !== null) {
        echo $t_column_start;
        $t_field_id = custom_field_get_id_from_name($t_custom_field);
        if ($t_field_id === false) {
            echo '@', $t_custom_field, '@';
        } else {
            $t_issue_id = $p_bug->id;
            $t_project_id = $p_bug->project_id;
            if (custom_field_is_linked($t_field_id, $t_project_id)) {
                $t_def = custom_field_get_definition($t_field_id);
                if (strpos($p_column, 'custom_Deadline') === 0 && $t_def['type'] == CUSTOM_FIELD_TYPE_DATE) {
                    $deadline_date = custom_field_get_value($t_field_id, $t_issue_id);
                    if ($p_issue_row['status'] < 80) {
                        $current_date = strtotime(date("Y-m-d"));
                        if ($current_date >= $deadline_date) {
                            echo '<b><font color="red">';
                            print_custom_field_value($t_def, $t_field_id, $t_issue_id);
                            echo '</font></b>';
                        } else {
                            print_custom_field_value($t_def, $t_field_id, $t_issue_id);
                        }
                    } elseif ($deadline_date) {
                        if (lang_get_current() == 'german') {
                            echo '<b>ERLEDIGT!</b>';
                        } else {
                            echo '<b>DONE!</b>';
                        }
                    }
                } else {
                    print_custom_field_value($t_def, $t_field_id, $t_issue_id);
                }
            } else {
                // field is not linked to project
                echo $t_column_empty;
            }
        }
        echo $t_column_end;
    } else {
        $t_plugin_columns = columns_get_plugin_columns();
        if ($p_columns_target != COLUMNS_TARGET_CSV_PAGE) {
            if ($p_column == 'summary') {
                $t_function = 'print_column_summary_BFE';
            } else {
                $t_function = 'print_column_' . $p_column;
            }
        } else {
            $t_function = 'csv_format_' . $p_column;
        }
        if (function_exists($t_function)) {
            if ($p_columns_target != COLUMNS_TARGET_CSV_PAGE) {
                $t_function($p_bug, $p_columns_target);
            } else {
                $t_function($p_bug);
            }
        } else {
            if (isset($t_plugin_columns[$p_column])) {
                $t_column_object = $t_plugin_columns[$p_column];
                print_column_plugin($t_column_object, $p_bug, $p_columns_target);
            } else {
                if (isset($p_bug->{$p_column})) {
                    echo $t_column_start . string_display_line($p_bug->{$p_column}) . $t_column_end;
                } else {
                    echo $t_column_start . '@' . $p_column . '@' . $t_column_end;
                }
            }
        }
    }
}
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------
# $Id: manage_custom_field_delete.php,v 1.17.2.1 2007-10-13 22:33:27 giallu Exp $
# --------------------------------------------------------
require_once 'core.php';
$t_core_path = config_get('core_path');
require_once $t_core_path . 'custom_field_api.php';
form_security_validate('manage_custom_field_delete');
auth_reauthenticate();
access_ensure_global_level(config_get('manage_custom_fields_threshold'));
$f_field_id = gpc_get_int('field_id');
$f_return = strip_tags(gpc_get_string('return', 'manage_custom_field_page.php'));
$t_definition = custom_field_get_definition($f_field_id);
if (0 < count(custom_field_get_project_ids($f_field_id))) {
    helper_ensure_confirmed(lang_get('confirm_used_custom_field_deletion') . '<br/>' . lang_get('custom_field') . ': ' . string_attribute($t_definition['name']), lang_get('field_delete_button'));
} else {
    helper_ensure_confirmed(lang_get('confirm_custom_field_deletion') . '<br/>' . lang_get('custom_field') . ': ' . string_attribute($t_definition['name']), lang_get('field_delete_button'));
}
custom_field_destroy($f_field_id);
form_security_purge('manage_custom_field_delete');
html_page_top1();
html_meta_redirect($f_return);
html_page_top2();
?>

<br />
<div align="center">
<?php 
Exemple #22
0
function filter_get_bug_rows(&$p_page_number, &$p_per_page, &$p_page_count, &$p_bug_count, $p_custom_filter = null, $p_project_id = null, $p_user_id = null, $p_show_sticky = null)
{
    log_event(LOG_FILTERING, 'FILTERING: START NEW FILTER QUERY');
    $t_bug_table = config_get('mantis_bug_table');
    $t_bug_text_table = config_get('mantis_bug_text_table');
    $t_bugnote_table = config_get('mantis_bugnote_table');
    $t_custom_field_string_table = config_get('mantis_custom_field_string_table');
    $t_bugnote_text_table = config_get('mantis_bugnote_text_table');
    $t_project_table = config_get('mantis_project_table');
    $t_bug_monitor_table = config_get('mantis_bug_monitor_table');
    $t_limit_reporters = config_get('limit_reporters');
    $t_bug_relationship_table = config_get('mantis_bug_relationship_table');
    $t_report_bug_threshold = config_get('report_bug_threshold');
    $t_current_user_id = auth_get_current_user_id();
    if (null === $p_user_id) {
        $t_user_id = $t_current_user_id;
    } else {
        $t_user_id = $p_user_id;
    }
    $c_user_id = db_prepare_int($t_user_id);
    if (null === $p_project_id) {
        # @@@ If project_id is not specified, then use the project id(s) in the filter if set, otherwise, use current project.
        $t_project_id = helper_get_current_project();
    } else {
        $t_project_id = $p_project_id;
    }
    if ($p_custom_filter === null) {
        # Prefer current_user_get_bug_filter() over user_get_filter() when applicable since it supports
        # cookies set by previous version of the code.
        if ($t_user_id == $t_current_user_id) {
            $t_filter = current_user_get_bug_filter();
        } else {
            $t_filter = user_get_bug_filter($t_user_id, $t_project_id);
        }
    } else {
        $t_filter = $p_custom_filter;
    }
    $t_filter = filter_ensure_valid_filter($t_filter);
    if (false === $t_filter) {
        return false;
        # signify a need to create a cookie
        #@@@ error instead?
    }
    $t_view_type = $t_filter['_view_type'];
    $t_where_clauses = array("{$t_project_table}.enabled = 1", "{$t_project_table}.id = {$t_bug_table}.project_id");
    $t_select_clauses = array("{$t_bug_table}.*");
    $t_join_clauses = array();
    $t_from_clauses = array();
    // normalize the project filtering into an array $t_project_ids
    if ('simple' == $t_view_type) {
        log_event(LOG_FILTERING, 'FILTERING: Simple Filter');
        $t_project_ids = array($t_project_id);
        $t_include_sub_projects = true;
    } else {
        log_event(LOG_FILTERING, 'FILTERING: Advanced Filter');
        if (!is_array($t_filter['project_id'])) {
            $t_project_ids = array(db_prepare_int($t_filter['project_id']));
        } else {
            $t_project_ids = array_map('db_prepare_int', $t_filter['project_id']);
        }
        $t_include_sub_projects = count($t_project_ids) == 1 && $t_project_ids[0] == META_FILTER_CURRENT;
    }
    log_event(LOG_FILTERING, 'FILTERING: project_ids = ' . implode(',', $t_project_ids));
    log_event(LOG_FILTERING, 'FILTERING: include sub-projects = ' . ($t_include_sub_projects ? '1' : '0'));
    // if the array has ALL_PROJECTS, then reset the array to only contain ALL_PROJECTS.
    // replace META_FILTER_CURRENT with the actualy current project id.
    $t_all_projects_found = false;
    $t_new_project_ids = array();
    foreach ($t_project_ids as $t_pid) {
        if ($t_pid == META_FILTER_CURRENT) {
            $t_pid = $t_project_id;
        }
        if ($t_pid == ALL_PROJECTS) {
            $t_all_projects_found = true;
            log_event(LOG_FILTERING, 'FILTERING: all projects selected');
            break;
        }
        // filter out inaccessible projects.
        if (!access_has_project_level(VIEWER, $t_pid, $t_user_id)) {
            continue;
        }
        $t_new_project_ids[] = $t_pid;
    }
    $t_projects_query_required = true;
    if ($t_all_projects_found) {
        if (user_is_administrator($t_user_id)) {
            log_event(LOG_FILTERING, 'FILTERING: all projects + administrator, hence no project filter.');
            $t_projects_query_required = false;
        } else {
            $t_project_ids = user_get_accessible_projects($t_user_id);
        }
    } else {
        $t_project_ids = $t_new_project_ids;
    }
    if ($t_projects_query_required) {
        // expand project ids to include sub-projects
        if ($t_include_sub_projects) {
            $t_top_project_ids = $t_project_ids;
            foreach ($t_top_project_ids as $t_pid) {
                log_event(LOG_FILTERING, 'FILTERING: Getting sub-projects for project id ' . $t_pid);
                $t_project_ids = array_merge($t_project_ids, user_get_all_accessible_subprojects($t_user_id, $t_pid));
            }
            $t_project_ids = array_unique($t_project_ids);
        }
        // if no projects are accessible, then return an empty array.
        if (count($t_project_ids) == 0) {
            log_event(LOG_FILTERING, 'FILTERING: no accessible projects');
            return array();
        }
        log_event(LOG_FILTERING, 'FILTERING: project_ids after including sub-projects = ' . implode(',', $t_project_ids));
        // this array is to be populated with project ids for which we only want to show public issues.  This is due to the limited
        // access of the current user.
        $t_public_only_project_ids = array();
        // this array is populated with project ids that the current user has full access to.
        $t_private_and_public_project_ids = array();
        $t_access_required_to_view_private_bugs = config_get('private_bug_threshold');
        foreach ($t_project_ids as $t_pid) {
            if (access_has_project_level($t_access_required_to_view_private_bugs, $t_pid, $t_user_id)) {
                $t_private_and_public_project_ids[] = $t_pid;
            } else {
                $t_public_only_project_ids[] = $t_pid;
            }
        }
        log_event(LOG_FILTERING, 'FILTERING: project_ids (with public/private access) = ' . implode(',', $t_private_and_public_project_ids));
        log_event(LOG_FILTERING, 'FILTERING: project_ids (with public access) = ' . implode(',', $t_public_only_project_ids));
        $t_count_private_and_public_project_ids = count($t_private_and_public_project_ids);
        if ($t_count_private_and_public_project_ids == 1) {
            $t_private_and_public_query = "( {$t_bug_table}.project_id = " . $t_private_and_public_project_ids[0] . " )";
        } else {
            if ($t_count_private_and_public_project_ids > 1) {
                $t_private_and_public_query = "( {$t_bug_table}.project_id in (" . implode(', ', $t_private_and_public_project_ids) . ") )";
            } else {
                $t_private_and_public_query = null;
            }
        }
        $t_count_public_only_project_ids = count($t_public_only_project_ids);
        $t_public_view_state_check = "( ( {$t_bug_table}.view_state = " . VS_PUBLIC . " ) OR ( {$t_bug_table}.reporter_id = {$t_user_id} ) )";
        if ($t_count_public_only_project_ids == 1) {
            $t_public_only_query = "( ( {$t_bug_table}.project_id = " . $t_public_only_project_ids[0] . " ) AND {$t_public_view_state_check} )";
        } else {
            if ($t_count_public_only_project_ids > 1) {
                $t_public_only_query = "( ( {$t_bug_table}.project_id in (" . implode(', ', $t_public_only_project_ids) . ") ) AND {$t_public_view_state_check} )";
            } else {
                $t_public_only_query = null;
            }
        }
        // both queries can't be null, so we either have one of them or both.
        if ($t_private_and_public_query === null) {
            $t_project_query = $t_public_only_query;
        } else {
            if ($t_public_only_query === null) {
                $t_project_query = $t_private_and_public_query;
            } else {
                $t_project_query = "( {$t_public_only_query} OR {$t_private_and_public_query} )";
            }
        }
        log_event(LOG_FILTERING, 'FILTERING: project query = ' . $t_project_query);
        array_push($t_where_clauses, $t_project_query);
    }
    # view state
    $t_view_state = db_prepare_int($t_filter['view_state']);
    if ($t_filter['view_state'] !== META_FILTER_ANY && !is_blank($t_filter['view_state'])) {
        $t_view_state_query = "({$t_bug_table}.view_state='{$t_view_state}')";
        log_event(LOG_FILTERING, 'FILTERING: view_state query = ' . $t_view_state_query);
        array_push($t_where_clauses, $t_view_state_query);
    } else {
        log_event(LOG_FILTERING, 'FILTERING: no view_state query');
    }
    # reporter
    $t_any_found = false;
    foreach ($t_filter['reporter_id'] as $t_filter_member) {
        if (META_FILTER_ANY === $t_filter_member || 0 === $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['reporter_id']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['reporter_id'] as $t_filter_member) {
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "0");
            } else {
                $c_reporter_id = db_prepare_int($t_filter_member);
                if (META_FILTER_MYSELF == $c_reporter_id) {
                    array_push($t_clauses, $c_user_id);
                } else {
                    array_push($t_clauses, $c_reporter_id);
                }
            }
        }
        if (1 < count($t_clauses)) {
            $t_reporter_query = "( {$t_bug_table}.reporter_id in (" . implode(', ', $t_clauses) . ") )";
        } else {
            $t_reporter_query = "( {$t_bug_table}.reporter_id={$t_clauses['0']} )";
        }
        log_event(LOG_FILTERING, 'FILTERING: reporter query = ' . $t_reporter_query);
        array_push($t_where_clauses, $t_reporter_query);
    } else {
        log_event(LOG_FILTERING, 'FILTERING: no reporter query');
    }
    # limit reporter
    # @@@ thraxisp - access_has_project_level checks greater than or equal to,
    #   this assumed that there aren't any holes above REPORTER where the limit would apply
    #
    if (ON === $t_limit_reporters && !access_has_project_level(REPORTER + 1, $t_project_id, $t_user_id)) {
        $c_reporter_id = $c_user_id;
        array_push($t_where_clauses, "({$t_bug_table}.reporter_id='{$c_reporter_id}')");
    }
    # handler
    $t_any_found = false;
    foreach ($t_filter['handler_id'] as $t_filter_member) {
        if (META_FILTER_ANY === $t_filter_member || 0 === $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['handler_id']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['handler_id'] as $t_filter_member) {
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, 0);
            } else {
                $c_handler_id = db_prepare_int($t_filter_member);
                if (META_FILTER_MYSELF == $c_handler_id) {
                    array_push($t_clauses, $c_user_id);
                } else {
                    array_push($t_clauses, $c_handler_id);
                }
            }
        }
        if (1 < count($t_clauses)) {
            $t_handler_query = "( {$t_bug_table}.handler_id in (" . implode(', ', $t_clauses) . ") )";
        } else {
            $t_handler_query = "( {$t_bug_table}.handler_id={$t_clauses['0']} )";
        }
        log_event(LOG_FILTERING, 'FILTERING: handler query = ' . $t_handler_query);
        array_push($t_where_clauses, $t_handler_query);
    } else {
        log_event(LOG_FILTERING, 'FILTERING: no handler query');
    }
    # category
    if (!_filter_is_any($t_filter['show_category'])) {
        $t_clauses = array();
        foreach ($t_filter['show_category'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "''");
            } else {
                $c_show_category = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_show_category}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.category in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.category={$t_clauses['0']} )");
        }
    }
    # severity
    $t_any_found = false;
    foreach ($t_filter['show_severity'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member || 0 === $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['show_severity']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['show_severity'] as $t_filter_member) {
            $c_show_severity = db_prepare_int($t_filter_member);
            array_push($t_clauses, $c_show_severity);
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.severity in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.severity={$t_clauses['0']} )");
        }
    }
    # show / hide status
    # take a list of all available statuses then remove the ones that we want hidden, then make sure
    # the ones we want shown are still available
    $t_status_arr = explode_enum_string(config_get('status_enum_string'));
    $t_available_statuses = array();
    $t_desired_statuses = array();
    foreach ($t_status_arr as $t_this_status) {
        $t_this_status_arr = explode_enum_arr($t_this_status);
        $t_available_statuses[] = $t_this_status_arr[0];
    }
    if ('simple' == $t_filter['_view_type']) {
        # simple filtering: if showing any, restrict by the hide status value, otherwise ignore the hide
        $t_any_found = false;
        $t_this_status = $t_filter['show_status'][0];
        $t_this_hide_status = $t_filter['hide_status'][0];
        if (META_FILTER_ANY == $t_this_status || is_blank($t_this_status) || 0 === $t_this_status) {
            $t_any_found = true;
        }
        if ($t_any_found) {
            foreach ($t_available_statuses as $t_this_available_status) {
                if ($t_this_hide_status > $t_this_available_status) {
                    $t_desired_statuses[] = $t_this_available_status;
                }
            }
        } else {
            $t_desired_statuses[] = $t_this_status;
        }
    } else {
        # advanced filtering: ignore the hide
        $t_any_found = false;
        foreach ($t_filter['show_status'] as $t_this_status) {
            $t_desired_statuses[] = $t_this_status;
            if (META_FILTER_ANY == $t_this_status || is_blank($t_this_status) || 0 === $t_this_status) {
                $t_any_found = true;
            }
        }
        if ($t_any_found) {
            $t_desired_statuses = array();
        }
    }
    if (count($t_desired_statuses) > 0) {
        $t_clauses = array();
        foreach ($t_desired_statuses as $t_filter_member) {
            $c_show_status = db_prepare_int($t_filter_member);
            array_push($t_clauses, $c_show_status);
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.status in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.status={$t_clauses['0']} )");
        }
    }
    # resolution
    $t_any_found = false;
    foreach ($t_filter['show_resolution'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['show_resolution']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['show_resolution'] as $t_filter_member) {
            $c_show_resolution = db_prepare_int($t_filter_member);
            array_push($t_clauses, $c_show_resolution);
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.resolution in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.resolution={$t_clauses['0']} )");
        }
    }
    # priority
    $t_any_found = false;
    foreach ($t_filter['show_priority'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member || 0 === $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['show_priority']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['show_priority'] as $t_filter_member) {
            $c_show_priority = db_prepare_int($t_filter_member);
            array_push($t_clauses, $c_show_priority);
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.priority in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.priority={$t_clauses['0']} )");
        }
    }
    # product build
    $t_any_found = false;
    foreach ($t_filter['show_build'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member && is_numeric($t_filter_member)) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['show_build']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['show_build'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "''");
            } else {
                $c_show_build = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_show_build}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.build in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.build={$t_clauses['0']} )");
        }
    }
    # product version
    if (!_filter_is_any($t_filter['show_version'])) {
        $t_clauses = array();
        foreach ($t_filter['show_version'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "''");
            } else {
                $c_show_version = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_show_version}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.version in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.version={$t_clauses['0']} )");
        }
    }
    # profile
    if (!_filter_is_any($t_filter['show_profile'])) {
        $t_clauses = array();
        foreach ($t_filter['show_profile'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "0");
            } else {
                $c_show_profile = db_prepare_int($t_filter_member);
                array_push($t_clauses, "{$c_show_profile}");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.profile_id in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.profile_id={$t_clauses['0']} )");
        }
    }
    # platform
    if (!_filter_is_any($t_filter['platform'])) {
        $t_clauses = array();
        foreach ($t_filter['platform'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, '');
            } else {
                $c_platform = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_platform}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.platform in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.platform = {$t_clauses['0']} )");
        }
    }
    # os
    if (!_filter_is_any($t_filter['os'])) {
        $t_clauses = array();
        foreach ($t_filter['os'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, '');
            } else {
                $c_os = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_os}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.os in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.os = {$t_clauses['0']} )");
        }
    }
    # os_build
    if (!_filter_is_any($t_filter['os_build'])) {
        $t_clauses = array();
        foreach ($t_filter['os_build'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, '');
            } else {
                $c_os_build = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_os_build}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.os_build in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.os_build = {$t_clauses['0']} )");
        }
    }
    # date filter
    if ('on' == $t_filter['do_filter_by_date'] && is_numeric($t_filter['start_month']) && is_numeric($t_filter['start_day']) && is_numeric($t_filter['start_year']) && is_numeric($t_filter['end_month']) && is_numeric($t_filter['end_day']) && is_numeric($t_filter['end_year'])) {
        $t_start_string = db_prepare_string($t_filter['start_year'] . "-" . $t_filter['start_month'] . "-" . $t_filter['start_day'] . " 00:00:00");
        $t_end_string = db_prepare_string($t_filter['end_year'] . "-" . $t_filter['end_month'] . "-" . $t_filter['end_day'] . " 23:59:59");
        array_push($t_where_clauses, "({$t_bug_table}.date_submitted BETWEEN '{$t_start_string}' AND '{$t_end_string}' )");
    }
    # fixed in version
    if (!_filter_is_any($t_filter['fixed_in_version'])) {
        $t_clauses = array();
        foreach ($t_filter['fixed_in_version'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "''");
            } else {
                $c_fixed_in_version = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_fixed_in_version}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.fixed_in_version in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.fixed_in_version={$t_clauses['0']} )");
        }
    }
    # target version
    if (!_filter_is_any($t_filter['target_version'])) {
        $t_clauses = array();
        foreach ($t_filter['target_version'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "''");
            } else {
                $c_target_version = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_target_version}'");
            }
        }
        #echo var_dump( $t_clauses ); exit;
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.target_version in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.target_version={$t_clauses['0']} )");
        }
    }
    # users monitoring a bug
    $t_any_found = false;
    foreach ($t_filter['user_monitor'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member || 0 === $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['user_monitor']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        $t_table_name = 'user_monitor';
        array_push($t_from_clauses, $t_bug_monitor_table);
        array_push($t_join_clauses, "LEFT JOIN {$t_bug_monitor_table} {$t_table_name} ON {$t_table_name}.bug_id = {$t_bug_table}.id");
        foreach ($t_filter['user_monitor'] as $t_filter_member) {
            $c_user_monitor = db_prepare_int($t_filter_member);
            if (META_FILTER_MYSELF == $c_user_monitor) {
                array_push($t_clauses, $c_user_id);
            } else {
                array_push($t_clauses, $c_user_monitor);
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_table_name}.user_id in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_table_name}.user_id={$t_clauses['0']} )");
        }
    }
    # bug relationship
    $t_any_found = false;
    $c_rel_type = $t_filter['relationship_type'];
    $c_rel_bug = $t_filter['relationship_bug'];
    if (-1 == $c_rel_type || 0 == $c_rel_bug) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        # use the complementary type
        $t_comp_type = relationship_get_complementary_type($c_rel_type);
        $t_clauses = array();
        $t_table_name = 'relationship';
        array_push($t_from_clauses, $t_bug_relationship_table);
        array_push($t_join_clauses, "LEFT JOIN {$t_bug_relationship_table} {$t_table_name} ON {$t_table_name}.destination_bug_id = {$t_bug_table}.id");
        array_push($t_join_clauses, "LEFT JOIN {$t_bug_relationship_table} {$t_table_name}2 ON {$t_table_name}2.source_bug_id = {$t_bug_table}.id");
        // get reverse relationships
        array_push($t_clauses, "({$t_table_name}.relationship_type='{$t_comp_type}' AND {$t_table_name}.source_bug_id='{$c_rel_bug}')");
        array_push($t_clauses, "({$t_table_name}" . "2.relationship_type='{$c_rel_type}' AND {$t_table_name}" . "2.destination_bug_id='{$c_rel_bug}')");
        array_push($t_where_clauses, '(' . implode(' OR ', $t_clauses) . ')');
    }
    # tags
    $c_tag_string = trim($t_filter['tag_string']);
    if (!is_blank($c_tag_string)) {
        $t_tags = tag_parse_filters($c_tag_string);
        if (count($t_tags)) {
            $t_tags_all = array();
            $t_tags_any = array();
            $t_tags_none = array();
            foreach ($t_tags as $t_tag_row) {
                switch ($t_tag_row['filter']) {
                    case 1:
                        $t_tags_all[] = $t_tag_row;
                        break;
                    case 0:
                        $t_tags_any[] = $t_tag_row;
                        break;
                    case -1:
                        $t_tags_none[] = $t_tag_row;
                        break;
                }
            }
            if (0 < $t_filter['tag_select'] && tag_exists($t_filter['tag_select'])) {
                $t_tags_any[] = tag_get($t_filter['tag_select']);
            }
            $t_bug_tag_table = config_get('mantis_bug_tag_table');
            if (count($t_tags_all)) {
                $t_clauses = array();
                foreach ($t_tags_all as $t_tag_row) {
                    array_push($t_clauses, "{$t_bug_table}.id IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE {$t_bug_tag_table}.tag_id = {$t_tag_row['id']} )");
                }
                array_push($t_where_clauses, '(' . implode(' AND ', $t_clauses) . ')');
            }
            if (count($t_tags_any)) {
                $t_clauses = array();
                foreach ($t_tags_any as $t_tag_row) {
                    array_push($t_clauses, "{$t_bug_tag_table}.tag_id = {$t_tag_row['id']}");
                }
                array_push($t_where_clauses, "{$t_bug_table}.id IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE ( " . implode(' OR ', $t_clauses) . ') )');
            }
            if (count($t_tags_none)) {
                $t_clauses = array();
                foreach ($t_tags_none as $t_tag_row) {
                    array_push($t_clauses, "{$t_bug_tag_table}.tag_id = {$t_tag_row['id']}");
                }
                array_push($t_where_clauses, "{$t_bug_table}.id NOT IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE ( " . implode(' OR ', $t_clauses) . ') )');
            }
        }
    }
    # custom field filters
    if (ON == config_get('filter_by_custom_fields')) {
        # custom field filtering
        # @@@ At the moment this gets the linked fields relating to the current project
        #     It should get the ones relating to the project in the filter or all projects
        #     if multiple projects.
        $t_custom_fields = custom_field_get_linked_ids($t_project_id);
        foreach ($t_custom_fields as $t_cfid) {
            $t_custom_where_clause = '';
            # Ignore all custom filters that are not set, or that are set to '' or "any"
            $t_any_found = false;
            foreach ($t_filter['custom_fields'][$t_cfid] as $t_filter_member) {
                if (META_FILTER_ANY == $t_filter_member && is_numeric($t_filter_member)) {
                    $t_any_found = true;
                }
            }
            if (!isset($t_filter['custom_fields'][$t_cfid])) {
                $t_any_found = true;
            }
            if (!$t_any_found) {
                $t_def = custom_field_get_definition($t_cfid);
                $t_table_name = $t_custom_field_string_table . '_' . $t_cfid;
                # We need to filter each joined table or the result query will explode in dimensions
                # Each custom field will result in a exponential growth like Number_of_Issues^Number_of_Custom_Fields
                # and only after this process ends (if it is able to) the result query will be filtered
                # by the WHERE clause and by the DISTINCT clause
                $t_cf_join_clause = "LEFT JOIN {$t_custom_field_string_table} {$t_table_name} ON {$t_table_name}.bug_id = {$t_bug_table}.id AND {$t_table_name}.field_id = {$t_cfid} ";
                if ($t_def['type'] == CUSTOM_FIELD_TYPE_DATE) {
                    switch ($t_filter['custom_fields'][$t_cfid][0]) {
                        case CUSTOM_FIELD_DATE_ANY:
                            break;
                        case CUSTOM_FIELD_DATE_NONE:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '(( ' . $t_table_name . '.bug_id is null) OR ( ' . $t_table_name . '.value = 0)';
                            break;
                        case CUSTOM_FIELD_DATE_BEFORE:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '(( ' . $t_table_name . '.value != 0 AND (' . $t_table_name . '.value+0) < ' . $t_filter['custom_fields'][$t_cfid][2] . ')';
                            break;
                        case CUSTOM_FIELD_DATE_AFTER:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '( (' . $t_table_name . '.value+0) > ' . ($t_filter['custom_fields'][$t_cfid][1] + 1);
                            break;
                        default:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '( (' . $t_table_name . '.value+0) BETWEEN ' . $t_filter['custom_fields'][$t_cfid][1] . ' AND ' . $t_filter['custom_fields'][$t_cfid][2];
                            break;
                    }
                } else {
                    array_push($t_join_clauses, $t_cf_join_clause);
                    $t_filter_array = array();
                    foreach ($t_filter['custom_fields'][$t_cfid] as $t_filter_member) {
                        $t_filter_member = stripslashes($t_filter_member);
                        if (META_FILTER_NONE == $t_filter_member) {
                            # coerce filter value if selecting META_FILTER_NONE so it will match empty fields
                            $t_filter_member = '';
                            # but also add those _not_ present in the custom field string table
                            array_push($t_filter_array, "{$t_bug_table}.id NOT IN (SELECT bug_id FROM {$t_custom_field_string_table} WHERE field_id={$t_cfid})");
                        }
                        switch ($t_def['type']) {
                            case CUSTOM_FIELD_TYPE_MULTILIST:
                            case CUSTOM_FIELD_TYPE_CHECKBOX:
                                array_push($t_filter_array, db_helper_like("{$t_table_name}.value", '%|' . db_prepare_string($t_filter_member) . '|%'));
                                break;
                            default:
                                array_push($t_filter_array, "{$t_table_name}.value = '" . db_prepare_string($t_filter_member) . "'");
                        }
                    }
                    $t_custom_where_clause .= '(' . implode(' OR ', $t_filter_array);
                }
                if (!is_blank($t_custom_where_clause)) {
                    array_push($t_where_clauses, $t_custom_where_clause . ')');
                }
            }
        }
    }
    $t_textsearch_where_clause = '';
    $t_textsearch_wherejoin_clause = '';
    # Simple Text Search - Thanks to Alan Knowles
    if (!is_blank($t_filter['search'])) {
        $c_search = db_prepare_string($t_filter['search']);
        $c_search_int = db_prepare_int($t_filter['search']);
        $t_textsearch_where_clause = '(' . db_helper_like('summary', "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.description", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.steps_to_reproduce", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.additional_information", "%{$c_search}%") . " OR ( {$t_bug_table}.id = '{$c_search_int}' ) )";
        $t_textsearch_wherejoin_clause = '(' . db_helper_like('summary', "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.description", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.steps_to_reproduce", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.additional_information", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_table}.id", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bugnote_text_table}.note", "%{$c_search}%") . ' )';
        array_push($t_where_clauses, "({$t_bug_text_table}.id = {$t_bug_table}.bug_text_id)");
        $t_from_clauses = array($t_bug_text_table, $t_project_table, $t_bug_table);
    } else {
        $t_from_clauses = array($t_project_table, $t_bug_table);
    }
    $t_select = implode(', ', array_unique($t_select_clauses));
    $t_from = 'FROM ' . implode(', ', array_unique($t_from_clauses));
    $t_join = implode(' ', $t_join_clauses);
    if (count($t_where_clauses) > 0) {
        $t_where = 'WHERE ' . implode(' AND ', $t_where_clauses);
    } else {
        $t_where = '';
    }
    # Possibly do two passes. First time, grab the IDs of issues that match the filters. Second time, grab the IDs of issues that
    # have bugnotes that match the text search if necessary.
    $t_id_array = array();
    for ($i = 0; $i < 2; $i++) {
        $t_id_where = $t_where;
        $t_id_join = $t_join;
        if ($i == 0) {
            if (!is_blank($t_id_where) && !is_blank($t_textsearch_where_clause)) {
                $t_id_where = $t_id_where . ' AND ' . $t_textsearch_where_clause;
            }
        } else {
            if (!is_blank($t_textsearch_wherejoin_clause)) {
                $t_id_where = $t_id_where . ' AND ' . $t_textsearch_wherejoin_clause;
                $t_id_join = $t_id_join . " INNER JOIN {$t_bugnote_table} ON {$t_bugnote_table}.bug_id = {$t_bug_table}.id";
                $t_id_join = $t_id_join . " INNER JOIN {$t_bugnote_text_table} ON {$t_bugnote_text_table}.id = {$t_bugnote_table}.bugnote_text_id";
            }
        }
        $query = "SELECT DISTINCT {$t_bug_table}.id AS id\r\n\t\t\t\t\t\t{$t_from}\r\n\t\t\t\t\t\t{$t_id_join}\r\n\t\t\t\t\t\t{$t_id_where}";
        if ($i == 0 || !is_blank($t_textsearch_wherejoin_clause)) {
            $result = db_query($query);
            $row_count = db_num_rows($result);
            for ($j = 0; $j < $row_count; $j++) {
                $row = db_fetch_array($result);
                $t_id_array[] = db_prepare_int($row['id']);
            }
        }
    }
    $t_id_array = array_unique($t_id_array);
    # Get the total number of bugs that meet the criteria.
    $bug_count = count($t_id_array);
    $rows = array();
    if ($bug_count > 0) {
        $t_where = "WHERE {$t_bug_table}.id in (" . implode(", ", $t_id_array) . ")";
    } else {
        return $rows;
    }
    $t_from = 'FROM ' . $t_bug_table;
    # write the value back in case the caller wants to know
    $p_bug_count = $bug_count;
    if (null === $p_per_page) {
        $p_per_page = (int) $t_filter['per_page'];
    } else {
        if (-1 == $p_per_page) {
            $p_per_page = $bug_count;
        }
    }
    # Guard against silly values of $f_per_page.
    if (0 == $p_per_page) {
        $p_per_page = $bug_count;
        // 0 - means show all
    }
    $p_per_page = (int) abs($p_per_page);
    # Use $bug_count and $p_per_page to determine how many pages
    # to split this list up into.
    # For the sake of consistency have at least one page, even if it
    # is empty.
    $t_page_count = ceil($bug_count / $p_per_page);
    if ($t_page_count < 1) {
        $t_page_count = 1;
    }
    # write the value back in case the caller wants to know
    $p_page_count = $t_page_count;
    # Make sure $p_page_number isn't past the last page.
    if ($p_page_number > $t_page_count) {
        $p_page_number = $t_page_count;
    }
    # Make sure $p_page_number isn't before the first page
    if ($p_page_number < 1) {
        $p_page_number = 1;
    }
    # Now add the rest of the criteria i.e. sorting, limit.
    # if sort is blank then default the sort and direction.  This is to fix the
    # symptoms of #3953.  Note that even if the main problem is fixed, we may
    # have to keep this code for a while to handle filters saved with this blank field.
    if (is_blank($t_filter['sort'])) {
        $t_filter['sort'] = 'last_updated';
        $t_filter['dir'] = 'DESC';
    }
    $t_order_array = array();
    $t_sort_fields = split(',', $t_filter['sort']);
    $t_dir_fields = split(',', $t_filter['dir']);
    if ('on' == $t_filter['sticky_issues'] && NULL !== $p_show_sticky) {
        $t_order_array[] = "sticky DESC";
    }
    $t_join = '';
    for ($i = 0; $i < count($t_sort_fields); $i++) {
        $c_sort = db_prepare_string($t_sort_fields[$i]);
        if (!in_array($t_sort_fields[$i], array_slice($t_sort_fields, $i + 1))) {
            # if sorting by a custom field
            if (strpos($c_sort, 'custom_') === 0) {
                $t_custom_field = substr($c_sort, strlen('custom_'));
                $t_custom_field_id = custom_field_get_id_from_name($t_custom_field);
                $t_join .= " LEFT JOIN {$t_custom_field_string_table} ON ( ( {$t_custom_field_string_table}.bug_id = {$t_bug_table}.id ) AND ( {$t_custom_field_string_table}.field_id = {$t_custom_field_id} ) )";
                $c_sort = "{$t_custom_field_string_table}.value";
                $t_select_clauses[] = "{$t_custom_field_string_table}.value";
            }
            if ('DESC' == $t_dir_fields[$i]) {
                $c_dir = 'DESC';
            } else {
                $c_dir = 'ASC';
            }
            $t_order_array[] = "{$c_sort} {$c_dir}";
        }
    }
    # add basic sorting if necessary
    if (!in_array('last_updated', $t_sort_fields)) {
        $t_order_array[] = 'last_updated DESC';
    }
    if (!in_array('date_submitted', $t_sort_fields)) {
        $t_order_array[] = 'date_submitted DESC';
    }
    $t_order = " ORDER BY " . implode(', ', $t_order_array);
    $t_select = implode(', ', array_unique($t_select_clauses));
    $query2 = "SELECT DISTINCT {$t_select}\r\n\t\t\t\t\t{$t_from}\r\n\t\t\t\t\t{$t_join}\r\n\t\t\t\t\t{$t_where}\r\n\t\t\t\t\t{$t_order}";
    # Figure out the offset into the db query
    #
    # for example page number 1, per page 5:
    #     t_offset = 0
    # for example page number 2, per page 5:
    #     t_offset = 5
    $c_per_page = db_prepare_int($p_per_page);
    $c_page_number = db_prepare_int($p_page_number);
    $t_offset = ($c_page_number - 1) * $c_per_page;
    # perform query
    $result2 = db_query($query2, $c_per_page, $t_offset);
    $row_count = db_num_rows($result2);
    $t_id_array_lastmod = array();
    for ($i = 0; $i < $row_count; $i++) {
        $row = db_fetch_array($result2);
        $t_id_array_lastmod[] = db_prepare_int($row['id']);
        $row['date_submitted'] = db_unixtimestamp($row['date_submitted']);
        $row['last_updated'] = db_unixtimestamp($row['last_updated']);
        array_push($rows, $row);
    }
    $t_id_array_lastmod = array_unique($t_id_array_lastmod);
    // paulr: it should be impossible for t_id_array_lastmod to be array():
    // that would imply that $t_id_array is null which aborts this function early
    //if ( count( $t_id_array_lastmod ) > 0 ) {
    $t_where = "WHERE {$t_bugnote_table}.bug_id in (" . implode(", ", $t_id_array_lastmod) . ")";
    $query3 = "SELECT DISTINCT bug_id,MAX(last_modified) as last_modified, COUNT(last_modified) as count FROM {$t_bugnote_table} {$t_where} GROUP BY bug_id";
    # perform query
    $result3 = db_query($query3);
    $row_count = db_num_rows($result3);
    for ($i = 0; $i < $row_count; $i++) {
        $row = db_fetch_array($result3);
        $t_stats[$row['bug_id']] = $row;
    }
    foreach ($rows as $row) {
        if (!isset($t_stats[$row['id']])) {
            bug_cache_database_result($row, false);
        } else {
            bug_cache_database_result($row, $t_stats[$row['id']]);
        }
    }
    return $rows;
}
		<td>
			<textarea <?php 
    echo helper_get_tab_index();
    ?>
 id="additional_info" name="additional_info" cols="80" rows="10"><?php 
    echo string_textarea($f_additional_info);
    ?>
</textarea>
		</td>
	</tr>
<?php 
}
$t_custom_fields_found = false;
$t_related_custom_field_ids = custom_field_get_linked_ids($t_project_id);
foreach ($t_related_custom_field_ids as $t_id) {
    $t_def = custom_field_get_definition($t_id);
    if (($t_def['display_report'] || $t_def['require_report']) && custom_field_has_write_access_to_project($t_id, $t_project_id)) {
        $t_custom_fields_found = true;
        ?>
	<tr>
		<th class="category">
			<?php 
        if ($t_def['require_report']) {
            ?>
				<span class="required">*</span>
			<?php 
        }
        ?>
			<?php 
        if ($t_def['type'] != CUSTOM_FIELD_TYPE_RADIO && $t_def['type'] != CUSTOM_FIELD_TYPE_CHECKBOX) {
            ?>
function custom_function_default_print_column_value($p_column, $p_issue_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE)
{
    if (COLUMNS_TARGET_CSV_PAGE == $p_columns_target) {
        $t_column_start = '';
        $t_column_end = '';
        $t_column_empty = '';
    } else {
        $t_column_start = '<td>';
        $t_column_end = '</td>';
        $t_column_empty = '&nbsp;';
    }
    if (strpos($p_column, 'custom_') === 0) {
        echo $t_column_start;
        $t_custom_field = substr($p_column, 7);
        $t_field_id = custom_field_get_id_from_name($t_custom_field);
        if ($t_field_id === false) {
            echo '@', $t_custom_field, '@';
        } else {
            $t_issue_id = $p_issue_row['id'];
            $t_project_id = $p_issue_row['project_id'];
            if (custom_field_is_linked($t_field_id, $t_project_id)) {
                $t_def = custom_field_get_definition($t_field_id);
                print_custom_field_value($t_def, $t_field_id, $t_issue_id);
            } else {
                // field is not linked to project
                echo $t_column_empty;
            }
        }
        echo $t_column_end;
    } else {
        if ($p_columns_target != COLUMNS_TARGET_CSV_PAGE) {
            $t_function = 'print_column_' . $p_column;
        } else {
            $t_function = 'csv_format_' . $p_column;
        }
        if (function_exists($t_function)) {
            if ($p_columns_target != COLUMNS_TARGET_CSV_PAGE) {
                $t_function($p_issue_row, $p_columns_target);
            } else {
                $t_function($p_issue_row[$p_column]);
            }
        } else {
            if (isset($p_issue_row[$p_column])) {
                echo $t_column_start . $p_issue_row[$p_column] . $t_column_end;
            } else {
                echo $t_column_start . '@' . $p_column . '@' . $t_column_end;
            }
        }
    }
}
Exemple #25
0
/**
 * Gets the localized title for the specified column.  The column can be native or custom.
 * The custom fields must contain the 'custom_' prefix.
 *
 * @param string $p_column - The column name.
 * @return string The column localized name.
 * @access public
 */
function column_get_title($p_column)
{
    $t_custom_field = column_get_custom_field_name($p_column);
    if ($t_custom_field !== null) {
        $t_field_id = custom_field_get_id_from_name($t_custom_field);
        if ($t_field_id === false) {
            $t_custom_field = '@' . $t_custom_field . '@';
        } else {
            $t_def = custom_field_get_definition($t_field_id);
            $t_custom_field = lang_get_defaulted($t_def['name']);
        }
        return $t_custom_field;
    }
    $t_plugin_columns = columns_get_plugin_columns();
    if (isset($t_plugin_columns[$p_column])) {
        $t_column_object = $t_plugin_columns[$p_column];
        return $t_column_object->title;
    }
    switch ($p_column) {
        case 'attachment_count':
            return lang_get('attachments');
        case 'bugnotes_count':
            return '#';
        case 'category_id':
            return lang_get('category');
        case 'edit':
            return '';
        case 'handler_id':
            return lang_get('assigned_to');
        case 'last_updated':
            return lang_get('updated');
        case 'os_build':
            return lang_get('os_version');
        case 'project_id':
            return lang_get('email_project');
        case 'reporter_id':
            return lang_get('reporter');
        case 'selection':
            return '';
        case 'sponsorship_total':
            return sponsorship_get_currency();
        case 'version':
            return lang_get('product_version');
        case 'view_state':
            return lang_get('view_status');
        default:
            return lang_get_defaulted($p_column);
    }
}
Exemple #26
0
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] = string_display($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>";
    }
}