Esempio n. 1
0
function project_ensure_exists($p_project_id)
{
    if (!project_exists($p_project_id)) {
        error_parameters($p_project_id);
        trigger_error(ERROR_PROJECT_NOT_FOUND, ERROR);
    }
}
Esempio n. 2
0
}
# Manage filter's persistency through cookie
$t_cookie_name = config_get('manage_config_cookie');
if ($t_filter_save) {
    # Save user's filter to the cookie
    $t_cookie_string = implode(':', array($t_filter_user_value, $t_filter_project_value, $t_filter_config_value));
    gpc_set_cookie($t_cookie_name, $t_cookie_string, true);
} else {
    # Retrieve the filter from the cookie if it exists
    $t_cookie_string = gpc_get_cookie($t_cookie_name, null);
    if (null !== $t_cookie_string) {
        $t_cookie_contents = explode(':', $t_cookie_string);
        $t_filter_user_value = $t_cookie_contents[0];
        $t_filter_project_value = $t_cookie_contents[1];
        $t_filter_config_value = check_config_value($t_cookie_contents[2]);
        if ($t_filter_project_value != META_FILTER_NONE && !project_exists($t_filter_project_value)) {
            $t_filter_project_value = ALL_PROJECTS;
        }
    }
}
# Get config edit values
$t_edit_user_id = gpc_get_int('user_id', $t_filter_user_value == META_FILTER_NONE ? ALL_USERS : $t_filter_user_value);
$t_edit_project_id = gpc_get_int('project_id', $t_filter_project_value == META_FILTER_NONE ? ALL_PROJECTS : $t_filter_project_value);
$t_edit_option = gpc_get_string('config_option', $t_filter_config_value == META_FILTER_NONE ? '' : $t_filter_config_value);
$t_edit_type = gpc_get_string('type', CONFIG_TYPE_DEFAULT);
$t_edit_value = gpc_get_string('value', '');
# Apply filters
# Get users in db having specific configs
$t_query = 'SELECT DISTINCT user_id FROM {config} WHERE user_id <> ' . db_param();
$t_result = db_query($t_query, array(ALL_USERS));
if ($t_filter_user_value != META_FILTER_NONE && $t_filter_user_value != ALL_USERS) {
Esempio n. 3
0
/**
 * Return the current project id as stored in a cookie, in an Array
 * If no cookie exists, the user's default project is returned
 * If the current project is a subproject, the return value will include
 * any parent projects
 * @return array
 */
function helper_get_current_project_trace()
{
    $t_cookie_name = config_get('project_cookie');
    $t_project_id = gpc_get_cookie($t_cookie_name, null);
    if (null === $t_project_id) {
        $t_bottom = current_user_get_pref('default_project');
        $t_parent = $t_bottom;
        $t_project_id = array($t_bottom);
        while (true) {
            $t_parent = project_hierarchy_get_parent($t_parent);
            if (0 == $t_parent) {
                break;
            }
            array_unshift($t_project_id, $t_parent);
        }
    } else {
        $t_project_id = explode(';', $t_project_id);
        $t_bottom = $t_project_id[count($t_project_id) - 1];
    }
    if (!project_exists($t_bottom) || 0 == project_get_field($t_bottom, 'enabled') || !access_has_project_level(VIEWER, $t_bottom)) {
        $t_project_id = array(ALL_PROJECTS);
    }
    return $t_project_id;
}
Esempio n. 4
0
/**
 * Localizes one raw history item specified by set the next parameters: $p_field_name, $p_type, $p_old_value, $p_new_value
 * Returns array with two elements indexed as 'note' and 'change'
 * @param string  $p_field_name The field name of the field being localized.
 * @param integer $p_type       The type of the history entry.
 * @param string  $p_old_value  The old value of the field.
 * @param string  $p_new_value  The new value of the field.
 * @param boolean $p_linkify    Whether to return a string containing hyperlinks.
 * @return array
 */
function history_localize_item($p_field_name, $p_type, $p_old_value, $p_new_value, $p_linkify = true)
{
    $t_note = '';
    $t_change = '';
    $t_field_localized = $p_field_name;
    $t_raw = true;
    if (PLUGIN_HISTORY == $p_type) {
        $t_note = lang_get_defaulted('plugin_' . $p_field_name, $p_field_name);
        $t_change = isset($p_new_value) ? $p_old_value . ' => ' . $p_new_value : $p_old_value;
        return array('note' => $t_note, 'change' => $t_change, 'raw' => true);
    }
    switch ($p_field_name) {
        case 'category':
            $t_field_localized = lang_get('category');
            break;
        case 'status':
            $p_old_value = get_enum_element('status', $p_old_value);
            $p_new_value = get_enum_element('status', $p_new_value);
            $t_field_localized = lang_get('status');
            break;
        case 'severity':
            $p_old_value = get_enum_element('severity', $p_old_value);
            $p_new_value = get_enum_element('severity', $p_new_value);
            $t_field_localized = lang_get('severity');
            break;
        case 'reproducibility':
            $p_old_value = get_enum_element('reproducibility', $p_old_value);
            $p_new_value = get_enum_element('reproducibility', $p_new_value);
            $t_field_localized = lang_get('reproducibility');
            break;
        case 'resolution':
            $p_old_value = get_enum_element('resolution', $p_old_value);
            $p_new_value = get_enum_element('resolution', $p_new_value);
            $t_field_localized = lang_get('resolution');
            break;
        case 'priority':
            $p_old_value = get_enum_element('priority', $p_old_value);
            $p_new_value = get_enum_element('priority', $p_new_value);
            $t_field_localized = lang_get('priority');
            break;
        case 'eta':
            $p_old_value = get_enum_element('eta', $p_old_value);
            $p_new_value = get_enum_element('eta', $p_new_value);
            $t_field_localized = lang_get('eta');
            break;
        case 'view_state':
            $p_old_value = get_enum_element('view_state', $p_old_value);
            $p_new_value = get_enum_element('view_state', $p_new_value);
            $t_field_localized = lang_get('view_status');
            break;
        case 'projection':
            $p_old_value = get_enum_element('projection', $p_old_value);
            $p_new_value = get_enum_element('projection', $p_new_value);
            $t_field_localized = lang_get('projection');
            break;
        case 'sticky':
            $p_old_value = gpc_string_to_bool($p_old_value) ? lang_get('yes') : lang_get('no');
            $p_new_value = gpc_string_to_bool($p_new_value) ? lang_get('yes') : lang_get('no');
            $t_field_localized = lang_get('sticky_issue');
            break;
        case 'project_id':
            if (project_exists($p_old_value)) {
                $p_old_value = project_get_field($p_old_value, 'name');
            } else {
                $p_old_value = '@' . $p_old_value . '@';
            }
            # Note that the new value maybe an intermediately project and not the
            # current one.
            if (project_exists($p_new_value)) {
                $p_new_value = project_get_field($p_new_value, 'name');
            } else {
                $p_new_value = '@' . $p_new_value . '@';
            }
            $t_field_localized = lang_get('email_project');
            break;
        case 'handler_id':
            $t_field_localized = lang_get('assigned_to');
        case 'reporter_id':
            if ('reporter_id' == $p_field_name) {
                $t_field_localized = lang_get('reporter');
            }
            if (0 == $p_old_value) {
                $p_old_value = '';
            } else {
                $p_old_value = user_get_name($p_old_value);
            }
            if (0 == $p_new_value) {
                $p_new_value = '';
            } else {
                $p_new_value = user_get_name($p_new_value);
            }
            break;
        case 'version':
            $t_field_localized = lang_get('product_version');
            break;
        case 'fixed_in_version':
            $t_field_localized = lang_get('fixed_in_version');
            break;
        case 'target_version':
            $t_field_localized = lang_get('target_version');
            break;
        case 'date_submitted':
            $p_old_value = date(config_get('normal_date_format'), $p_old_value);
            $p_new_value = date(config_get('normal_date_format'), $p_new_value);
            $t_field_localized = lang_get('date_submitted');
            break;
        case 'last_updated':
            $p_old_value = date(config_get('normal_date_format'), $p_old_value);
            $p_new_value = date(config_get('normal_date_format'), $p_new_value);
            $t_field_localized = lang_get('last_update');
            break;
        case 'os':
            $t_field_localized = lang_get('os');
            break;
        case 'os_build':
            $t_field_localized = lang_get('os_version');
            break;
        case 'build':
            $t_field_localized = lang_get('build');
            break;
        case 'platform':
            $t_field_localized = lang_get('platform');
            break;
        case 'summary':
            $t_field_localized = lang_get('summary');
            break;
        case 'duplicate_id':
            $t_field_localized = lang_get('duplicate_id');
            break;
        case 'sponsorship_total':
            $t_field_localized = lang_get('sponsorship_total');
            break;
        case 'due_date':
            if ($p_old_value !== '') {
                $p_old_value = date(config_get('normal_date_format'), (int) $p_old_value);
            }
            if ($p_new_value !== '') {
                $p_new_value = date(config_get('normal_date_format'), (int) $p_new_value);
            }
            $t_field_localized = lang_get('due_date');
            break;
        default:
            # assume it's a custom field name
            $t_field_id = custom_field_get_id_from_name($p_field_name);
            if (false !== $t_field_id) {
                $t_cf_type = custom_field_type($t_field_id);
                if ('' != $p_old_value) {
                    $p_old_value = string_custom_field_value_for_email($p_old_value, $t_cf_type);
                }
                $p_new_value = string_custom_field_value_for_email($p_new_value, $t_cf_type);
                $t_field_localized = lang_get_defaulted($p_field_name);
            }
    }
    if (NORMAL_TYPE != $p_type) {
        switch ($p_type) {
            case NEW_BUG:
                $t_note = lang_get('new_bug');
                break;
            case BUGNOTE_ADDED:
                $t_note = lang_get('bugnote_added') . ': ' . $p_old_value;
                break;
            case BUGNOTE_UPDATED:
                $t_note = lang_get('bugnote_edited') . ': ' . $p_old_value;
                $t_old_value = (int) $p_old_value;
                $t_new_value = (int) $p_new_value;
                if ($p_linkify && bug_revision_exists($t_new_value)) {
                    if (bugnote_exists($t_old_value)) {
                        $t_bug_revision_view_page_argument = 'bugnote_id=' . $t_old_value . '#r' . $t_new_value;
                    } else {
                        $t_bug_revision_view_page_argument = 'rev_id=' . $t_new_value;
                    }
                    $t_change = '<a href="bug_revision_view_page.php?' . $t_bug_revision_view_page_argument . '">' . lang_get('view_revisions') . '</a>';
                    $t_raw = false;
                }
                break;
            case BUGNOTE_DELETED:
                $t_note = lang_get('bugnote_deleted') . ': ' . $p_old_value;
                break;
            case DESCRIPTION_UPDATED:
                $t_note = lang_get('description_updated');
                $t_old_value = (int) $p_old_value;
                if ($p_linkify && bug_revision_exists($t_old_value)) {
                    $t_change = '<a href="bug_revision_view_page.php?rev_id=' . $t_old_value . '#r' . $t_old_value . '">' . lang_get('view_revisions') . '</a>';
                    $t_raw = false;
                }
                break;
            case ADDITIONAL_INFO_UPDATED:
                $t_note = lang_get('additional_information_updated');
                $t_old_value = (int) $p_old_value;
                if ($p_linkify && bug_revision_exists($t_old_value)) {
                    $t_change = '<a href="bug_revision_view_page.php?rev_id=' . $t_old_value . '#r' . $t_old_value . '">' . lang_get('view_revisions') . '</a>';
                    $t_raw = false;
                }
                break;
            case STEP_TO_REPRODUCE_UPDATED:
                $t_note = lang_get('steps_to_reproduce_updated');
                $t_old_value = (int) $p_old_value;
                if ($p_linkify && bug_revision_exists($t_old_value)) {
                    $t_change = '<a href="bug_revision_view_page.php?rev_id=' . $t_old_value . '#r' . $t_old_value . '">' . lang_get('view_revisions') . '</a>';
                    $t_raw = false;
                }
                break;
            case FILE_ADDED:
                $t_note = lang_get('file_added') . ': ' . $p_old_value;
                break;
            case FILE_DELETED:
                $t_note = lang_get('file_deleted') . ': ' . $p_old_value;
                break;
            case BUGNOTE_STATE_CHANGED:
                $p_old_value = get_enum_element('view_state', $p_old_value);
                $t_note = lang_get('bugnote_view_state') . ': ' . $p_new_value . ': ' . $p_old_value;
                break;
            case BUG_MONITOR:
                $p_old_value = user_get_name($p_old_value);
                $t_note = lang_get('bug_monitor') . ': ' . $p_old_value;
                break;
            case BUG_UNMONITOR:
                if ($p_old_value !== '') {
                    $p_old_value = user_get_name($p_old_value);
                }
                $t_note = lang_get('bug_end_monitor') . ': ' . $p_old_value;
                break;
            case BUG_DELETED:
                $t_note = lang_get('bug_deleted') . ': ' . $p_old_value;
                break;
            case BUG_ADD_SPONSORSHIP:
                $t_note = lang_get('sponsorship_added');
                $t_change = user_get_name($p_old_value) . ': ' . sponsorship_format_amount($p_new_value);
                break;
            case BUG_UPDATE_SPONSORSHIP:
                $t_note = lang_get('sponsorship_updated');
                $t_change = user_get_name($p_old_value) . ': ' . sponsorship_format_amount($p_new_value);
                break;
            case BUG_DELETE_SPONSORSHIP:
                $t_note = lang_get('sponsorship_deleted');
                $t_change = user_get_name($p_old_value) . ': ' . sponsorship_format_amount($p_new_value);
                break;
            case BUG_PAID_SPONSORSHIP:
                $t_note = lang_get('sponsorship_paid');
                $t_change = user_get_name($p_old_value) . ': ' . get_enum_element('sponsorship', $p_new_value);
                break;
            case BUG_ADD_RELATIONSHIP:
                $t_note = lang_get('relationship_added');
                $t_change = relationship_get_description_for_history($p_old_value) . ' ' . bug_format_id($p_new_value);
                break;
            case BUG_REPLACE_RELATIONSHIP:
                $t_note = lang_get('relationship_replaced');
                $t_change = relationship_get_description_for_history($p_old_value) . ' ' . bug_format_id($p_new_value);
                break;
            case BUG_DEL_RELATIONSHIP:
                $t_note = lang_get('relationship_deleted');
                # Fix for #7846: There are some cases where old value is empty, this may be due to an old bug.
                if (!is_blank($p_old_value) && $p_old_value > 0) {
                    $t_change = relationship_get_description_for_history($p_old_value) . ' ' . bug_format_id($p_new_value);
                } else {
                    $t_change = bug_format_id($p_new_value);
                }
                break;
            case BUG_CLONED_TO:
                $t_note = lang_get('bug_cloned_to') . ': ' . bug_format_id($p_new_value);
                break;
            case BUG_CREATED_FROM:
                $t_note = lang_get('bug_created_from') . ': ' . bug_format_id($p_new_value);
                break;
            case TAG_ATTACHED:
                $t_note = lang_get('tag_history_attached') . ': ' . $p_old_value;
                break;
            case TAG_DETACHED:
                $t_note = lang_get('tag_history_detached') . ': ' . $p_old_value;
                break;
            case TAG_RENAMED:
                $t_note = lang_get('tag_history_renamed');
                $t_change = $p_old_value . ' => ' . $p_new_value;
                break;
            case BUG_REVISION_DROPPED:
                $t_note = lang_get('bug_revision_dropped_history') . ': ' . bug_revision_get_type_name($p_new_value) . ': ' . $p_old_value;
                break;
            case BUGNOTE_REVISION_DROPPED:
                $t_note = lang_get('bugnote_revision_dropped_history') . ': ' . $p_new_value . ': ' . $p_old_value;
                break;
        }
    }
    # output special cases
    if (NORMAL_TYPE == $p_type) {
        $t_note = $t_field_localized;
        $t_change = $p_old_value . ' => ' . $p_new_value;
    }
    # end if DEFAULT
    return array('note' => $t_note, 'change' => $t_change, 'raw' => $t_raw);
}
Esempio n. 5
0
 */
/**
 * MantisBT Core API's
 */
require_once 'core.php';
require_once 'news_api.php';
require_once 'string_api.php';
news_ensure_enabled();
$f_news_id = gpc_get_int('news_id');
$f_action = gpc_get_string('action', '');
# If deleting item redirect to delete script
if ('delete' == $f_action) {
    form_security_validate('news_delete');
    $row = news_get_row($f_news_id);
    # This check is to allow deleting of news items that were left orphan due to bug #3723
    if (project_exists($row['project_id'])) {
        access_ensure_project_level(config_get('manage_news_threshold'), $row['project_id']);
    }
    helper_ensure_confirmed(lang_get('delete_news_sure_msg'), lang_get('delete_news_item_button'));
    news_delete($f_news_id);
    form_security_purge('news_delete');
    print_header_redirect('news_menu_page.php', true);
}
# Retrieve news item data and prefix with v_
$row = news_get_row($f_news_id);
if ($row) {
    extract($row, EXTR_PREFIX_ALL, 'v');
}
access_ensure_project_level(config_get('manage_news_threshold'), $v_project_id);
$v_headline = string_attribute($v_headline);
$v_body = string_textarea($v_body);
Esempio n. 6
0
}
if (isset($_GET['cat'])) {
    echo '&cat=' . $_GET['cat'];
}
if (isset($_GET['pio'])) {
    echo '&pio=' . $_GET['pio'];
}
echo '\';">x</div>';
if (isset($_POST['submit'])) {
    if ($_POST['select'] == "uplpro" && $_POST['proname'] == "") {
        $error[] = 'Du hast keinen Projektnamen eingegeben!';
    }
    if ($_POST['select'] == "uplpro" && $_POST['procat'] == "") {
        $error[] = 'Du hast keine Projektkategorie ausgewählt!';
    }
    if ($_POST['select'] == "uplpro" && !project_exists($_POST['proname'])) {
        $error[] = 'Der Projektname ist bereits vorhanden!';
    }
    if ($_POST['select'] != "uplpro" && $_POST['title'] == "") {
        $error[] = 'Du hast keinen Titel eingetragen!';
    }
    if ($_POST['select'] == "uplsin" && $_POST['descr'] == "") {
        $error[] = 'Du hast keine Beschreibung eingegeben!';
    }
    if ($_POST['select'] == "uplsin" && $_POST['type'] == "") {
        $error[] = 'Du hast keinen Typ angegeben!';
    }
    if ($_POST['select'] == "uplscr" && $_POST['script'] == "") {
        $error[] = 'Du hast keinen Text eingegeben!';
    }
    if ($_POST['select'] == "uplav" && $_POST['mtype'] == "") {
Esempio n. 7
0
 public function process_mailbox($p_mailbox)
 {
     $this->_mailbox = $p_mailbox + ERP_get_default_mailbox();
     if ($this->_functionality_enabled) {
         if ($this->_mailbox['enabled']) {
             // Check whether EmailReporting supports the mailbox type. The check is based on available default ports
             if (isset($this->_default_ports[$this->_mailbox['mailbox_type']])) {
                 if (project_exists($this->_mailbox['project_id'])) {
                     if (category_exists($this->_mailbox['global_category_id'])) {
                         $t_upload_folder_passed = TRUE;
                         if ($this->_allow_file_upload && $this->_file_upload_method == DISK) {
                             $t_upload_folder_passed = FALSE;
                             $t_file_path = project_get_field($this->_mailbox['project_id'], 'file_path');
                             if ($t_file_path == '') {
                                 $t_file_path = config_get('absolute_path_default_upload_folder');
                             }
                             $t_file_path = ERP_prepare_directory_string($t_file_path, TRUE);
                             $t_real_file_path = ERP_prepare_directory_string($t_file_path);
                             if (!file_exists($t_file_path) || !is_dir($t_file_path) || !is_writable($t_file_path) || !is_readable($t_file_path)) {
                                 $this->custom_error('Upload folder is not writable: ' . $t_file_path . "\n");
                             } elseif (strcasecmp($t_real_file_path, $t_file_path) !== 0) {
                                 $this->custom_error('Upload folder is not an absolute path' . "\n" . 'Upload folder: ' . $t_file_path . "\n" . 'Absolute path: ' . $t_real_file_path . "\n");
                             } else {
                                 $t_upload_folder_passed = TRUE;
                             }
                         }
                         if ($t_upload_folder_passed) {
                             $this->prepare_mailbox_hostname();
                             if (!$this->_test_only && $this->_mail_debug) {
                                 var_dump($this->_mailbox);
                             }
                             $this->show_memory_usage('Start process mailbox');
                             $t_process_mailbox_function = 'process_' . strtolower($this->_mailbox['mailbox_type']) . '_mailbox';
                             $this->{$t_process_mailbox_function}();
                             $this->show_memory_usage('Finished process mailbox');
                         }
                     } else {
                         $this->custom_error('Category does not exist');
                     }
                 } else {
                     $this->custom_error('Project does not exist');
                 }
             } else {
                 $this->custom_error('Unknown mailbox type');
             }
         } else {
             $this->custom_error('Mailbox disabled');
         }
     }
     return $this->_result;
 }
Esempio n. 8
0
function helper_get_current_project_trace()
{
    $t_cookie_name = config_get('project_cookie');
    $t_project_id = gpc_get_cookie($t_cookie_name, null);
    if (null === $t_project_id) {
        $t_bottom = current_user_get_pref('default_project');
        $t_project_id = array($t_bottom);
    } else {
        $t_project_id = split(';', $t_project_id);
        $t_bottom = $t_project_id[count($t_project_id) - 1];
    }
    if (!project_exists($t_bottom) || 0 == project_get_field($t_bottom, 'enabled') || !access_has_project_level(VIEWER, $t_bottom)) {
        $t_project_id = array(ALL_PROJECTS);
    }
    return $t_project_id;
}
Esempio n. 9
0
/**
 * Update Issue in database
 *
 * Created By KGB
 * @param string $p_username The name of the user trying to add the issue.
 * @param string $p_password The password of the user.
 * @param Array $p_issue A IssueData structure containing information about the new issue.
 * @return integer The id of the created issue.
 */
function mc_issue_update($p_username, $p_password, $p_issue_id, $p_issue)
{
    $t_user_id = mci_check_login($p_username, $p_password);
    if ($t_user_id === false) {
        return new soap_fault('Client', '', 'Access Denied');
    }
    if (!bug_exists($p_issue_id)) {
        return new soap_fault('Server', '', "Issue '{$p_issue_id}' does not exist.");
    }
    $t_project_id = bug_get_field($p_issue_id, 'project_id');
    if (!mci_has_readwrite_access($t_user_id, $t_project_id)) {
        return new soap_fault('Client', '', 'Access Denied');
    }
    extract($p_issue, EXTR_PREFIX_ALL, 'v');
    $t_project_id = mci_get_project_id($v_project);
    $t_handler_id = mci_get_user_id($v_handler);
    $t_priority_id = mci_get_priority_id($v_priority);
    $t_severity_id = mci_get_severity_id($v_severity);
    $t_status_id = mci_get_status_id($v_status);
    $t_reproducibility_id = mci_get_reproducibility_id($v_reproducibility);
    $t_resolution_id = mci_get_resolution_id($v_resolution);
    $t_projection_id = mci_get_projection_id($v_projection);
    $t_eta_id = mci_get_eta_id($v_eta);
    $t_view_state_id = mci_get_view_state_id($v_view_state);
    $t_reporter_id = mci_get_user_id($v_reporter);
    if ($t_reporter_id == 0) {
        $t_reporter_id = $t_user_id;
    }
    if ($t_project_id == 0 || !project_exists($t_project_id)) {
        if ($t_project_id == 0) {
            return new soap_fault('Client', '', "Project '" . $v_project['name'] . "' does not exist.");
        } else {
            return new soap_fault('Client', '', "Project '{$t_project_id}' does not exist.");
        }
    }
    if (!access_has_bug_level(config_get('update_bug_threshold'), $p_issue_id, $t_user_id)) {
        return new soap_fault('Client', '', "User '{$t_user_id}' does not have access right to report issues.");
    }
    if ($t_handler_id != 0 && !user_exists($t_handler_id)) {
        return new soap_fault('Client', '', "User '{$t_handler_id}' does not exist.");
    }
    if (!in_array($v_category, mci_category_get_all_rows($t_project_id, $t_user_id))) {
        $t_error_when_category_not_found = config_get('mc_error_when_category_not_found');
        if ($t_error_when_category_not_found == ON) {
            if (is_blank($v_category) && count(category_get_all_rows($t_project_id)) == 0) {
                $v_category = '';
                // it is ok to have category as empty if project has no categories
            } else {
                return new soap_fault('Client', '', "Category '{$v_category}' does not exist in project '{$t_project_id}'.");
            }
        } else {
            $t_category_when_not_found = config_get('mc_category_when_not_found');
            $v_category = $t_category_when_not_found;
        }
    }
    if (isset($v_version) && !is_blank($v_version) && !version_get_id($v_version, $t_project_id)) {
        $t_error_when_version_not_found = config_get('mc_error_when_version_not_found');
        if ($t_error_when_version_not_found == ON) {
            $t_project_name = project_get_name($t_project_id);
            return new soap_fault('Client', '', "Version '{$v_version}' does not exist in project '{$t_project_name}'.");
        } else {
            $t_version_when_not_found = config_get('mc_version_when_not_found');
            $v_version = $t_version_when_not_found;
        }
    }
    if (is_blank($v_summary)) {
        return new soap_fault('Client', '', "Mandatory field 'summary' is missing.");
    }
    if (is_blank($v_description)) {
        return new soap_fault('Client', '', "Mandatory field 'description' is missing.");
    }
    if ($v_priority == 0) {
        $v_priority = config_get('default_bug_priority');
    }
    if ($v_severity == 0) {
        $v_severity = config_get('default_bug_severity');
    }
    if ($v_view_state == 0) {
        $v_view_state = config_get('default_bug_view_status');
    }
    if ($v_reproducibility == 0) {
        $v_reproducibility = 10;
    }
    $t_bug_data = new BugData();
    $t_bug_data->project_id = $t_project_id;
    $t_bug_data->reporter_id = $t_reporter_id;
    $t_bug_data->handler_id = $t_handler_id;
    $t_bug_data->priority = $t_priority_id;
    $t_bug_data->severity = $t_severity_id;
    $t_bug_data->reproducibility = $t_reproducibility_id;
    $t_bug_data->status = $t_status_id;
    $t_bug_data->resolution = $t_resolution_id;
    $t_bug_data->projection = $t_projection_id;
    $t_bug_data->category = $v_category;
    $t_bug_data->date_submitted = isset($v_date_submitted) ? $v_date_submitted : '';
    $t_bug_data->last_updated = isset($v_last_updated) ? $v_last_updated : '';
    $t_bug_data->eta = $t_eta_id;
    $t_bug_data->os = isset($v_os) ? $v_os : '';
    $t_bug_data->os_build = isset($v_os_build) ? $v_os_build : '';
    $t_bug_data->platform = isset($v_platform) ? $v_platform : '';
    $t_bug_data->version = isset($v_version) ? $v_version : '';
    $t_bug_data->fixed_in_version = isset($v_fixed_in_version) ? $v_fixed_in_version : '';
    $t_bug_data->build = isset($v_build) ? $v_build : '';
    $t_bug_data->view_state = $t_view_state_id;
    $t_bug_data->summary = $v_summary;
    $t_bug_data->sponsorship_total = isset($v_sponsorship_total) ? $v_sponsorship_total : 0;
    # omitted:
    # var $bug_text_id
    # $t_bug_data->profile_id;
    # extended info
    $t_bug_data->description = $v_description;
    $t_bug_data->steps_to_reproduce = isset($v_steps_to_reproduce) ? $v_steps_to_reproduce : '';
    $t_bug_data->additional_information = isset($v_additional_information) ? $v_additional_information : '';
    # submit the issue
    $t_is_success = bug_update($p_issue_id, $t_bug_data, true, false);
    mci_issue_set_custom_fields($p_issue_id, $v_custom_fields);
    if (isset($v_notes) && is_array($v_notes)) {
        foreach ($v_notes as $t_note) {
            if (isset($t_note['view_state'])) {
                $t_view_state = $t_note['view_state'];
            } else {
                $t_view_state = config_get('default_bugnote_view_status');
            }
            // TODO: consider supporting updating of bugnotes and detecting the ones that haven't changed.
            $t_view_state_id = mci_get_enum_id_from_objectref('view_state', $t_view_state);
            bugnote_add($p_issue_id, $t_note['text'], '0:00', $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE);
        }
    }
    return $t_is_success;
}
Esempio n. 10
0
function history_localize_item($p_field_name, $p_type, $p_old_value, $p_new_value)
{
    $t_note = '';
    $t_change = '';
    $t_field_localized = $p_field_name;
    switch ($p_field_name) {
        case 'category':
            $t_field_localized = lang_get('category');
            break;
        case 'status':
            $p_old_value = get_enum_element('status', $p_old_value);
            $p_new_value = get_enum_element('status', $p_new_value);
            $t_field_localized = lang_get('status');
            break;
        case 'severity':
            $p_old_value = get_enum_element('severity', $p_old_value);
            $p_new_value = get_enum_element('severity', $p_new_value);
            $t_field_localized = lang_get('severity');
            break;
        case 'reproducibility':
            $p_old_value = get_enum_element('reproducibility', $p_old_value);
            $p_new_value = get_enum_element('reproducibility', $p_new_value);
            $t_field_localized = lang_get('reproducibility');
            break;
        case 'resolution':
            $p_old_value = get_enum_element('resolution', $p_old_value);
            $p_new_value = get_enum_element('resolution', $p_new_value);
            $t_field_localized = lang_get('resolution');
            break;
        case 'priority':
            $p_old_value = get_enum_element('priority', $p_old_value);
            $p_new_value = get_enum_element('priority', $p_new_value);
            $t_field_localized = lang_get('priority');
            break;
        case 'eta':
            $p_old_value = get_enum_element('eta', $p_old_value);
            $p_new_value = get_enum_element('eta', $p_new_value);
            $t_field_localized = lang_get('eta');
            break;
        case 'view_state':
            $p_old_value = get_enum_element('view_state', $p_old_value);
            $p_new_value = get_enum_element('view_state', $p_new_value);
            $t_field_localized = lang_get('view_status');
            break;
        case 'projection':
            $p_old_value = get_enum_element('projection', $p_old_value);
            $p_new_value = get_enum_element('projection', $p_new_value);
            $t_field_localized = lang_get('projection');
            break;
        case 'sticky':
            $p_old_value = gpc_string_to_bool($p_old_value) ? lang_get('yes') : lang_get('no');
            $p_new_value = gpc_string_to_bool($p_new_value) ? lang_get('yes') : lang_get('no');
            $t_field_localized = lang_get('sticky_issue');
            break;
        case 'project_id':
            if (project_exists($p_old_value)) {
                $p_old_value = project_get_field($p_old_value, 'name');
            } else {
                $p_old_value = '@' . $p_old_value . '@';
            }
            # Note that the new value maybe an intermediately project and not the
            # current one.
            if (project_exists($p_new_value)) {
                $p_new_value = project_get_field($p_new_value, 'name');
            } else {
                $p_new_value = '@' . $p_new_value . '@';
            }
            $t_field_localized = lang_get('email_project');
            break;
        case 'handler_id':
            $t_field_localized = lang_get('assigned_to');
        case 'reporter_id':
            if ('reporter_id' == $p_field_name) {
                $t_field_localized = lang_get('reporter');
            }
            if (0 == $p_old_value) {
                $p_old_value = '';
            } else {
                $p_old_value = user_get_name($p_old_value);
            }
            if (0 == $p_new_value) {
                $p_new_value = '';
            } else {
                $p_new_value = user_get_name($p_new_value);
            }
            break;
        case 'fixed_in_version':
            $t_field_localized = lang_get('fixed_in_version');
            break;
        case 'date_submitted':
            $t_field_localized = lang_get('date_submitted');
            break;
        case 'last_updated':
            $t_field_localized = lang_get('last_update');
            break;
        case 'summary':
            $t_field_localized = lang_get('summary');
            break;
        case 'duplicate_id':
            $t_field_localized = lang_get('duplicate_id');
            break;
        case 'sponsorship_total':
            $t_field_localized = lang_get('sponsorship_total');
            break;
        default:
            # assume it's a custom field name
            $t_field_id = custom_field_get_id_from_name($p_field_name);
            if (false !== $t_field_id) {
                $t_cf_type = custom_field_type($t_field_id);
                if ('' != $p_old_value) {
                    $p_old_value = string_custom_field_value_for_email($p_old_value, $t_cf_type);
                }
                $p_new_value = string_custom_field_value_for_email($p_new_value, $t_cf_type);
            }
    }
    if (NORMAL_TYPE != $p_type) {
        switch ($p_type) {
            case NEW_BUG:
                $t_note = lang_get('new_bug');
                break;
            case BUGNOTE_ADDED:
                $t_note = lang_get('bugnote_added') . ": " . $p_old_value;
                break;
            case BUGNOTE_UPDATED:
                $t_note = lang_get('bugnote_edited') . ": " . $p_old_value;
                break;
            case BUGNOTE_DELETED:
                $t_note = lang_get('bugnote_deleted') . ": " . $p_old_value;
                break;
            case DESCRIPTION_UPDATED:
                $t_note = lang_get('description_updated');
                break;
            case ADDITIONAL_INFO_UPDATED:
                $t_note = lang_get('additional_information_updated');
                break;
            case STEP_TO_REPRODUCE_UPDATED:
                $t_note = lang_get('steps_to_reproduce_updated');
                break;
            case FILE_ADDED:
                $t_note = lang_get('file_added') . ": " . $p_old_value;
                break;
            case FILE_DELETED:
                $t_note = lang_get('file_deleted') . ": " . $p_old_value;
                break;
            case BUGNOTE_STATE_CHANGED:
                $p_old_value = get_enum_element('view_state', $p_old_value);
                $t_note = lang_get('bugnote_view_state') . ": " . $p_old_value . ": " . $p_new_value;
                break;
            case BUG_MONITOR:
                $p_old_value = user_get_name($p_old_value);
                $t_note = lang_get('bug_monitor') . ": " . $p_old_value;
                break;
            case BUG_UNMONITOR:
                $p_old_value = user_get_name($p_old_value);
                $t_note = lang_get('bug_end_monitor') . ": " . $p_old_value;
                break;
            case BUG_DELETED:
                $t_note = lang_get('bug_deleted') . ": " . $p_old_value;
                break;
            case BUG_ADD_SPONSORSHIP:
                $t_note = lang_get('sponsorship_added');
                $t_change = user_get_name($p_old_value) . ': ' . sponsorship_format_amount($p_new_value);
                break;
            case BUG_UPDATE_SPONSORSHIP:
                $t_note = lang_get('sponsorship_updated');
                $t_change = user_get_name($p_old_value) . ': ' . sponsorship_format_amount($p_new_value);
                break;
            case BUG_DELETE_SPONSORSHIP:
                $t_note = lang_get('sponsorship_deleted');
                $t_change = user_get_name($p_old_value) . ': ' . sponsorship_format_amount($p_new_value);
                break;
            case BUG_PAID_SPONSORSHIP:
                $t_note = lang_get('sponsorship_paid');
                $t_change = user_get_name($p_old_value) . ': ' . get_enum_element('sponsorship', $p_new_value);
                break;
            case BUG_ADD_RELATIONSHIP:
                $t_note = lang_get('relationship_added');
                $t_change = relationship_get_description_for_history($p_old_value) . ' ' . bug_format_id($p_new_value);
                break;
            case BUG_REPLACE_RELATIONSHIP:
                $t_note = lang_get('relationship_replaced');
                $t_change = relationship_get_description_for_history($p_old_value) . ' ' . bug_format_id($p_new_value);
                break;
            case BUG_DEL_RELATIONSHIP:
                $t_note = lang_get('relationship_deleted');
                $t_change = relationship_get_description_for_history($p_old_value) . ' ' . bug_format_id($p_new_value);
                break;
            case BUG_CLONED_TO:
                $t_note = lang_get('bug_cloned_to');
                $t_change = bug_format_id($p_new_value);
                break;
            case BUG_CREATED_FROM:
                $t_note = lang_get('bug_created_from');
                $t_change = bug_format_id($p_new_value);
                break;
            case CHECKIN:
                $t_note = lang_get('checkin');
                break;
        }
    }
    # output special cases
    if (NORMAL_TYPE == $p_type) {
        $t_note = $t_field_localized;
        $t_change = $p_old_value . ' => ' . $p_new_value;
    }
    # end if DEFAULT
    return array('note' => $t_note, 'change' => $t_change);
}
Esempio n. 11
0
    $f_description = $t_bug->description;
    $f_steps_to_reproduce = $t_bug->steps_to_reproduce;
    $f_additional_info = $t_bug->additional_information;
    $f_view_state = (int) $t_bug->view_state;
    $f_due_date = $t_bug->due_date;
    $t_project_id = $t_bug->project_id;
} else {
    # Get Project Id and set it as current
    $t_current_project = helper_get_current_project();
    $t_project_id = gpc_get_int('project_id', $t_current_project);
    # If all projects, use default project if set
    $t_default_project = user_pref_get_pref(auth_get_current_user_id(), 'default_project');
    if (ALL_PROJECTS == $t_project_id && ALL_PROJECTS != $t_default_project) {
        $t_project_id = $t_default_project;
    }
    if ((ALL_PROJECTS == $t_project_id || project_exists($t_project_id)) && $t_project_id != $t_current_project && project_enabled($t_project_id)) {
        helper_set_current_project($t_project_id);
        # Reloading the page is required so that the project browser
        # reflects the new current project
        print_header_redirect($_SERVER['REQUEST_URI'], true, false, true);
    }
    # New issues cannot be reported for the 'All Project' selection
    if (ALL_PROJECTS == $t_current_project) {
        print_header_redirect('login_select_proj_page.php?ref=bug_report_page.php');
    }
    access_ensure_project_level(config_get('report_bug_threshold'));
    $f_build = gpc_get_string('build', '');
    $f_platform = gpc_get_string('platform', '');
    $f_os = gpc_get_string('os', '');
    $f_os_build = gpc_get_string('os_build', '');
    $f_product_version = gpc_get_string('product_version', '');
Esempio n. 12
0
	$f_view_state			= (int)$t_bug->view_state;
	$f_due_date				= $t_bug->due_date;

	$t_project_id			= $t_bug->project_id;
} else {
	# Get Project Id and set it as current
	$t_current_project = helper_get_current_project();
	$t_project_id = gpc_get_int( 'project_id', $t_current_project );

	# If all projects, use default project if set
	$t_default_project = user_pref_get_pref( auth_get_current_user_id(), 'default_project' );
	if( ALL_PROJECTS == $t_project_id && ALL_PROJECTS != $t_default_project ) {
		$t_project_id = $t_default_project;
	}

	if( ( ALL_PROJECTS == $t_project_id || project_exists( $t_project_id ) )
	 && $t_project_id != $t_current_project
	) {
		helper_set_current_project( $t_project_id );
		# Reloading the page is required so that the project browser
		# reflects the new current project
		print_header_redirect( $_SERVER['REQUEST_URI'], true, false, true );
	}

	# New issues cannot be reported for the 'All Project' selection
	if( ALL_PROJECTS == $t_current_project ) {
		print_header_redirect( 'login_select_proj_page.php?ref=bug_report_page.php' );
	}

	access_ensure_project_level( config_get( 'report_bug_threshold' ) );
Esempio n. 13
0
    display_document_header();
    display_menu();
    display_no_auth();
    display_document_footer();
    exit;
}
if (!isset($_POST['project_name']) || !isset($_POST['ocp_id'])) {
    header('location: create_project_form.php');
    exit;
}
$_POST['project_name'] = trim($_POST['project_name']);
if (empty($_POST['project_name']) || empty($_POST['ocp_id'])) {
    display_warning('Wype³nij poprawnie formularz!');
    exit;
} else {
    if (project_exists($_POST['project_name'])) {
        display_warning('Projekt o nazwie ' . htmlspecialchars(stripslashes($_POST['project_name'])) . ' ju¿ istnieje!');
        exit;
    }
}
if (isset($_POST['confirmed'])) {
    if (!insert_project($_POST['project_name'], $_POST['ocp_id'])) {
        display_warning('Utworzenie projektu zakoñczone niepowodzeniem!');
        exit;
    }
    $orgs = str_replace("\r", '', $_POST['orgs']);
    $orgs = explode("\n", $orgs);
    $new_orgs = get_new_orgs($orgs);
    if (!insert_new_orgs($new_orgs)) {
        display_warning('Dodanie nowych organizacji zakoñczone niepowodzeniem!');
        exit;
Esempio n. 14
0
function mc_project_get_issue_headers($p_username, $p_password, $p_project_id, $p_page_number, $p_per_page)
{
    $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_page_count = 0;
    $t_bug_count = 0;
    $t_rows = filter_get_bug_rows($p_page_number, $p_per_page, $t_page_count, $t_bug_count, null, $p_project_id);
    $t_result = array();
    foreach ($t_rows as $t_issue_data) {
        $t_id = $t_issue_data->id;
        $t_issue = array();
        $t_issue['id'] = $t_id;
        $t_issue['view_state'] = $t_issue_data->view_state;
        $t_issue['last_updated'] = timestamp_to_iso8601($t_issue_data->last_updated);
        $t_issue['project'] = $t_issue_data->project_id;
        $t_issue['category'] = mci_get_category($t_issue_data->category_id);
        $t_issue['priority'] = $t_issue_data->priority;
        $t_issue['severity'] = $t_issue_data->severity;
        $t_issue['status'] = $t_issue_data->status;
        $t_issue['reporter'] = $t_issue_data->reporter_id;
        $t_issue['summary'] = $t_issue_data->summary;
        if (!empty($t_issue_data->handler_id)) {
            $t_issue['handler'] = $t_issue_data->handler_id;
        }
        $t_issue['resolution'] = $t_issue_data->resolution;
        $t_issue['attachments_count'] = count(mci_issue_get_attachments($t_issue_data->id));
        $t_issue['notes_count'] = count(mci_issue_get_notes($t_issue_data->id));
        $t_result[] = $t_issue;
    }
    return $t_result;
}
Esempio n. 15
0
/**
 * Update Issue in database
 *
 * Created By KGB
 * @param string $p_username The name of the user trying to add the issue.
 * @param string $p_password The password of the user.
 * @param Array $p_issue A IssueData structure containing information about the new issue.
 * @return integer The id of the created issue.
 */
function mc_issue_update( $p_username, $p_password, $p_issue_id, $p_issue ) {
	global $g_project_override;
	
	$t_user_id = mci_check_login( $p_username, $p_password );
	if( $t_user_id === false ) {
		return mci_soap_fault_login_failed();
	}

	if( !bug_exists( $p_issue_id ) ) {
		return new soap_fault( 'Client', '', "Issue '$p_issue_id' does not exist." );
	}

	$t_project_id = bug_get_field( $p_issue_id, 'project_id' );

	if( !mci_has_readwrite_access( $t_user_id, $t_project_id ) ) {
		return mci_soap_fault_access_denied( $t_user_id );
	}
	
	$g_project_override = $t_project_id; // ensure that helper_get_current_project() calls resolve to this project id

	$t_project_id = mci_get_project_id( $p_issue['project'] );
	$t_reporter_id = isset( $p_issue['reporter'] ) ? mci_get_user_id( $p_issue['reporter'] )  : $t_user_id ;
	$t_handler_id = isset( $p_issue['handler'] ) ? mci_get_user_id( $p_issue['handler'] ) : 0;
	$t_project = $p_issue['project'];
	$t_summary = isset( $p_issue['summary'] ) ? $p_issue['summary'] : '';
	$t_description = isset( $p_issue['description'] ) ? $p_issue['description'] : '';
	
	
	if(( $t_project_id == 0 ) || !project_exists( $t_project_id ) ) {
		if( $t_project_id == 0 ) {
			return new soap_fault( 'Client', '', "Project '" . $t_project['name'] . "' does not exist." );
		}
		return new soap_fault( 'Client', '', "Project '$t_project_id' does not exist." );
	}

	if( !access_has_bug_level( config_get( 'update_bug_threshold' ), $p_issue_id, $t_user_id ) ) {
		return mci_soap_fault_access_denied( $t_user_id,  "Not enough rights to update issues" );
	}

	if(( $t_handler_id != 0 ) && !user_exists( $t_handler_id ) ) {
		return new soap_fault( 'Client', '', "User '$t_handler_id' does not exist." );
	}

	$t_category = isset ( $p_issue['category'] ) ? $p_issue['category'] : null;

	$t_category_id = translate_category_name_to_id( $t_category, $t_project_id );
	if ( $t_category_id == 0 && !config_get( 'allow_no_category' ) ) {
		if ( isset( $p_issue['category'] ) && !is_blank( $p_issue['category'] ) ) {
			return new soap_fault( 'Client', '', "Category field must be supplied." );
		} else {
			return new soap_fault( 'Client', '', "Category '" . $p_issue['category'] . "' not found for project '$t_project_name'." );
		}
	}

	if ( isset( $p_issue['version'] ) && !is_blank( $p_issue['version'] ) && !version_get_id( $p_issue['version'], $t_project_id ) ) {
		$t_error_when_version_not_found = config_get( 'mc_error_when_version_not_found' );
		if( $t_error_when_version_not_found == ON ) {
			$t_project_name = project_get_name( $t_project_id );
			return new soap_fault( 'Client', '', "Version '" . $p_issue['version'] . "' does not exist in project '$t_project_name'." );
		} else {
			$t_version_when_not_found = config_get( 'mc_version_when_not_found' );
			$p_issue['version'] = $t_version_when_not_found;
		}
	}

	if ( is_blank( $t_summary ) ) {
		return new soap_fault( 'Client', '', "Mandatory field 'summary' is missing." );
	}

	if ( is_blank( $t_description ) ) {
		return new soap_fault( 'Client', '', "Mandatory field 'description' is missing." );
	}

	// fields which we expect to always be set
	$t_bug_data = bug_get( $p_issue_id, true );
	$t_bug_data->project_id = $t_project_id;
	$t_bug_data->reporter_id = $t_reporter_id;
	$t_bug_data->handler_id = $t_handler_id;
	$t_bug_data->category_id = $t_category_id;
	$t_bug_data->summary = $t_summary;
	$t_bug_data->description = $t_description;

	// fields which might not be set
	if ( isset ( $p_issue['steps_to_reproduce'] ) )
		$t_bug_data->steps_to_reproduce = $p_issue['steps_to_reproduce'];
	if ( isset ( $p_issue['additional_information'] ) )
		$t_bug_data->additional_information = $p_issue['additional_information'];
	if ( isset( $p_issue['priority'] ) )
		$t_bug_data->priority = mci_get_priority_id( $p_issue['priority'] );
	if ( isset( $p_issue['severity'] ) )
		$t_bug_data->severity = mci_get_severity_id( $p_issue['severity'] );
	if ( isset( $p_issue['status'] ) )
		$t_bug_data->status = mci_get_status_id ( $p_issue['status'] );
	if ( isset ( $p_issue['reproducibility'] ) )
		$t_bug_data->reproducibility = mci_get_reproducibility_id( $p_issue['reproducibility'] );
	if ( isset ( $p_issue['resolution'] ) )
		$t_bug_data->resolution = mci_get_resolution_id( $p_issue['resolution'] );
	if ( isset ( $p_issue['projection'] ) )
		$t_bug_data->projection = mci_get_projection_id( $p_issue['projection'] );
	if ( isset ( $p_issue['eta'] ) )
		$t_bug_data->eta = mci_get_eta_id( $p_issue['eta'] );
	if ( isset ( $p_issue['view_state'] ) )
		$t_bug_data->view_state = mci_get_view_state_id( $p_issue['view_state'] );
	if ( isset ( $p_issue['date_submitted'] ) )
		$t_bug_data->date_submitted = $p_issue['date_submitted'];
	if ( isset ( $p_issue['date_updated'] ) )
		$t_bug_data->last_updated = $p_issue['last_updated'];
	if ( isset ( $p_issue['os'] ) )
		$t_bug_data->os = $p_issue['os'];
	if ( isset ( $p_issue['os_build'] ) )
		$t_bug_data->os_build = $p_issue['os_build'];
	if ( isset ( $p_issue['build'] ) )
		$t_bug_data->build = $p_issue['build'];
	if ( isset ( $p_issue['platform'] ) )
		$t_bug_data->platform = $p_issue['platform'];
	if ( isset ( $p_issue['version'] ) )
		$t_bug_data->version = $p_issue['version'];
	if ( isset ( $p_issue['fixed_in_version'] ) )
		$t_bug_data->fixed_in_version = $p_issue['fixed_in_version'];

	if ( isset( $p_issue['due_date'] ) && access_has_global_level( config_get( 'due_date_update_threshold' ) ) ) {
		$t_bug_data->due_date = mci_iso8601_to_timestamp( $p_issue['due_date'] );
	} else {
		$t_bug_data->due_date = date_get_null();
	}

	if( access_has_project_level( config_get( 'roadmap_update_threshold' ), $t_bug_data->project_id, $t_user_id ) ) {
		$t_bug_data->target_version = isset( $p_issue['target_version'] ) ? $p_issue['target_version'] : '';
	}

	mci_issue_set_custom_fields( $p_issue_id, $p_issue['custom_fields'], true );
	if ( isset ( $p_issue['monitors'] ) )
	    mci_issue_set_monitors( $p_issue_id , $t_user_id, $p_issue['monitors'] );

	if ( isset( $p_issue['notes'] ) && is_array( $p_issue['notes'] ) ) {
		foreach ( $p_issue['notes'] as $t_note ) {
			if ( isset( $t_note['view_state'] ) ) {
				$t_view_state = $t_note['view_state'];
			} else {
				$t_view_state = config_get( 'default_bugnote_view_status' );
			}

			if ( isset( $t_note['id'] ) && ( (int)$t_note['id'] > 0 ) ) {
				$t_bugnote_id = (integer)$t_note['id'];
				
				$t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_view_state );

				if ( bugnote_exists( $t_bugnote_id ) ) {
					bugnote_set_text( $t_bugnote_id, $t_note['text'] );
					bugnote_set_view_state( $t_bugnote_id, $t_view_state_id == VS_PRIVATE );
					bugnote_date_update( $t_bugnote_id );
					if ( isset( $t_note['time_tracking'] ) )
						bugnote_set_time_tracking( $t_bugnote_id, mci_get_time_tracking_from_note( $p_issue_id, $t_note ) );
				}
			} else {
				$t_view_state_id = mci_get_enum_id_from_objectref( 'view_state', $t_view_state );
				
				$note_type = isset ( $t_note['note_type'] ) ? (int) $t_note['note_type'] : BUGNOTE;
			    $note_attr = isset ( $t_note['note_type'] ) ? $t_note['note_attr'] : '';
				
				bugnote_add( $p_issue_id, $t_note['text'], mci_get_time_tracking_from_note( $p_issue_id, $t_note ), $t_view_state_id == VS_PRIVATE, $note_type, $note_attr, $t_user_id, FALSE );
			}
		}
	}

	# submit the issue
	return $t_bug_data->update( /* update_extended */ true, /* bypass_email */ true );
	
}
Esempio n. 16
0
    $f_category_id = $t_bug->category_id;
    $f_reproducibility = $t_bug->reproducibility;
    $f_eta = $t_bug->eta;
    $f_severity = $t_bug->severity;
    $f_priority = $t_bug->priority;
    $f_summary = $t_bug->summary;
    $f_description = $t_bug->description;
    $f_steps_to_reproduce = $t_bug->steps_to_reproduce;
    $f_additional_info = $t_bug->additional_information;
    $f_view_state = (int) $t_bug->view_state;
    $f_due_date = $t_bug->due_date;
    $t_project_id = $t_bug->project_id;
} else {
    # Get Project Id and set it as current
    $t_project_id = gpc_get_int('project_id', helper_get_current_project());
    if ((ALL_PROJECTS == $t_project_id || project_exists($t_project_id)) && $t_project_id != helper_get_current_project()) {
        helper_set_current_project($t_project_id);
        # Reloading the page is required so that the project browser
        # reflects the new current project
        print_header_redirect($_SERVER['REQUEST_URI'], true, false, true);
    }
    # New issues cannot be reported for the 'All Project' selection
    if (ALL_PROJECTS == helper_get_current_project()) {
        print_header_redirect('login_select_proj_page.php?ref=bug_report_page.php');
    }
    access_ensure_project_level(config_get('report_bug_threshold'));
    $f_build = gpc_get_string('build', '');
    $f_platform = gpc_get_string('platform', '');
    $f_os = gpc_get_string('os', '');
    $f_os_build = gpc_get_string('os_build', '');
    $f_product_version = gpc_get_string('product_version', '');
Esempio n. 17
0
/**
 * Get Issue Headers
 * @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 attachments for.
 * @param integer $p_page_number Page number.
 * @param integer $p_per_page    Per page.
 * @return mixed
 */
function mc_project_get_issue_headers($p_username, $p_password, $p_project_id, $p_page_number, $p_per_page)
{
    global $g_project_override;
    $t_user_id = mci_check_login($p_username, $p_password);
    if ($t_user_id === false) {
        return mci_soap_fault_login_failed();
    }
    if ($p_project_id != ALL_PROJECTS && !project_exists($p_project_id)) {
        return SoapObjectsFactory::newSoapFault('Client', 'Project \'' . $p_project_id . '\' does not exist.');
    }
    $g_project_override = $p_project_id;
    if (!mci_has_readonly_access($t_user_id, $p_project_id)) {
        return mci_soap_fault_access_denied($t_user_id);
    }
    $t_orig_page_number = $p_page_number < 1 ? 1 : $p_page_number;
    $t_page_count = 0;
    $t_bug_count = 0;
    $t_rows = filter_get_bug_rows($p_page_number, $p_per_page, $t_page_count, $t_bug_count, null, $p_project_id);
    $t_result = array();
    # the page number was moved back, so we have exceeded the actual page number, see bug #12991
    if ($t_orig_page_number > $p_page_number) {
        return $t_result;
    }
    foreach ($t_rows as $t_issue_data) {
        $t_result[] = mci_issue_data_as_header_array($t_issue_data);
    }
    return $t_result;
}
Esempio n. 18
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);
}
Esempio n. 19
0
/**
 * Update Issue in database
 *
 * Created By KGB
 * @param string   $p_username The name of the user trying to add the issue.
 * @param string   $p_password The password of the user.
 * @param integer  $p_issue_id The issue id of the existing issue being updated.
 * @param stdClass $p_issue    A IssueData structure containing information about the new issue.
 * @return integer The id of the created issue.
 */
function mc_issue_update($p_username, $p_password, $p_issue_id, stdClass $p_issue)
{
    global $g_project_override;
    $t_user_id = mci_check_login($p_username, $p_password);
    if ($t_user_id === false) {
        return mci_soap_fault_login_failed();
    }
    if (!bug_exists($p_issue_id)) {
        return SoapObjectsFactory::newSoapFault('Client', 'Issue \'' . $p_issue_id . '\' does not exist.');
    }
    if (bug_is_readonly($p_issue_id)) {
        return SoapObjectsFactory::newSoapFault('Client', 'Issue \'' . $p_issue_id . '\' is readonly');
    }
    $t_project_id = bug_get_field($p_issue_id, 'project_id');
    if (!mci_has_readwrite_access($t_user_id, $t_project_id)) {
        return mci_soap_fault_access_denied($t_user_id);
    }
    $g_project_override = $t_project_id;
    # ensure that helper_get_current_project() calls resolve to this project id
    $p_issue = SoapObjectsFactory::unwrapObject($p_issue);
    $t_project_id = mci_get_project_id($p_issue['project']);
    $t_reporter_id = isset($p_issue['reporter']) ? mci_get_user_id($p_issue['reporter']) : $t_user_id;
    $t_handler_id = isset($p_issue['handler']) ? mci_get_user_id($p_issue['handler']) : 0;
    $t_project = $p_issue['project'];
    $t_summary = isset($p_issue['summary']) ? $p_issue['summary'] : '';
    $t_description = isset($p_issue['description']) ? $p_issue['description'] : '';
    if ($t_project_id == 0 || !project_exists($t_project_id)) {
        if ($t_project_id == 0) {
            return SoapObjectsFactory::newSoapFault('Client', 'Project \'' . $t_project['name'] . '\' does not exist.');
        }
        return SoapObjectsFactory::newSoapFault('Client', 'Project \'' . $t_project_id . '\' does not exist.');
    }
    if (!access_has_bug_level(config_get('update_bug_threshold'), $p_issue_id, $t_user_id)) {
        return mci_soap_fault_access_denied($t_user_id, 'Not enough rights to update issues');
    }
    $t_category = isset($p_issue['category']) ? $p_issue['category'] : null;
    $t_category_id = translate_category_name_to_id($t_category, $t_project_id);
    if ($t_category_id == 0 && !config_get('allow_no_category')) {
        if (isset($p_issue['category']) && !is_blank($p_issue['category'])) {
            return SoapObjectsFactory::newSoapFault('Client', 'Category field must be supplied.');
        } else {
            $t_project_name = project_get_name($t_project_id);
            return SoapObjectsFactory::newSoapFault('Client', 'Category \'' . $p_issue['category'] . '\' not found for project \'' . $t_project_name . '\'.');
        }
    }
    if (isset($p_issue['version']) && !is_blank($p_issue['version']) && !version_get_id($p_issue['version'], $t_project_id)) {
        $t_error_when_version_not_found = config_get('webservice_error_when_version_not_found');
        if ($t_error_when_version_not_found == ON) {
            $t_project_name = project_get_name($t_project_id);
            return SoapObjectsFactory::newSoapFault('Client', 'Version \'' . $p_issue['version'] . '\' does not exist in project \'' . $t_project_name . '\'.');
        } else {
            $t_version_when_not_found = config_get('webservice_version_when_not_found');
            $p_issue['version'] = $t_version_when_not_found;
        }
    }
    if (is_blank($t_summary)) {
        return SoapObjectsFactory::newSoapFault('Client', 'Mandatory field \'summary\' is missing.');
    }
    if (is_blank($t_description)) {
        return SoapObjectsFactory::newSoapFault('Client', 'Mandatory field \'description\' is missing.');
    }
    # fields which we expect to always be set
    $t_bug_data = bug_get($p_issue_id, true);
    $t_bug_data->project_id = $t_project_id;
    $t_bug_data->reporter_id = $t_reporter_id;
    $t_access_check_result = mci_issue_handler_access_check($t_user_id, $t_project_id, $t_bug_data->handler_id, $t_handler_id);
    if ($t_access_check_result !== true) {
        return $t_access_check_result;
    }
    $t_bug_data->handler_id = $t_handler_id;
    $t_bug_data->category_id = $t_category_id;
    $t_bug_data->summary = $t_summary;
    $t_bug_data->description = $t_description;
    # fields which might not be set
    if (isset($p_issue['steps_to_reproduce'])) {
        $t_bug_data->steps_to_reproduce = $p_issue['steps_to_reproduce'];
    }
    if (isset($p_issue['additional_information'])) {
        $t_bug_data->additional_information = $p_issue['additional_information'];
    }
    if (isset($p_issue['priority'])) {
        $t_bug_data->priority = mci_get_priority_id($p_issue['priority']);
    }
    if (isset($p_issue['severity'])) {
        $t_bug_data->severity = mci_get_severity_id($p_issue['severity']);
    }
    if (isset($p_issue['status'])) {
        $t_bug_data->status = mci_get_status_id($p_issue['status']);
    }
    if (isset($p_issue['reproducibility'])) {
        $t_bug_data->reproducibility = mci_get_reproducibility_id($p_issue['reproducibility']);
    }
    if (isset($p_issue['resolution'])) {
        $t_bug_data->resolution = mci_get_resolution_id($p_issue['resolution']);
    }
    if (isset($p_issue['projection'])) {
        $t_bug_data->projection = mci_get_projection_id($p_issue['projection']);
    }
    if (isset($p_issue['eta'])) {
        $t_bug_data->eta = mci_get_eta_id($p_issue['eta']);
    }
    if (isset($p_issue['view_state'])) {
        $t_bug_data->view_state = mci_get_view_state_id($p_issue['view_state']);
    }
    if (isset($p_issue['date_submitted'])) {
        $t_bug_data->date_submitted = $p_issue['date_submitted'];
    }
    if (isset($p_issue['date_updated'])) {
        $t_bug_data->last_updated = $p_issue['last_updated'];
    }
    if (isset($p_issue['profile_id'])) {
        $t_bug_data->profile_id = $p_issue['profile_id'];
    }
    if (isset($p_issue['os'])) {
        $t_bug_data->os = $p_issue['os'];
    }
    if (isset($p_issue['os_build'])) {
        $t_bug_data->os_build = $p_issue['os_build'];
    }
    if (isset($p_issue['build'])) {
        $t_bug_data->build = $p_issue['build'];
    }
    if (isset($p_issue['platform'])) {
        $t_bug_data->platform = $p_issue['platform'];
    }
    if (isset($p_issue['version'])) {
        $t_bug_data->version = $p_issue['version'];
    }
    if (isset($p_issue['fixed_in_version'])) {
        $t_bug_data->fixed_in_version = $p_issue['fixed_in_version'];
    }
    if (isset($p_issue['sticky']) && access_has_bug_level(config_get('set_bug_sticky_threshold'), $t_bug_data->id)) {
        $t_bug_data->sticky = $p_issue['sticky'];
    }
    if (isset($p_issue['due_date']) && access_has_global_level(config_get('due_date_update_threshold'))) {
        $t_bug_data->due_date = SoapObjectsFactory::parseDateTimeString($p_issue['due_date']);
    } else {
        $t_bug_data->due_date = date_get_null();
    }
    if (access_has_project_level(config_get('roadmap_update_threshold'), $t_bug_data->project_id, $t_user_id)) {
        $t_bug_data->target_version = isset($p_issue['target_version']) ? $p_issue['target_version'] : '';
    }
    $t_set_custom_field_error = mci_issue_set_custom_fields($p_issue_id, $p_issue['custom_fields'], true);
    if ($t_set_custom_field_error != null) {
        return $t_set_custom_field_error;
    }
    if (isset($p_issue['monitors'])) {
        mci_issue_set_monitors($p_issue_id, $t_user_id, $p_issue['monitors']);
    }
    if (isset($p_issue['notes']) && is_array($p_issue['notes'])) {
        $t_bugnotes = bugnote_get_all_visible_bugnotes($p_issue_id, 'DESC', 0);
        $t_bugnotes_by_id = array();
        foreach ($t_bugnotes as $t_bugnote) {
            $t_bugnotes_by_id[$t_bugnote->id] = $t_bugnote;
        }
        foreach ($p_issue['notes'] as $t_note) {
            $t_note = SoapObjectsFactory::unwrapObject($t_note);
            if (isset($t_note['view_state'])) {
                $t_view_state = $t_note['view_state'];
            } else {
                $t_view_state = config_get('default_bugnote_view_status');
            }
            if (isset($t_note['id']) && (int) $t_note['id'] > 0) {
                $t_bugnote_id = (int) $t_note['id'];
                $t_view_state_id = mci_get_enum_id_from_objectref('view_state', $t_view_state);
                if (array_key_exists($t_bugnote_id, $t_bugnotes_by_id)) {
                    $t_bugnote_changed = false;
                    if ($t_bugnote->note !== $t_note['text']) {
                        bugnote_set_text($t_bugnote_id, $t_note['text']);
                        $t_bugnote_changed = true;
                    }
                    if ($t_bugnote->view_state != $t_view_state_id) {
                        bugnote_set_view_state($t_bugnote_id, $t_view_state_id == VS_PRIVATE);
                        $t_bugnote_changed = true;
                    }
                    if (isset($t_note['time_tracking']) && $t_note['time_tracking'] != $t_bugnote->time_tracking) {
                        bugnote_set_time_tracking($t_bugnote_id, mci_get_time_tracking_from_note($p_issue_id, $t_note));
                        $t_bugnote_changed = true;
                    }
                    if ($t_bugnote_changed) {
                        bugnote_date_update($t_bugnote_id);
                    }
                }
            } else {
                $t_view_state_id = mci_get_enum_id_from_objectref('view_state', $t_view_state);
                $t_note_type = isset($t_note['note_type']) ? (int) $t_note['note_type'] : BUGNOTE;
                $t_note_attr = isset($t_note['note_type']) ? $t_note['note_attr'] : '';
                bugnote_add($p_issue_id, $t_note['text'], mci_get_time_tracking_from_note($p_issue_id, $t_note), $t_view_state_id == VS_PRIVATE, $t_note_type, $t_note_attr, $t_user_id, false);
            }
        }
        # The issue has been cached earlier in the bug_get() call.  Flush the cache since it is
        # now stale.  Otherwise, the email notification will be based on the cached data.
        bugnote_clear_cache($p_issue_id);
    }
    if (isset($p_issue['tags']) && is_array($p_issue['tags'])) {
        mci_tag_set_for_issue($p_issue_id, $p_issue['tags'], $t_user_id);
    }
    # submit the issue
    log_event(LOG_WEBSERVICE, 'updating issue \'' . $p_issue_id . '\'');
    return $t_bug_data->update(true, true);
}
Esempio n. 20
0
    $f_description = $t_bug->description;
    $f_steps_to_reproduce = $t_bug->steps_to_reproduce;
    $f_additional_info = $t_bug->additional_information;
    $f_view_state = (int) $t_bug->view_state;
    $f_due_date = $t_bug->due_date;
    $t_project_id = $t_bug->project_id;
} else {
    # Get Project Id and set it as current
    $t_current_project = helper_get_current_project();
    $t_project_id = gpc_get_int('project_id', $t_current_project);
    # If all projects, use default project if set
    $t_default_project = user_pref_get_pref(auth_get_current_user_id(), 'default_project');
    if (ALL_PROJECTS == $t_project_id && ALL_PROJECTS != $t_default_project) {
        $t_project_id = $t_default_project;
    }
    if ((ALL_PROJECTS == $t_project_id || project_exists($t_project_id)) && $t_project_id != $t_current_project) {
        helper_set_current_project($t_project_id);
        # Reloading the page is required so that the project browser
        # reflects the new current project
        print_header_redirect($_SERVER['REQUEST_URI'], true, false, true);
    }
    # New issues cannot be reported for the 'All Project' selection
    if (ALL_PROJECTS == $t_current_project) {
        print_header_redirect('login_select_proj_page.php?ref=bug_report_page.php');
    }
    access_ensure_project_level(config_get('report_bug_threshold'));
    $f_build = gpc_get_string('build', '');
    $f_platform = gpc_get_string('platform', '');
    $f_os = gpc_get_string('os', '');
    $f_os_build = gpc_get_string('os_build', '');
    $f_product_version = gpc_get_string('product_version', '');
Esempio n. 21
0
/**
 * Update Issue in database
 *
 * Created By KGB
 * @param string $p_username The name of the user trying to add the issue.
 * @param string $p_password The password of the user.
 * @param Array $p_issue A IssueData structure containing information about the new issue.
 * @return integer The id of the created issue.
 */
function mc_issue_update($p_username, $p_password, $p_issue_id, $p_issue)
{
    $t_user_id = mci_check_login($p_username, $p_password);
    if ($t_user_id === false) {
        return mci_soap_fault_login_failed();
    }
    if (!bug_exists($p_issue_id)) {
        return new soap_fault('Client', '', "Issue '{$p_issue_id}' does not exist.");
    }
    $t_project_id = bug_get_field($p_issue_id, 'project_id');
    if (!mci_has_readwrite_access($t_user_id, $t_project_id)) {
        return mci_soap_fault_access_denied($t_user_id);
    }
    $t_project_id = mci_get_project_id($p_issue['project']);
    $t_handler_id = isset($p_issue['handler']) ? mci_get_user_id($p_issue['handler']) : 0;
    $t_priority_id = isset($p_issue['priority']) ? mci_get_priority_id($p_issue['priority']) : config_get('default_bug_priority');
    $t_severity_id = isset($p_issue['severity']) ? mci_get_severity_id($p_issue['severity']) : config_get('default_bug_severity');
    $t_status_id = isset($p_issue['status']) ? mci_get_status_id($p_issue['status']) : config_get('bug_submit_status');
    $t_reproducibility_id = isset($p_issue['reproducibility']) ? mci_get_reproducibility_id($p_issue['reproducibility']) : config_get('default_bug_reproducibility');
    $t_resolution_id = isset($p_issue['resolution']) ? mci_get_resolution_id($p_issue['resolution']) : config_get('default_bug_resolution');
    $t_projection_id = isset($p_issue['projection']) ? mci_get_projection_id($p_issue['projection']) : config_get('default_bug_resolution');
    $t_eta_id = isset($p_issue['eta']) ? mci_get_eta_id($p_issue['eta']) : config_get('default_bug_eta');
    $t_view_state_id = isset($p_issue['view_state']) ? mci_get_view_state_id($p_issue['view_state']) : config_get('default_bug_view_status');
    $t_reporter_id = isset($p_issue['reporter']) ? mci_get_user_id($p_issue['reporter']) : 0;
    $t_project = $p_issue['project'];
    $t_summary = isset($p_issue['summary']) ? $p_issue['summary'] : '';
    $t_description = isset($p_issue['description']) ? $p_issue['description'] : '';
    $t_additional_information = isset($p_issue['additional_information']) ? $p_issue['additional_information'] : '';
    $t_steps_to_reproduce = isset($p_issue['steps_to_reproduce']) ? $p_issue['steps_to_reproduce'] : '';
    $t_build = isset($p_issue['build']) ? $p_issue['build'] : '';
    $t_platform = isset($p_issue['platform']) ? $p_issue['platform'] : '';
    $t_os = isset($p_issue['os']) ? $p_issue['os'] : '';
    $t_os_build = isset($p_issue['os_build']) ? $p_issue['os_build'] : '';
    $t_sponsorship_total = isset($p_issue['sponsorship_total']) ? $p_issue['sponsorship_total'] : 0;
    if ($t_reporter_id == 0) {
        $t_reporter_id = $t_user_id;
    }
    if ($t_project_id == 0 || !project_exists($t_project_id)) {
        if ($t_project_id == 0) {
            return new soap_fault('Client', '', "Project '" . $t_project['name'] . "' does not exist.");
        }
        return new soap_fault('Client', '', "Project '{$t_project_id}' does not exist.");
    }
    if (!access_has_bug_level(config_get('update_bug_threshold'), $p_issue_id, $t_user_id)) {
        return mci_soap_fault_access_denied($t_user_id, "Not enough rights to update issues");
    }
    if ($t_handler_id != 0 && !user_exists($t_handler_id)) {
        return new soap_fault('Client', '', "User '{$t_handler_id}' does not exist.");
    }
    $t_category = isset($p_issue['category']) ? $p_issue['category'] : null;
    $t_category_id = translate_category_name_to_id($t_category, $t_project_id);
    if ($t_category_id == 0 && !config_get('allow_no_category')) {
        if (isset($p_issue['category']) && !is_blank($p_issue['category'])) {
            return new soap_fault('Client', '', "Category field must be supplied.");
        } else {
            return new soap_fault('Client', '', "Category '" . $p_issue['category'] . "' not found for project '{$t_project_name}'.");
        }
    }
    if (isset($p_issue['version']) && !is_blank($p_issue['version']) && !version_get_id($p_issue['version'], $t_project_id)) {
        $t_error_when_version_not_found = config_get('mc_error_when_version_not_found');
        if ($t_error_when_version_not_found == ON) {
            $t_project_name = project_get_name($t_project_id);
            return new soap_fault('Client', '', "Version '" . $p_issue['version'] . "' does not exist in project '{$t_project_name}'.");
        } else {
            $t_version_when_not_found = config_get('mc_version_when_not_found');
            $p_issue['version'] = $t_version_when_not_found;
        }
    }
    if (is_blank($t_summary)) {
        return new soap_fault('Client', '', "Mandatory field 'summary' is missing.");
    }
    if (is_blank($t_description)) {
        return new soap_fault('Client', '', "Mandatory field 'description' is missing.");
    }
    if ($t_priority_id == 0) {
        $t_priority_id = config_get('default_bug_priority');
    }
    if ($t_severity_id == 0) {
        $t_severity_id = config_get('default_bug_severity');
    }
    if ($t_view_state_id == 0) {
        $t_view_state_id = config_get('default_bug_view_status');
    }
    if ($t_reproducibility_id == 0) {
        $t_reproducibility_id = config_get('default_bug_reproducibility');
    }
    $t_bug_data = new BugData();
    $t_bug_data->id = $p_issue_id;
    $t_bug_data->project_id = $t_project_id;
    $t_bug_data->reporter_id = $t_reporter_id;
    $t_bug_data->handler_id = $t_handler_id;
    $t_bug_data->priority = $t_priority_id;
    $t_bug_data->severity = $t_severity_id;
    $t_bug_data->reproducibility = $t_reproducibility_id;
    $t_bug_data->status = $t_status_id;
    $t_bug_data->resolution = $t_resolution_id;
    $t_bug_data->projection = $t_projection_id;
    $t_bug_data->category_id = $t_category_id;
    $t_bug_data->date_submitted = isset($v_date_submitted) ? $v_date_submitted : '';
    $t_bug_data->last_updated = isset($v_last_updated) ? $v_last_updated : '';
    $t_bug_data->eta = $t_eta_id;
    $t_bug_data->os = $t_os;
    $t_bug_data->os_build = $t_os_build;
    $t_bug_data->platform = $t_platform;
    $t_bug_data->version = isset($p_issue['version']) ? $p_issue['version'] : '';
    $t_bug_data->fixed_in_version = isset($p_issue['fixed_in_version']) ? $p_issue['fixed_in_version'] : '';
    $t_bug_data->build = $t_build;
    $t_bug_data->view_state = $t_view_state_id;
    $t_bug_data->summary = $t_summary;
    $t_bug_data->sponsorship_total = $t_sponsorship_total;
    if (isset($p_issue['due_date']) && access_has_global_level(config_get('due_date_update_threshold'))) {
        $t_bug_data->due_date = mci_iso8601_to_timestamp($p_issue['due_date']);
    } else {
        $t_bug_data->due_date = date_get_null();
    }
    if (access_has_project_level(config_get('roadmap_update_threshold'), $t_bug_data->project_id, $t_user_id)) {
        $t_bug_data->target_version = isset($p_issue['target_version']) ? $p_issue['target_version'] : '';
    }
    # omitted:
    # var $bug_text_id
    # $t_bug_data->profile_id;
    # extended info
    $t_bug_data->description = $t_description;
    $t_bug_data->steps_to_reproduce = isset($t_steps_to_reproduce) ? $t_steps_to_reproduce : '';
    $t_bug_data->additional_information = isset($t_additional_information) ? $t_additional_information : '';
    # submit the issue
    $t_is_success = $t_bug_data->update(true, true);
    mci_issue_set_custom_fields($p_issue_id, $p_issue['custom_fields'], true);
    if (isset($p_issue['notes']) && is_array($p_issue['notes'])) {
        foreach ($p_issue['notes'] as $t_note) {
            if (isset($t_note['view_state'])) {
                $t_view_state = $t_note['view_state'];
            } else {
                $t_view_state = config_get('default_bugnote_view_status');
            }
            if (isset($t_note['id']) && (int) $t_note['id'] > 0) {
                $t_bugnote_id = (int) $t_note['id'];
                if (bugnote_exists($t_bugnote_id)) {
                    bugnote_set_text($t_bugnote_id, $t_note['text']);
                    bugnote_set_view_state($t_bugnote_id, $t_view_state_id == VS_PRIVATE);
                    bugnote_date_update($t_bugnote_id);
                    if (isset($t_note['time_tracking'])) {
                        bugnote_set_time_tracking($t_bugnote_id, mci_get_time_tracking_from_note($p_issue_id, $t_note));
                    }
                }
            } else {
                $t_view_state_id = mci_get_enum_id_from_objectref('view_state', $t_view_state);
                bugnote_add($p_issue_id, $t_note['text'], mci_get_time_tracking_from_note($p_issue_id, $t_note), $t_view_state_id == VS_PRIVATE, BUGNOTE, '', $t_user_id, FALSE);
            }
        }
    }
    return $t_is_success;
}