Example #1
0
function sponsorship_cache_row($p_sponsorship_id, $p_trigger_errors = true)
{
    global $g_cache_sponsorships;
    $c_sponsorship_id = db_prepare_int($p_sponsorship_id);
    $t_sponsorship_table = config_get('mantis_sponsorship_table');
    if (isset($g_cache_sponsorships[$c_sponsorship_id])) {
        return $g_cache_sponsorships[$c_sponsorship_id];
    }
    $query = "SELECT *\r\n\t\t\t\t  FROM {$t_sponsorship_table}\r\n\t\t\t\t  WHERE id='{$c_sponsorship_id}'";
    $result = db_query($query);
    if (0 == db_num_rows($result)) {
        $g_cache_sponsorships[$c_sponsorship_id] = false;
        if ($p_trigger_errors) {
            error_parameters($p_sponsorship_id);
            trigger_error(ERROR_SPONSORSHIP_NOT_FOUND, ERROR);
        } else {
            return false;
        }
    }
    $row = db_fetch_array($result);
    $row['date_submitted'] = db_unixtimestamp($row['date_submitted']);
    $row['last_updated'] = db_unixtimestamp($row['last_updated']);
    $g_cache_sponsorships[$c_sponsorship_id] = $row;
    return $row;
}
Example #2
0
function bug_get_bugnote_stats($p_bug_id)
{
    global $g_cache_bug;
    $c_bug_id = db_prepare_int($p_bug_id);
    if (!is_null($g_cache_bug[$c_bug_id]['_stats'])) {
        if ($g_cache_bug[$c_bug_id]['_stats'] === false) {
            return false;
        } else {
            $t_stats['last_modified'] = db_unixtimestamp($g_cache_bug[$c_bug_id]['_stats']['last_modified']);
            $t_stats['count'] = $g_cache_bug[$c_bug_id]['_stats']['count'];
        }
        return $t_stats;
    }
    $t_bugnote_table = config_get('mantis_bugnote_table');
    $query = "SELECT last_modified\n\t\t\t\t  FROM {$t_bugnote_table}\n\t\t\t\t  WHERE bug_id='{$c_bug_id}'\n\t\t\t\t  ORDER BY last_modified DESC";
    $result = db_query($query);
    $row = db_fetch_array($result);
    if (false === $row) {
        return false;
    }
    $t_stats['last_modified'] = db_unixtimestamp($row['last_modified']);
    $t_stats['count'] = db_num_rows($result);
    return $t_stats;
}
function install_date_migrate($p_data)
{
    // $p_data[0] = tablename, [1] id column, [2] = old column, [3] = new column
    # Disable query logging even if enabled in config, due to possibility of mass spam
    $t_log_queries = install_set_log_queries();
    $t_table = $p_data[0];
    $t_id_column = $p_data[1];
    if (is_array($p_data[2])) {
        $t_old_column = implode(',', $p_data[2]);
        $t_date_array = true;
        $t_cnt_fields = count($p_data[2]);
        $t_pairs = array();
        foreach ($p_data[3] as $var) {
            array_push($t_pairs, "{$var}=" . db_param());
        }
        $t_new_column = implode(',', $t_pairs);
        $query = "SELECT {$t_id_column}, {$t_old_column} FROM {$t_table}";
        $t_first_column = true;
        # In order to handle large databases where we may timeout during the upgrade, we don't
        # start form the beginning everytime.  Here we will only pickup rows where at least one
        # of the datetime fields wasn't upgraded yet and upgrade them all.
        foreach ($p_data[3] as $t_new_column_name) {
            if ($t_first_column) {
                $t_first_column = false;
                $query .= ' WHERE ';
            } else {
                $query .= ' OR ';
            }
            $query .= "{$t_new_column_name} = 1";
        }
    } else {
        $t_old_column = $p_data[2];
        $t_new_column = $p_data[3] . "=" . db_param();
        $t_date_array = false;
        # The check for timestamp being = 1 is to make sure the field wasn't upgraded
        # already in a previous run - see bug #12601 for more details.
        $t_new_column_name = $p_data[3];
        $query = "SELECT {$t_id_column}, {$t_old_column} FROM {$t_table} WHERE {$t_new_column_name} = 1";
    }
    $t_result = db_query_bound($query);
    while ($row = db_fetch_array($t_result)) {
        $t_id = (int) $row[$t_id_column];
        if ($t_date_array) {
            for ($i = 0; $i < $t_cnt_fields; $i++) {
                $t_old_value = $row[$p_data[2][$i]];
                $t_new_value[$i] = db_unixtimestamp($t_old_value);
                if ($t_new_value[$i] < 100000) {
                    $t_new_value[$i] = 1;
                }
            }
            $t_values = $t_new_value;
            $t_values[] = $t_id;
        } else {
            $t_old_value = $row[$t_old_column];
            $t_new_value = db_unixtimestamp($t_old_value);
            if ($t_new_value < 100000) {
                $t_new_value = 1;
            }
            $t_values = array($t_new_value, $t_id);
        }
        $query = "UPDATE {$t_table} SET {$t_new_column}\n\t\t\t\t\tWHERE {$t_id_column}=" . db_param();
        db_query_bound($query, $t_values);
    }
    # Re-enable query logging if we disabled it
    install_set_log_queries($t_log_queries);
    # return 2 because that's what ADOdb/DataDict does when things happen properly
    return 2;
}
Example #4
0
function email_queue_row_to_object($p_row)
{
    # typically this function takes as an input the result of db_fetch_array() which can be false.
    if ($p_row === false) {
        return false;
    }
    $t_row = $p_row;
    $t_row['submitted'] = db_unixtimestamp($t_row['submitted']);
    $t_row['metadata'] = unserialize($t_row['metadata']);
    $t_email_data = new EmailData();
    $t_row_keys = array_keys($t_row);
    $t_vars = get_object_vars($t_email_data);
    # Check each variable in the class
    foreach ($t_vars as $t_var => $t_value) {
        # If we got a field from the DB with the same name
        if (in_array($t_var, $t_row_keys, true)) {
            # Store that value in the object
            $t_email_data->{$t_var} = $t_row[$t_var];
        }
    }
    return $t_email_data;
}
Example #5
0
        if (OFF == config_get('enable_project_documentation')) {
            access_denied();
        }
        access_ensure_project_level(config_get('view_proj_doc_threshold'), $v_project_id);
        break;
}
# flush output buffer to protect download
@ob_end_clean();
# Make sure that IE can download the attachments under https.
header('Pragma: public');
header('Content-Type: ' . $v_file_type);
header('Content-Length: ' . $v_filesize);
# Added Quotes (") around file name.
header('Content-Disposition: attachment; filename="' . file_get_display_name($v_filename) . '"');
header('Content-Description: Download Data');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', db_unixtimestamp($v_date_added)));
# To fix an IE bug which causes problems when downloading
# attached files via HTTPS, we disable the "Pragma: no-cache"
# command when IE is used over HTTPS.
global $g_allow_file_cache;
if (isset($_SERVER["HTTPS"]) && "on" == $_SERVER["HTTPS"] && preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"])) {
    # Suppress "Pragma: no-cache" header.
} else {
    if (!isset($g_allow_file_cache)) {
        header('Pragma: no-cache');
    }
}
header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time()));
# dump file content to the connection.
switch (config_get('file_upload_method')) {
    case DISK:
Example #6
0
		<tr>
			<td class="print">
				<?php 
        echo print_user($v3_reporter_id);
        ?>
&nbsp;&nbsp;&nbsp;
			</td>
		</tr>
		<tr>
			<td class="print">
				<?php 
        echo $v3_date_submitted;
        ?>
&nbsp;&nbsp;&nbsp;
				<?php 
        if (db_unixtimestamp($v3_date_submitted) != db_unixtimestamp($v3_last_modified)) {
            echo '<br />(' . lang_get('edited_on') . ' ' . $v3_last_modified . ')';
        }
        ?>
			</td>
		</tr>
		</table>
	</td>
	<td class="nopad" valign="top" width="85%">
		<table class="hide" cellspacing="1">
		<tr>
			<td class="print">
				<?php 
        switch ($v3_note_type) {
            case REMINDER:
                echo '<div class="italic">' . lang_get('reminder_sent_to') . ': ';
Example #7
0
function create_cumulative_bydate()
{
    $t_clo_val = CLOSED;
    $t_res_val = config_get('bug_resolved_status_threshold');
    $t_bug_table = config_get('mantis_bug_table');
    $t_history_table = config_get('mantis_bug_history_table');
    $t_project_id = helper_get_current_project();
    $t_user_id = auth_get_current_user_id();
    $specific_where = helper_project_specific_where($t_project_id, $t_user_id);
    # Get all the submitted dates
    $query = "SELECT date_submitted\n\t\t\t\tFROM {$t_bug_table}\n\t\t\t\tWHERE {$specific_where}\n\t\t\t\tORDER BY date_submitted";
    $result = db_query($query);
    $bug_count = db_num_rows($result);
    for ($i = 0; $i < $bug_count; $i++) {
        $row = db_fetch_array($result);
        # rationalise the timestamp to a day to reduce the amount of data
        $t_date = db_unixtimestamp($row['date_submitted']);
        $t_date = (int) ($t_date / 86400);
        if (isset($metrics[$t_date])) {
            $metrics[$t_date][0]++;
        } else {
            $metrics[$t_date] = array(1, 0, 0);
        }
    }
    ### Get all the dates where a transition from not resolved to resolved may have happened
    #    also, get the last updated date for the bug as this may be all the information we have
    $query = "SELECT {$t_bug_table}.id, last_updated, date_modified, new_value, old_value\n\t\t\tFROM {$t_bug_table} LEFT JOIN {$t_history_table}\n\t\t\tON {$t_bug_table}.id = {$t_history_table}.bug_id\n\t\t\tWHERE {$specific_where}\n\t\t\t\t\t\tAND {$t_bug_table}.status >= '{$t_res_val}'\n\t\t\t\t\t\tAND ( ( {$t_history_table}.new_value >= '{$t_res_val}'\n\t\t\t\t\t\t\t\tAND {$t_history_table}.field_name = 'status' )\n\t\t\t\t\t\tOR {$t_history_table}.id is NULL )\n\t\t\tORDER BY {$t_bug_table}.id, date_modified ASC";
    $result = db_query($query);
    $bug_count = db_num_rows($result);
    $t_last_id = 0;
    for ($i = 0; $i < $bug_count; $i++) {
        $row = db_fetch_array($result);
        $t_id = $row['id'];
        # if h_last_updated is NULL, there were no appropriate history records
        #  (i.e. pre 0.18 data), use last_updated from bug table instead
        if (NULL == $row['date_modified']) {
            $t_date = db_unixtimestamp($row['last_updated']);
        } else {
            if ($t_res_val > $row['old_value']) {
                $t_date = db_unixtimestamp($row['date_modified']);
            }
        }
        if ($t_id != $t_last_id) {
            if (0 != $t_last_id) {
                # rationalise the timestamp to a day to reduce the amount of data
                $t_date_index = (int) ($t_last_date / 86400);
                if (isset($metrics[$t_date_index])) {
                    $metrics[$t_date_index][1]++;
                } else {
                    $metrics[$t_date_index] = array(0, 1, 0);
                }
            }
            $t_last_id = $t_id;
        }
        $t_last_date = $t_date;
    }
    ksort($metrics);
    $metrics_count = count($metrics);
    $t_last_opened = 0;
    $t_last_resolved = 0;
    foreach ($metrics as $i => $vals) {
        $t_date = $i * 86400;
        $t_metrics[$t_date][0] = $t_last_opened = $metrics[$i][0] + $t_last_opened;
        $t_metrics[$t_date][1] = $t_last_resolved = $metrics[$i][1] + $t_last_resolved;
        $t_metrics[$t_date][2] = $t_metrics[$t_date][0] - $t_metrics[$t_date][1];
    }
    return $t_metrics;
}
#  will look up the most recent 'resolved' status change and return it as well
$query = "SELECT b.id, b.date_submitted, b.last_updated, MAX(h.date_modified) as hist_update, b.status \n        FROM {$t_bug_table} b LEFT JOIN {$t_history_table} h \n            ON b.id = h.bug_id  AND h.type=0 AND h.field_name='status' AND h.new_value='{$t_resolved}'  \n            WHERE b.status >='{$t_resolved}' AND {$specific_where}\n            GROUP BY b.id, b.status, b.date_submitted, b.last_updated \n            ORDER BY b.id ASC";
$result = db_query($query);
$bug_count = db_num_rows($result);
$t_bug_id = 0;
$t_largest_diff = 0;
$t_total_time = 0;
for ($i = 0; $i < $bug_count; $i++) {
    $row = db_fetch_array($result);
    $t_date_submitted = db_unixtimestamp($row['date_submitted']);
    $t_id = $row['id'];
    $t_status = $row['status'];
    if ($row['hist_update'] !== NULL) {
        $t_last_updated = db_unixtimestamp($row['hist_update']);
    } else {
        $t_last_updated = db_unixtimestamp($row['last_updated']);
    }
    if ($t_last_updated < $t_date_submitted) {
        $t_last_updated = 0;
        $t_date_submitted = 0;
    }
    $t_diff = $t_last_updated - $t_date_submitted;
    $t_total_time = $t_total_time + $t_diff;
    if ($t_diff > $t_largest_diff) {
        $t_largest_diff = $t_diff;
        $t_bug_id = $row['id'];
    }
}
if ($bug_count < 1) {
    $bug_count = 1;
}
Example #9
0
function string_get_bugnote_view_link($p_bug_id, $p_bugnote_id, $p_user_id = null, $p_detail_info = true, $p_fqdn = false)
{
    if (bug_exists($p_bug_id) && bugnote_exists($p_bugnote_id)) {
        $t_link = '<a href="';
        if ($p_fqdn) {
            $t_link .= config_get('path');
        }
        $t_link .= string_get_bugnote_view_url($p_bug_id, $p_bugnote_id, $p_user_id) . '"';
        if ($p_detail_info) {
            $t_reporter = string_attribute(user_get_name(bugnote_get_field($p_bugnote_id, 'reporter_id')));
            $t_update_date = string_attribute(date(config_get('normal_date_format'), db_unixtimestamp(bugnote_get_field($p_bugnote_id, 'last_modified'))));
            $t_link .= ' title="[' . $t_update_date . '] ' . $t_reporter . '"';
        }
        $t_link .= '>' . lang_get('bugnote') . ': ' . bugnote_format_id($p_bugnote_id) . '</a>';
    } else {
        $t_link = lang_get('bugnote') . ': ' . bugnote_format_id($p_bugnote_id);
    }
    return $t_link;
}
Example #10
0
function news_get_limited_rows($p_offset, $p_project_id = null)
{
    if ($p_project_id === null) {
        $p_project_id = helper_get_current_project();
    }
    $c_offset = db_prepare_int($p_offset);
    $t_projects = current_user_get_all_accessible_subprojects($p_project_id);
    $t_projects[] = $p_project_id;
    if (ALL_PROJECTS != $p_project_id) {
        $t_projects[] = ALL_PROJECTS;
    }
    $t_projects = array_map('db_prepare_int', $t_projects);
    $t_news_table = config_get('mantis_news_table');
    $t_news_view_limit = config_get('news_view_limit');
    $t_news_view_limit_days = config_get('news_view_limit_days');
    switch (config_get('news_limit_method')) {
        case 0:
            # BY_LIMIT - Select the news posts
            $query = "SELECT *\n\t\t\t\t\t\tFROM {$t_news_table}";
            if (1 == count($t_projects)) {
                $c_project_id = $t_projects[0];
                $query .= " WHERE project_id='{$c_project_id}'";
            } else {
                $query .= ' WHERE project_id IN (' . join($t_projects, ',') . ')';
            }
            $query .= ' ORDER BY announcement DESC, id DESC';
            $result = db_query($query, $t_news_view_limit, $c_offset);
            break;
        case 1:
            # BY_DATE - Select the news posts
            $query = "SELECT *\n\t\t\t\t\t\tFROM {$t_news_table}";
            if (1 == count($t_projects)) {
                $c_project_id = $t_projects[0];
                $query .= " WHERE project_id='{$c_project_id}'";
            } else {
                $query .= ' WHERE project_id IN (' . join($t_projects, ',') . ')';
            }
            $query .= " AND " . db_helper_compare_days(db_now(), 'date_posted', "< {$t_news_view_limit_days}") . " OR  announcement = 1\n\t\t\t\t\t\tORDER BY announcement DESC, id DESC";
            $result = db_query($query, $t_news_view_limit, $c_offset);
            break;
    }
    # end switch
    $t_row_count = db_num_rows($result);
    $t_rows = array();
    for ($i = 0; $i < $t_row_count; $i++) {
        $row = db_fetch_array($result);
        $row['date_posted'] = db_unixtimestamp($row['date_posted']);
        array_push($t_rows, $row);
    }
    return $t_rows;
}
    echo lang_get('bug_notes_title');
    ?>
	</td>
</tr>
<?php 
    for ($i = 0; $i < $num_notes; $i++) {
        # prefix all bugnote data with v3_
        $row = db_fetch_array($result);
        extract($row, EXTR_PREFIX_ALL, 'v3');
        if (db_unixtimestamp($v3_date_submitted) != db_unixtimestamp($v3_last_modified)) {
            $t_bugnote_modified = true;
        } else {
            $t_bugnote_modified = false;
        }
        $v3_date_submitted = date(config_get('normal_date_format'), db_unixtimestamp($v3_date_submitted));
        $v3_last_modified = date(config_get('normal_date_format'), db_unixtimestamp($v3_last_modified));
        # grab the bugnote text and id and prefix with v3_
        $query = "SELECT note\n\t\t\t\tFROM {$t_bugnote_text_table}\n\t\t\t\tWHERE id='{$v3_bugnote_text_id}'";
        $result2 = db_query($query);
        $row = db_fetch_array($result2);
        $v3_note = $row['note'];
        $v3_note = string_display_links($v3_note);
        $t_bugnote_id_formatted = bugnote_format_id($v3_id);
        if (VS_PRIVATE == $v3_view_state) {
            $t_bugnote_css = 'bugnote-private';
            $t_bugnote_note_css = 'bugnote-note-private';
        } else {
            $t_bugnote_css = 'bugnote-public';
            $t_bugnote_note_css = 'bugnote-note-public';
        }
        ?>
Example #12
0
function bugnote_get_all_bugnotes($p_bug_id, $p_user_bugnote_order, $p_user_bugnote_limit)
{
    global $g_cache_bugnotes;
    if (!isset($g_cache_bugnotes)) {
        $g_cache_bugnotes = array();
    }
    # the cache should be aware of the sorting order
    if (!isset($g_cache_bugnotes[$p_bug_id][$p_user_bugnote_order])) {
        $c_bug_id = db_prepare_int($p_bug_id);
        $t_bugnote_table = config_get('mantis_bugnote_table');
        $t_bugnote_text_table = config_get('mantis_bugnote_text_table');
        if (0 == $p_user_bugnote_limit) {
            ## Show all bugnotes
            $t_bugnote_limit = -1;
            $t_bugnote_offset = -1;
        } else {
            ## Use offset only if order is ASC to get the last bugnotes
            if ('ASC' == $p_user_bugnote_order) {
                $result = db_query("SELECT COUNT(*) AS row_count FROM {$t_bugnote_table} WHERE bug_id = '{$c_bug_id}'");
                $row = db_fetch_array($result);
                $t_bugnote_offset = $row['row_count'] - $p_user_bugnote_limit;
            } else {
                $t_bugnote_offset = -1;
            }
            $t_bugnote_limit = $p_user_bugnote_limit;
        }
        # sort by bugnote id which should be more accurate than submit date, since two bugnotes
        # may be submitted at the same time if submitted using a script (eg: MantisConnect).
        $query = "SELECT b.*, t.note\r\n\t\t\t          \tFROM      {$t_bugnote_table} b\r\n\t\t\t          \tLEFT JOIN {$t_bugnote_text_table} t ON b.bugnote_text_id = t.id\r\n\t\t\t          \tWHERE b.bug_id = '{$c_bug_id}'\r\n\t\t\t          \tORDER BY b.id {$p_user_bugnote_order}";
        $t_bugnotes = array();
        # BUILD bugnotes array
        $result = db_query($query, $t_bugnote_limit, $t_bugnote_offset);
        $count = db_num_rows($result);
        for ($i = 0; $i < $count; $i++) {
            $row = db_fetch_array($result);
            $t_bugnote = new BugnoteData();
            $t_bugnote->id = $row['id'];
            $t_bugnote->bug_id = $row['bug_id'];
            $t_bugnote->note = $row['note'];
            $t_bugnote->view_state = $row['view_state'];
            $t_bugnote->reporter_id = $row['reporter_id'];
            $t_bugnote->date_submitted = db_unixtimestamp($row['date_submitted']);
            $t_bugnote->last_modified = db_unixtimestamp($row['last_modified']);
            $t_bugnote->note_type = $row['note_type'];
            $t_bugnote->note_attr = $row['note_attr'];
            $t_bugnote->time_tracking = $row['time_tracking'];
            $t_bugnotes[] = $t_bugnote;
        }
        $g_cache_bugnotes[$p_bug_id][$p_user_bugnote_order] = $t_bugnotes;
    }
    return $g_cache_bugnotes[$p_bug_id][$p_user_bugnote_order];
}
?>
	</td>
	<td class="right">
		<?php 
print_doc_menu('proj_doc_page.php');
?>
	</td>
</tr>
<?php 
for ($i = 0; $i < $num_files; $i++) {
    $row = db_fetch_array($result);
    extract($row, EXTR_PREFIX_ALL, 'v');
    $v_filesize = number_format($v_filesize);
    $v_title = string_display($v_title);
    $v_description = string_display_links($v_description);
    $v_date_added = date(config_get('normal_date_format'), db_unixtimestamp($v_date_added));
    ?>
<tr valign="top" <?php 
    echo helper_alternate_class($i);
    ?>
>
	<td>
<?php 
    $t_href = '<a href="file_download.php?file_id=' . $v_id . '&amp;type=doc">';
    echo $t_href;
    print_file_icon($v_filename);
    echo '</a>&nbsp;' . $t_href . $v_title . '</a> (' . $v_filesize . ' bytes)';
    ?>
	<br />
	<span class="small">
<?php 
Example #14
0
/**
 * Get the attachments of an issue.
 *
 * @param integer $p_issue_id  The id of the issue to retrieve the attachments for
 * @return Array that represents an AttachmentData structure
 */
function mci_issue_get_attachments($p_issue_id)
{
    $t_attachment_rows = bug_get_attachments($p_issue_id);
    $t_result = array();
    foreach ($t_attachment_rows as $t_attachment_row) {
        $t_attachment = array();
        $t_attachment['id'] = $t_attachment_row['id'];
        $t_attachment['filename'] = $t_attachment_row['filename'];
        $t_attachment['size'] = $t_attachment_row['filesize'];
        $t_attachment['content_type'] = $t_attachment_row['file_type'];
        $t_attachment['date_submitted'] = timestamp_to_iso8601(db_unixtimestamp($t_attachment_row['date_added']));
        $t_attachment['download_url'] = mci_get_mantis_path() . 'file_download.php?file_id=' . $t_attachment_row['id'] . '&amp;type=bug';
        $t_result[] = $t_attachment;
    }
    return $t_result;
}
/**
 * Format date for display
 */
function string_format_complete_date($p_date)
{
    $t_timestamp = db_unixtimestamp($p_date);
    return date(config_get('complete_date_format'), $t_timestamp);
}
Example #16
0
#  (e.g., bug is CLOSED, not RESOLVED). The linkage to the history field
#  will look up the most recent 'resolved' status change and return it as well
$query = "SELECT b.id, b.date_submitted, b.last_updated, MAX(h.date_modified) as hist_update, b.status \n        FROM {$t_bug_table} b LEFT JOIN {$t_history_table} h \n            ON b.id = h.bug_id  AND h.type=0 AND h.field_name='status' AND h.new_value='{$t_resolved}'  \n            WHERE b.status >='{$t_resolved}' \n            GROUP BY b.id, b.status, b.date_submitted, b.last_updated \n            ORDER BY b.id ASC";
$result = db_query($query);
$bug_count = db_num_rows($result);
$t_bug_id = 0;
$t_largest_diff = 0;
$t_total_time = 0;
for ($i = 0; $i < $bug_count; $i++) {
    $row = db_fetch_array($result);
    $t_date_submitted = db_unixtimestamp($row['date_submitted']);
    $t_last_updated = db_unixtimestamp($row['last_updated']);
    $t_id = $row['id'];
    $t_status = $row['status'];
    if ($row['hist_update'] !== NULL) {
        $t_last_updated = db_unixtimestamp($row['hist_update']);
    }
    if ($t_last_updated < $t_date_submitted) {
        $t_last_updated = 0;
        $t_date_submitted = 0;
    }
    $t_diff = $t_last_updated - $t_date_submitted;
    $t_total_time = $t_total_time + $t_diff;
    if ($t_diff > $t_largest_diff) {
        $t_largest_diff = $t_diff;
        $t_bug_id = $row['id'];
    }
}
if ($bug_count < 1) {
    $bug_count = 1;
}
Example #17
0
function version_get_all_rows_with_subs($p_project_id, $p_released = null)
{
    $t_project_where = helper_project_specific_where($p_project_id);
    if ($p_released === null) {
        $t_released_where = '';
    } else {
        $c_released = db_prepare_int($p_released);
        $t_released_where = "AND ( released = {$c_released} )";
    }
    $t_project_version_table = config_get('mantis_project_version_table');
    $query = "SELECT *\r\n\t\t\t\t  FROM {$t_project_version_table}\r\n\t\t\t\t  WHERE {$t_project_where} {$t_released_where}\r\n\t\t\t\t  ORDER BY date_order DESC";
    $result = db_query($query);
    $count = db_num_rows($result);
    $rows = array();
    for ($i = 0; $i < $count; $i++) {
        $row = db_fetch_array($result);
        $row['date_order'] = db_unixtimestamp($row['date_order']);
        $rows[] = $row;
    }
    return $rows;
}
Example #18
0
function email_collect_recipients($p_bug_id, $p_notify_type)
{
    $c_bug_id = db_prepare_int($p_bug_id);
    $t_recipients = array();
    # add Reporter
    if (ON == email_notify_flag($p_notify_type, 'reporter')) {
        $t_reporter_id = bug_get_field($p_bug_id, 'reporter_id');
        $t_recipients[$t_reporter_id] = true;
        log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, add reporter={$t_reporter_id}");
    }
    # add Handler
    if (ON == email_notify_flag($p_notify_type, 'handler')) {
        $t_handler_id = bug_get_field($p_bug_id, 'handler_id');
        if ($t_handler_id > 0) {
            $t_recipients[$t_handler_id] = true;
            log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, add handler={$t_handler_id}");
        }
    }
    $t_project_id = bug_get_field($p_bug_id, 'project_id');
    # add users monitoring the bug
    $t_bug_monitor_table = config_get('mantis_bug_monitor_table');
    if (ON == email_notify_flag($p_notify_type, 'monitor')) {
        $query = "SELECT DISTINCT user_id\n\t\t\t\t\t  FROM {$t_bug_monitor_table}\n\t\t\t\t\t  WHERE bug_id={$c_bug_id}";
        $result = db_query($query);
        $count = db_num_rows($result);
        for ($i = 0; $i < $count; $i++) {
            $t_user_id = db_result($result, $i);
            $t_recipients[$t_user_id] = true;
            log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, add monitor={$t_user_id}");
        }
    }
    # add users who contributed bugnotes
    $t_bugnote_id = bugnote_get_latest_id($p_bug_id);
    $t_bugnote_view = bugnote_get_field($t_bugnote_id, 'view_state');
    $t_bugnote_date = db_unixtimestamp(bugnote_get_field($t_bugnote_id, 'last_modified'));
    $t_bug_date = bug_get_field($p_bug_id, 'last_updated');
    $t_bugnote_table = config_get('mantis_bugnote_table');
    if (ON == email_notify_flag($p_notify_type, 'bugnotes')) {
        $query = "SELECT DISTINCT reporter_id\n\t\t\t\t\t  FROM {$t_bugnote_table}\n\t\t\t\t\t  WHERE bug_id = {$c_bug_id}";
        $result = db_query($query);
        $count = db_num_rows($result);
        for ($i = 0; $i < $count; $i++) {
            $t_user_id = db_result($result, $i);
            $t_recipients[$t_user_id] = true;
            log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, add note author={$t_user_id}");
        }
    }
    # add project users who meet the thresholds
    $t_bug_is_private = bug_get_field($p_bug_id, 'view_state') == VS_PRIVATE;
    $t_threshold_min = email_notify_flag($p_notify_type, 'threshold_min');
    $t_threshold_max = email_notify_flag($p_notify_type, 'threshold_max');
    $t_threshold_users = project_get_all_user_rows($t_project_id, $t_threshold_min);
    foreach ($t_threshold_users as $t_user) {
        if ($t_user['access_level'] <= $t_threshold_max) {
            if (!$t_bug_is_private || access_compare_level($t_user['access_level'], config_get('private_bug_threshold'))) {
                $t_recipients[$t_user['id']] = true;
                log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, add project user="******"bug={$p_bug_id}, drop {$t_id} (own)");
            continue;
        }
        # Eliminate users who don't exist anymore or who are disabled
        if (!user_exists($t_id) || !user_is_enabled($t_id)) {
            log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, drop {$t_id} (disabled)");
            continue;
        }
        # Exclude users who have this notification type turned off
        if ($t_pref_field) {
            $t_notify = user_pref_get_pref($t_id, $t_pref_field);
            if (OFF == $t_notify) {
                log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, drop {$t_id} (pref {$t_pref_field} off)");
                continue;
            } else {
                # Users can define the severity of an issue before they are emailed for
                # each type of notification
                $t_min_sev_pref_field = $t_pref_field . '_min_severity';
                $t_min_sev_notify = user_pref_get_pref($t_id, $t_min_sev_pref_field);
                $t_bug_severity = bug_get_field($p_bug_id, 'severity');
                if ($t_bug_severity < $t_min_sev_notify) {
                    log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, drop {$t_id} (pref threshold)");
                    continue;
                }
            }
        }
        # check that user can see bugnotes if the last update included a bugnote
        if ($t_bug_date == $t_bugnote_date) {
            if (!access_has_bugnote_level(VIEWER, $t_bugnote_id, $t_id)) {
                log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, drop {$t_id} (access level)");
                continue;
            }
        }
        # Finally, let's get their emails, if they've set one
        $t_email = user_get_email($t_id);
        if (is_blank($t_email)) {
            log_event(LOG_EMAIL_RECIPIENT, "bug={$p_bug_id}, drop {$t_id} (no email)");
        } else {
            # @@@ we could check the emails for validity again but I think
            #   it would be too slow
            $t_final_recipients[$t_id] = $t_email;
        }
    }
    return $t_final_recipients;
}
    } else {
        $t_data[$t_ptr][$t_row['status']] = 1;
        $t_view_status[$t_row['status']] = isset($t_status_arr[$t_row['status']]) ? $t_status_arr[$t_row['status']] : '@' . $t_row['status'] . '@';
    }
    $t_bug[] = $t_row['id'];
}
// get the history for these bugs over the interval required to offset the data
// type = 0 and field=status are status changes
// type = 1 are new bugs
$t_select = 'SELECT bug_id, type, old_value, new_value, date_modified FROM ' . $t_bug_hist_table . ' WHERE bug_id in (' . implode(',', $t_bug) . ') and ( (type=' . NORMAL_TYPE . ' and field_name=\'status\') 
            or type=' . NEW_BUG . ' ) and date_modified >= \'' . db_date($t_start) . '\'' . ' order by date_modified DESC';
$t_result = db_query($t_select);
$t_row = db_fetch_array($t_result);
for ($t_now = time() - $t_incr; $t_now >= $t_start; $t_now -= $t_incr) {
    // walk through the data points and use the data retrieved to update counts
    while ($t_row !== false && db_unixtimestamp($t_row['date_modified']) >= $t_now) {
        switch ($t_row['type']) {
            case 0:
                // updated bug
                if (isset($t_data[$t_ptr][$t_row['new_value']])) {
                    if ($t_data[$t_ptr][$t_row['new_value']] > 0) {
                        $t_data[$t_ptr][$t_row['new_value']]--;
                    }
                } else {
                    $t_data[$t_ptr][$t_row['new_value']] = 0;
                    $t_view_status[$t_row['new_value']] = isset($t_status_arr[$t_row['new_value']]) ? $t_status_arr[$t_row['new_value']] : '@' . $t_row['new_value'] . '@';
                }
                if (isset($t_data[$t_ptr][$t_row['old_value']])) {
                    $t_data[$t_ptr][$t_row['old_value']]++;
                } else {
                    $t_data[$t_ptr][$t_row['old_value']] = 1;
    $query = "SELECT COUNT(*)\r\n\t\t\t\tFROM mantis_bug_table\r\n\t\t\t\tWHERE last_updated<='{$p_date}' AND\r\n\t\t\t\t\tstatus='90' AND\r\n\t\t\t\t\tproject_id='{$t_project_id}'";
    $result = db_query($query);
    return db_result($result, 0, 0);
}
# -- start --
$t_project_id = helper_get_current_project();
$query = "SELECT status, date_submitted, last_updated\r\n\t\t\tFROM mantis_bug_table\r\n\t\t\tWHERE project_id='{$t_project_id}' AND\r\n\t\t\t\t\tdate_submitted>='{$g_start_date}'\r\n\t\t\tORDER BY date_submitted ASC";
$result = db_query($query);
$bug_count = db_num_rows($result);
$data_date_arr = array();
while ($row = db_fetch_array($result)) {
    extract($row);
    if ($status < 80) {
        $date_str = date('m/d/Y', db_unixtimestamp($date_submitted));
    } else {
        $date_str = date('m/d/Y', db_unixtimestamp($last_updated));
    }
    $data_date_arr[] = $date_str;
}
$counter = 0;
while ($row = db_fetch_array($result)) {
    extract($row);
}
$data_date_arr_temp = array_unique($data_date_arr);
$data_date_arr = array();
foreach ($data_date_arr_temp as $key => $val) {
    $data_date_arr[] = $val;
}
usort($data_date_arr, 'tmpcmp');
# total up open
$data_open_count_arr = array();
Example #21
0
    html_set_rss_link($t_rss_link);
}
html_page_top1();
html_page_top2();
if (!current_user_is_anonymous()) {
    echo '<div class="quick-summary-left">';
    echo lang_get('open_and_assigned_to_me') . ': ';
    echo '<a class="subtle" href="view_all_set.php?type=1&amp;handler_id=' . auth_get_current_user_id() . '&amp;hide_status=' . RESOLVED . '">' . current_user_get_assigned_open_bug_count() . '</a>';
    echo '</div>';
    echo '<div class="quick-summary-right">';
    echo lang_get('open_and_reported_to_me') . ': ';
    echo '<a class="subtle" href="view_all_set.php?type=1&amp;reporter_id=' . auth_get_current_user_id() . '&amp;hide_status=' . RESOLVED . '">' . current_user_get_reported_open_bug_count() . '</a>';
    echo '</div>';
    echo '<div class="quick-summary-left">';
    echo lang_get('last_visit') . ': ';
    echo print_date(config_get('normal_date_format'), db_unixtimestamp(current_user_get_field('last_visit')));
    echo '</div>';
}
echo '<br />';
echo '<br />';
echo '<br />';
$t_news_rows = news_get_limited_rows($f_offset, $t_project_id);
$t_news_count = count($t_news_rows);
# Loop through results
for ($i = 0; $i < $t_news_count; $i++) {
    $t_row = $t_news_rows[$i];
    # only show VS_PRIVATE posts to configured threshold and above
    if (VS_PRIVATE == $t_row['view_state'] && !access_has_project_level(config_get('private_news_threshold'))) {
        continue;
    }
    print_news_entry_from_row($t_row);
Example #22
0
function filter_get_bug_rows(&$p_page_number, &$p_per_page, &$p_page_count, &$p_bug_count, $p_custom_filter = null, $p_project_id = null, $p_user_id = null, $p_show_sticky = null)
{
    log_event(LOG_FILTERING, 'FILTERING: START NEW FILTER QUERY');
    $t_bug_table = config_get('mantis_bug_table');
    $t_bug_text_table = config_get('mantis_bug_text_table');
    $t_bugnote_table = config_get('mantis_bugnote_table');
    $t_custom_field_string_table = config_get('mantis_custom_field_string_table');
    $t_bugnote_text_table = config_get('mantis_bugnote_text_table');
    $t_project_table = config_get('mantis_project_table');
    $t_bug_monitor_table = config_get('mantis_bug_monitor_table');
    $t_limit_reporters = config_get('limit_reporters');
    $t_bug_relationship_table = config_get('mantis_bug_relationship_table');
    $t_report_bug_threshold = config_get('report_bug_threshold');
    $t_current_user_id = auth_get_current_user_id();
    if (null === $p_user_id) {
        $t_user_id = $t_current_user_id;
    } else {
        $t_user_id = $p_user_id;
    }
    $c_user_id = db_prepare_int($t_user_id);
    if (null === $p_project_id) {
        # @@@ If project_id is not specified, then use the project id(s) in the filter if set, otherwise, use current project.
        $t_project_id = helper_get_current_project();
    } else {
        $t_project_id = $p_project_id;
    }
    if ($p_custom_filter === null) {
        # Prefer current_user_get_bug_filter() over user_get_filter() when applicable since it supports
        # cookies set by previous version of the code.
        if ($t_user_id == $t_current_user_id) {
            $t_filter = current_user_get_bug_filter();
        } else {
            $t_filter = user_get_bug_filter($t_user_id, $t_project_id);
        }
    } else {
        $t_filter = $p_custom_filter;
    }
    $t_filter = filter_ensure_valid_filter($t_filter);
    if (false === $t_filter) {
        return false;
        # signify a need to create a cookie
        #@@@ error instead?
    }
    $t_view_type = $t_filter['_view_type'];
    $t_where_clauses = array("{$t_project_table}.enabled = 1", "{$t_project_table}.id = {$t_bug_table}.project_id");
    $t_select_clauses = array("{$t_bug_table}.*");
    $t_join_clauses = array();
    $t_from_clauses = array();
    // normalize the project filtering into an array $t_project_ids
    if ('simple' == $t_view_type) {
        log_event(LOG_FILTERING, 'FILTERING: Simple Filter');
        $t_project_ids = array($t_project_id);
        $t_include_sub_projects = true;
    } else {
        log_event(LOG_FILTERING, 'FILTERING: Advanced Filter');
        if (!is_array($t_filter['project_id'])) {
            $t_project_ids = array(db_prepare_int($t_filter['project_id']));
        } else {
            $t_project_ids = array_map('db_prepare_int', $t_filter['project_id']);
        }
        $t_include_sub_projects = count($t_project_ids) == 1 && $t_project_ids[0] == META_FILTER_CURRENT;
    }
    log_event(LOG_FILTERING, 'FILTERING: project_ids = ' . implode(',', $t_project_ids));
    log_event(LOG_FILTERING, 'FILTERING: include sub-projects = ' . ($t_include_sub_projects ? '1' : '0'));
    // if the array has ALL_PROJECTS, then reset the array to only contain ALL_PROJECTS.
    // replace META_FILTER_CURRENT with the actualy current project id.
    $t_all_projects_found = false;
    $t_new_project_ids = array();
    foreach ($t_project_ids as $t_pid) {
        if ($t_pid == META_FILTER_CURRENT) {
            $t_pid = $t_project_id;
        }
        if ($t_pid == ALL_PROJECTS) {
            $t_all_projects_found = true;
            log_event(LOG_FILTERING, 'FILTERING: all projects selected');
            break;
        }
        // filter out inaccessible projects.
        if (!access_has_project_level(VIEWER, $t_pid, $t_user_id)) {
            continue;
        }
        $t_new_project_ids[] = $t_pid;
    }
    $t_projects_query_required = true;
    if ($t_all_projects_found) {
        if (user_is_administrator($t_user_id)) {
            log_event(LOG_FILTERING, 'FILTERING: all projects + administrator, hence no project filter.');
            $t_projects_query_required = false;
        } else {
            $t_project_ids = user_get_accessible_projects($t_user_id);
        }
    } else {
        $t_project_ids = $t_new_project_ids;
    }
    if ($t_projects_query_required) {
        // expand project ids to include sub-projects
        if ($t_include_sub_projects) {
            $t_top_project_ids = $t_project_ids;
            foreach ($t_top_project_ids as $t_pid) {
                log_event(LOG_FILTERING, 'FILTERING: Getting sub-projects for project id ' . $t_pid);
                $t_project_ids = array_merge($t_project_ids, user_get_all_accessible_subprojects($t_user_id, $t_pid));
            }
            $t_project_ids = array_unique($t_project_ids);
        }
        // if no projects are accessible, then return an empty array.
        if (count($t_project_ids) == 0) {
            log_event(LOG_FILTERING, 'FILTERING: no accessible projects');
            return array();
        }
        log_event(LOG_FILTERING, 'FILTERING: project_ids after including sub-projects = ' . implode(',', $t_project_ids));
        // this array is to be populated with project ids for which we only want to show public issues.  This is due to the limited
        // access of the current user.
        $t_public_only_project_ids = array();
        // this array is populated with project ids that the current user has full access to.
        $t_private_and_public_project_ids = array();
        $t_access_required_to_view_private_bugs = config_get('private_bug_threshold');
        foreach ($t_project_ids as $t_pid) {
            if (access_has_project_level($t_access_required_to_view_private_bugs, $t_pid, $t_user_id)) {
                $t_private_and_public_project_ids[] = $t_pid;
            } else {
                $t_public_only_project_ids[] = $t_pid;
            }
        }
        log_event(LOG_FILTERING, 'FILTERING: project_ids (with public/private access) = ' . implode(',', $t_private_and_public_project_ids));
        log_event(LOG_FILTERING, 'FILTERING: project_ids (with public access) = ' . implode(',', $t_public_only_project_ids));
        $t_count_private_and_public_project_ids = count($t_private_and_public_project_ids);
        if ($t_count_private_and_public_project_ids == 1) {
            $t_private_and_public_query = "( {$t_bug_table}.project_id = " . $t_private_and_public_project_ids[0] . " )";
        } else {
            if ($t_count_private_and_public_project_ids > 1) {
                $t_private_and_public_query = "( {$t_bug_table}.project_id in (" . implode(', ', $t_private_and_public_project_ids) . ") )";
            } else {
                $t_private_and_public_query = null;
            }
        }
        $t_count_public_only_project_ids = count($t_public_only_project_ids);
        $t_public_view_state_check = "( ( {$t_bug_table}.view_state = " . VS_PUBLIC . " ) OR ( {$t_bug_table}.reporter_id = {$t_user_id} ) )";
        if ($t_count_public_only_project_ids == 1) {
            $t_public_only_query = "( ( {$t_bug_table}.project_id = " . $t_public_only_project_ids[0] . " ) AND {$t_public_view_state_check} )";
        } else {
            if ($t_count_public_only_project_ids > 1) {
                $t_public_only_query = "( ( {$t_bug_table}.project_id in (" . implode(', ', $t_public_only_project_ids) . ") ) AND {$t_public_view_state_check} )";
            } else {
                $t_public_only_query = null;
            }
        }
        // both queries can't be null, so we either have one of them or both.
        if ($t_private_and_public_query === null) {
            $t_project_query = $t_public_only_query;
        } else {
            if ($t_public_only_query === null) {
                $t_project_query = $t_private_and_public_query;
            } else {
                $t_project_query = "( {$t_public_only_query} OR {$t_private_and_public_query} )";
            }
        }
        log_event(LOG_FILTERING, 'FILTERING: project query = ' . $t_project_query);
        array_push($t_where_clauses, $t_project_query);
    }
    # view state
    $t_view_state = db_prepare_int($t_filter['view_state']);
    if ($t_filter['view_state'] !== META_FILTER_ANY && !is_blank($t_filter['view_state'])) {
        $t_view_state_query = "({$t_bug_table}.view_state='{$t_view_state}')";
        log_event(LOG_FILTERING, 'FILTERING: view_state query = ' . $t_view_state_query);
        array_push($t_where_clauses, $t_view_state_query);
    } else {
        log_event(LOG_FILTERING, 'FILTERING: no view_state query');
    }
    # reporter
    $t_any_found = false;
    foreach ($t_filter['reporter_id'] as $t_filter_member) {
        if (META_FILTER_ANY === $t_filter_member || 0 === $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['reporter_id']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['reporter_id'] as $t_filter_member) {
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "0");
            } else {
                $c_reporter_id = db_prepare_int($t_filter_member);
                if (META_FILTER_MYSELF == $c_reporter_id) {
                    array_push($t_clauses, $c_user_id);
                } else {
                    array_push($t_clauses, $c_reporter_id);
                }
            }
        }
        if (1 < count($t_clauses)) {
            $t_reporter_query = "( {$t_bug_table}.reporter_id in (" . implode(', ', $t_clauses) . ") )";
        } else {
            $t_reporter_query = "( {$t_bug_table}.reporter_id={$t_clauses['0']} )";
        }
        log_event(LOG_FILTERING, 'FILTERING: reporter query = ' . $t_reporter_query);
        array_push($t_where_clauses, $t_reporter_query);
    } else {
        log_event(LOG_FILTERING, 'FILTERING: no reporter query');
    }
    # limit reporter
    # @@@ thraxisp - access_has_project_level checks greater than or equal to,
    #   this assumed that there aren't any holes above REPORTER where the limit would apply
    #
    if (ON === $t_limit_reporters && !access_has_project_level(REPORTER + 1, $t_project_id, $t_user_id)) {
        $c_reporter_id = $c_user_id;
        array_push($t_where_clauses, "({$t_bug_table}.reporter_id='{$c_reporter_id}')");
    }
    # handler
    $t_any_found = false;
    foreach ($t_filter['handler_id'] as $t_filter_member) {
        if (META_FILTER_ANY === $t_filter_member || 0 === $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['handler_id']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['handler_id'] as $t_filter_member) {
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, 0);
            } else {
                $c_handler_id = db_prepare_int($t_filter_member);
                if (META_FILTER_MYSELF == $c_handler_id) {
                    array_push($t_clauses, $c_user_id);
                } else {
                    array_push($t_clauses, $c_handler_id);
                }
            }
        }
        if (1 < count($t_clauses)) {
            $t_handler_query = "( {$t_bug_table}.handler_id in (" . implode(', ', $t_clauses) . ") )";
        } else {
            $t_handler_query = "( {$t_bug_table}.handler_id={$t_clauses['0']} )";
        }
        log_event(LOG_FILTERING, 'FILTERING: handler query = ' . $t_handler_query);
        array_push($t_where_clauses, $t_handler_query);
    } else {
        log_event(LOG_FILTERING, 'FILTERING: no handler query');
    }
    # category
    if (!_filter_is_any($t_filter['show_category'])) {
        $t_clauses = array();
        foreach ($t_filter['show_category'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "''");
            } else {
                $c_show_category = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_show_category}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.category in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.category={$t_clauses['0']} )");
        }
    }
    # severity
    $t_any_found = false;
    foreach ($t_filter['show_severity'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member || 0 === $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['show_severity']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['show_severity'] as $t_filter_member) {
            $c_show_severity = db_prepare_int($t_filter_member);
            array_push($t_clauses, $c_show_severity);
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.severity in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.severity={$t_clauses['0']} )");
        }
    }
    # show / hide status
    # take a list of all available statuses then remove the ones that we want hidden, then make sure
    # the ones we want shown are still available
    $t_status_arr = explode_enum_string(config_get('status_enum_string'));
    $t_available_statuses = array();
    $t_desired_statuses = array();
    foreach ($t_status_arr as $t_this_status) {
        $t_this_status_arr = explode_enum_arr($t_this_status);
        $t_available_statuses[] = $t_this_status_arr[0];
    }
    if ('simple' == $t_filter['_view_type']) {
        # simple filtering: if showing any, restrict by the hide status value, otherwise ignore the hide
        $t_any_found = false;
        $t_this_status = $t_filter['show_status'][0];
        $t_this_hide_status = $t_filter['hide_status'][0];
        if (META_FILTER_ANY == $t_this_status || is_blank($t_this_status) || 0 === $t_this_status) {
            $t_any_found = true;
        }
        if ($t_any_found) {
            foreach ($t_available_statuses as $t_this_available_status) {
                if ($t_this_hide_status > $t_this_available_status) {
                    $t_desired_statuses[] = $t_this_available_status;
                }
            }
        } else {
            $t_desired_statuses[] = $t_this_status;
        }
    } else {
        # advanced filtering: ignore the hide
        $t_any_found = false;
        foreach ($t_filter['show_status'] as $t_this_status) {
            $t_desired_statuses[] = $t_this_status;
            if (META_FILTER_ANY == $t_this_status || is_blank($t_this_status) || 0 === $t_this_status) {
                $t_any_found = true;
            }
        }
        if ($t_any_found) {
            $t_desired_statuses = array();
        }
    }
    if (count($t_desired_statuses) > 0) {
        $t_clauses = array();
        foreach ($t_desired_statuses as $t_filter_member) {
            $c_show_status = db_prepare_int($t_filter_member);
            array_push($t_clauses, $c_show_status);
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.status in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.status={$t_clauses['0']} )");
        }
    }
    # resolution
    $t_any_found = false;
    foreach ($t_filter['show_resolution'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['show_resolution']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['show_resolution'] as $t_filter_member) {
            $c_show_resolution = db_prepare_int($t_filter_member);
            array_push($t_clauses, $c_show_resolution);
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.resolution in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.resolution={$t_clauses['0']} )");
        }
    }
    # priority
    $t_any_found = false;
    foreach ($t_filter['show_priority'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member || 0 === $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['show_priority']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['show_priority'] as $t_filter_member) {
            $c_show_priority = db_prepare_int($t_filter_member);
            array_push($t_clauses, $c_show_priority);
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.priority in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.priority={$t_clauses['0']} )");
        }
    }
    # product build
    $t_any_found = false;
    foreach ($t_filter['show_build'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member && is_numeric($t_filter_member)) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['show_build']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        foreach ($t_filter['show_build'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "''");
            } else {
                $c_show_build = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_show_build}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.build in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.build={$t_clauses['0']} )");
        }
    }
    # product version
    if (!_filter_is_any($t_filter['show_version'])) {
        $t_clauses = array();
        foreach ($t_filter['show_version'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "''");
            } else {
                $c_show_version = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_show_version}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.version in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.version={$t_clauses['0']} )");
        }
    }
    # profile
    if (!_filter_is_any($t_filter['show_profile'])) {
        $t_clauses = array();
        foreach ($t_filter['show_profile'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "0");
            } else {
                $c_show_profile = db_prepare_int($t_filter_member);
                array_push($t_clauses, "{$c_show_profile}");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.profile_id in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.profile_id={$t_clauses['0']} )");
        }
    }
    # platform
    if (!_filter_is_any($t_filter['platform'])) {
        $t_clauses = array();
        foreach ($t_filter['platform'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, '');
            } else {
                $c_platform = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_platform}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.platform in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.platform = {$t_clauses['0']} )");
        }
    }
    # os
    if (!_filter_is_any($t_filter['os'])) {
        $t_clauses = array();
        foreach ($t_filter['os'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, '');
            } else {
                $c_os = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_os}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.os in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.os = {$t_clauses['0']} )");
        }
    }
    # os_build
    if (!_filter_is_any($t_filter['os_build'])) {
        $t_clauses = array();
        foreach ($t_filter['os_build'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, '');
            } else {
                $c_os_build = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_os_build}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.os_build in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.os_build = {$t_clauses['0']} )");
        }
    }
    # date filter
    if ('on' == $t_filter['do_filter_by_date'] && is_numeric($t_filter['start_month']) && is_numeric($t_filter['start_day']) && is_numeric($t_filter['start_year']) && is_numeric($t_filter['end_month']) && is_numeric($t_filter['end_day']) && is_numeric($t_filter['end_year'])) {
        $t_start_string = db_prepare_string($t_filter['start_year'] . "-" . $t_filter['start_month'] . "-" . $t_filter['start_day'] . " 00:00:00");
        $t_end_string = db_prepare_string($t_filter['end_year'] . "-" . $t_filter['end_month'] . "-" . $t_filter['end_day'] . " 23:59:59");
        array_push($t_where_clauses, "({$t_bug_table}.date_submitted BETWEEN '{$t_start_string}' AND '{$t_end_string}' )");
    }
    # fixed in version
    if (!_filter_is_any($t_filter['fixed_in_version'])) {
        $t_clauses = array();
        foreach ($t_filter['fixed_in_version'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "''");
            } else {
                $c_fixed_in_version = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_fixed_in_version}'");
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.fixed_in_version in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.fixed_in_version={$t_clauses['0']} )");
        }
    }
    # target version
    if (!_filter_is_any($t_filter['target_version'])) {
        $t_clauses = array();
        foreach ($t_filter['target_version'] as $t_filter_member) {
            $t_filter_member = stripslashes($t_filter_member);
            if (META_FILTER_NONE == $t_filter_member) {
                array_push($t_clauses, "''");
            } else {
                $c_target_version = db_prepare_string($t_filter_member);
                array_push($t_clauses, "'{$c_target_version}'");
            }
        }
        #echo var_dump( $t_clauses ); exit;
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_bug_table}.target_version in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_bug_table}.target_version={$t_clauses['0']} )");
        }
    }
    # users monitoring a bug
    $t_any_found = false;
    foreach ($t_filter['user_monitor'] as $t_filter_member) {
        if (META_FILTER_ANY == $t_filter_member || 0 === $t_filter_member) {
            $t_any_found = true;
        }
    }
    if (count($t_filter['user_monitor']) == 0) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        $t_clauses = array();
        $t_table_name = 'user_monitor';
        array_push($t_from_clauses, $t_bug_monitor_table);
        array_push($t_join_clauses, "LEFT JOIN {$t_bug_monitor_table} {$t_table_name} ON {$t_table_name}.bug_id = {$t_bug_table}.id");
        foreach ($t_filter['user_monitor'] as $t_filter_member) {
            $c_user_monitor = db_prepare_int($t_filter_member);
            if (META_FILTER_MYSELF == $c_user_monitor) {
                array_push($t_clauses, $c_user_id);
            } else {
                array_push($t_clauses, $c_user_monitor);
            }
        }
        if (1 < count($t_clauses)) {
            array_push($t_where_clauses, "( {$t_table_name}.user_id in (" . implode(', ', $t_clauses) . ") )");
        } else {
            array_push($t_where_clauses, "( {$t_table_name}.user_id={$t_clauses['0']} )");
        }
    }
    # bug relationship
    $t_any_found = false;
    $c_rel_type = $t_filter['relationship_type'];
    $c_rel_bug = $t_filter['relationship_bug'];
    if (-1 == $c_rel_type || 0 == $c_rel_bug) {
        $t_any_found = true;
    }
    if (!$t_any_found) {
        # use the complementary type
        $t_comp_type = relationship_get_complementary_type($c_rel_type);
        $t_clauses = array();
        $t_table_name = 'relationship';
        array_push($t_from_clauses, $t_bug_relationship_table);
        array_push($t_join_clauses, "LEFT JOIN {$t_bug_relationship_table} {$t_table_name} ON {$t_table_name}.destination_bug_id = {$t_bug_table}.id");
        array_push($t_join_clauses, "LEFT JOIN {$t_bug_relationship_table} {$t_table_name}2 ON {$t_table_name}2.source_bug_id = {$t_bug_table}.id");
        // get reverse relationships
        array_push($t_clauses, "({$t_table_name}.relationship_type='{$t_comp_type}' AND {$t_table_name}.source_bug_id='{$c_rel_bug}')");
        array_push($t_clauses, "({$t_table_name}" . "2.relationship_type='{$c_rel_type}' AND {$t_table_name}" . "2.destination_bug_id='{$c_rel_bug}')");
        array_push($t_where_clauses, '(' . implode(' OR ', $t_clauses) . ')');
    }
    # tags
    $c_tag_string = trim($t_filter['tag_string']);
    if (!is_blank($c_tag_string)) {
        $t_tags = tag_parse_filters($c_tag_string);
        if (count($t_tags)) {
            $t_tags_all = array();
            $t_tags_any = array();
            $t_tags_none = array();
            foreach ($t_tags as $t_tag_row) {
                switch ($t_tag_row['filter']) {
                    case 1:
                        $t_tags_all[] = $t_tag_row;
                        break;
                    case 0:
                        $t_tags_any[] = $t_tag_row;
                        break;
                    case -1:
                        $t_tags_none[] = $t_tag_row;
                        break;
                }
            }
            if (0 < $t_filter['tag_select'] && tag_exists($t_filter['tag_select'])) {
                $t_tags_any[] = tag_get($t_filter['tag_select']);
            }
            $t_bug_tag_table = config_get('mantis_bug_tag_table');
            if (count($t_tags_all)) {
                $t_clauses = array();
                foreach ($t_tags_all as $t_tag_row) {
                    array_push($t_clauses, "{$t_bug_table}.id IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE {$t_bug_tag_table}.tag_id = {$t_tag_row['id']} )");
                }
                array_push($t_where_clauses, '(' . implode(' AND ', $t_clauses) . ')');
            }
            if (count($t_tags_any)) {
                $t_clauses = array();
                foreach ($t_tags_any as $t_tag_row) {
                    array_push($t_clauses, "{$t_bug_tag_table}.tag_id = {$t_tag_row['id']}");
                }
                array_push($t_where_clauses, "{$t_bug_table}.id IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE ( " . implode(' OR ', $t_clauses) . ') )');
            }
            if (count($t_tags_none)) {
                $t_clauses = array();
                foreach ($t_tags_none as $t_tag_row) {
                    array_push($t_clauses, "{$t_bug_tag_table}.tag_id = {$t_tag_row['id']}");
                }
                array_push($t_where_clauses, "{$t_bug_table}.id NOT IN ( SELECT bug_id FROM {$t_bug_tag_table} WHERE ( " . implode(' OR ', $t_clauses) . ') )');
            }
        }
    }
    # custom field filters
    if (ON == config_get('filter_by_custom_fields')) {
        # custom field filtering
        # @@@ At the moment this gets the linked fields relating to the current project
        #     It should get the ones relating to the project in the filter or all projects
        #     if multiple projects.
        $t_custom_fields = custom_field_get_linked_ids($t_project_id);
        foreach ($t_custom_fields as $t_cfid) {
            $t_custom_where_clause = '';
            # Ignore all custom filters that are not set, or that are set to '' or "any"
            $t_any_found = false;
            foreach ($t_filter['custom_fields'][$t_cfid] as $t_filter_member) {
                if (META_FILTER_ANY == $t_filter_member && is_numeric($t_filter_member)) {
                    $t_any_found = true;
                }
            }
            if (!isset($t_filter['custom_fields'][$t_cfid])) {
                $t_any_found = true;
            }
            if (!$t_any_found) {
                $t_def = custom_field_get_definition($t_cfid);
                $t_table_name = $t_custom_field_string_table . '_' . $t_cfid;
                # We need to filter each joined table or the result query will explode in dimensions
                # Each custom field will result in a exponential growth like Number_of_Issues^Number_of_Custom_Fields
                # and only after this process ends (if it is able to) the result query will be filtered
                # by the WHERE clause and by the DISTINCT clause
                $t_cf_join_clause = "LEFT JOIN {$t_custom_field_string_table} {$t_table_name} ON {$t_table_name}.bug_id = {$t_bug_table}.id AND {$t_table_name}.field_id = {$t_cfid} ";
                if ($t_def['type'] == CUSTOM_FIELD_TYPE_DATE) {
                    switch ($t_filter['custom_fields'][$t_cfid][0]) {
                        case CUSTOM_FIELD_DATE_ANY:
                            break;
                        case CUSTOM_FIELD_DATE_NONE:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '(( ' . $t_table_name . '.bug_id is null) OR ( ' . $t_table_name . '.value = 0)';
                            break;
                        case CUSTOM_FIELD_DATE_BEFORE:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '(( ' . $t_table_name . '.value != 0 AND (' . $t_table_name . '.value+0) < ' . $t_filter['custom_fields'][$t_cfid][2] . ')';
                            break;
                        case CUSTOM_FIELD_DATE_AFTER:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '( (' . $t_table_name . '.value+0) > ' . ($t_filter['custom_fields'][$t_cfid][1] + 1);
                            break;
                        default:
                            array_push($t_join_clauses, $t_cf_join_clause);
                            $t_custom_where_clause = '( (' . $t_table_name . '.value+0) BETWEEN ' . $t_filter['custom_fields'][$t_cfid][1] . ' AND ' . $t_filter['custom_fields'][$t_cfid][2];
                            break;
                    }
                } else {
                    array_push($t_join_clauses, $t_cf_join_clause);
                    $t_filter_array = array();
                    foreach ($t_filter['custom_fields'][$t_cfid] as $t_filter_member) {
                        $t_filter_member = stripslashes($t_filter_member);
                        if (META_FILTER_NONE == $t_filter_member) {
                            # coerce filter value if selecting META_FILTER_NONE so it will match empty fields
                            $t_filter_member = '';
                            # but also add those _not_ present in the custom field string table
                            array_push($t_filter_array, "{$t_bug_table}.id NOT IN (SELECT bug_id FROM {$t_custom_field_string_table} WHERE field_id={$t_cfid})");
                        }
                        switch ($t_def['type']) {
                            case CUSTOM_FIELD_TYPE_MULTILIST:
                            case CUSTOM_FIELD_TYPE_CHECKBOX:
                                array_push($t_filter_array, db_helper_like("{$t_table_name}.value", '%|' . db_prepare_string($t_filter_member) . '|%'));
                                break;
                            default:
                                array_push($t_filter_array, "{$t_table_name}.value = '" . db_prepare_string($t_filter_member) . "'");
                        }
                    }
                    $t_custom_where_clause .= '(' . implode(' OR ', $t_filter_array);
                }
                if (!is_blank($t_custom_where_clause)) {
                    array_push($t_where_clauses, $t_custom_where_clause . ')');
                }
            }
        }
    }
    $t_textsearch_where_clause = '';
    $t_textsearch_wherejoin_clause = '';
    # Simple Text Search - Thanks to Alan Knowles
    if (!is_blank($t_filter['search'])) {
        $c_search = db_prepare_string($t_filter['search']);
        $c_search_int = db_prepare_int($t_filter['search']);
        $t_textsearch_where_clause = '(' . db_helper_like('summary', "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.description", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.steps_to_reproduce", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.additional_information", "%{$c_search}%") . " OR ( {$t_bug_table}.id = '{$c_search_int}' ) )";
        $t_textsearch_wherejoin_clause = '(' . db_helper_like('summary', "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.description", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.steps_to_reproduce", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_text_table}.additional_information", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bug_table}.id", "%{$c_search}%") . ' OR ' . db_helper_like("{$t_bugnote_text_table}.note", "%{$c_search}%") . ' )';
        array_push($t_where_clauses, "({$t_bug_text_table}.id = {$t_bug_table}.bug_text_id)");
        $t_from_clauses = array($t_bug_text_table, $t_project_table, $t_bug_table);
    } else {
        $t_from_clauses = array($t_project_table, $t_bug_table);
    }
    $t_select = implode(', ', array_unique($t_select_clauses));
    $t_from = 'FROM ' . implode(', ', array_unique($t_from_clauses));
    $t_join = implode(' ', $t_join_clauses);
    if (count($t_where_clauses) > 0) {
        $t_where = 'WHERE ' . implode(' AND ', $t_where_clauses);
    } else {
        $t_where = '';
    }
    # Possibly do two passes. First time, grab the IDs of issues that match the filters. Second time, grab the IDs of issues that
    # have bugnotes that match the text search if necessary.
    $t_id_array = array();
    for ($i = 0; $i < 2; $i++) {
        $t_id_where = $t_where;
        $t_id_join = $t_join;
        if ($i == 0) {
            if (!is_blank($t_id_where) && !is_blank($t_textsearch_where_clause)) {
                $t_id_where = $t_id_where . ' AND ' . $t_textsearch_where_clause;
            }
        } else {
            if (!is_blank($t_textsearch_wherejoin_clause)) {
                $t_id_where = $t_id_where . ' AND ' . $t_textsearch_wherejoin_clause;
                $t_id_join = $t_id_join . " INNER JOIN {$t_bugnote_table} ON {$t_bugnote_table}.bug_id = {$t_bug_table}.id";
                $t_id_join = $t_id_join . " INNER JOIN {$t_bugnote_text_table} ON {$t_bugnote_text_table}.id = {$t_bugnote_table}.bugnote_text_id";
            }
        }
        $query = "SELECT DISTINCT {$t_bug_table}.id AS id\r\n\t\t\t\t\t\t{$t_from}\r\n\t\t\t\t\t\t{$t_id_join}\r\n\t\t\t\t\t\t{$t_id_where}";
        if ($i == 0 || !is_blank($t_textsearch_wherejoin_clause)) {
            $result = db_query($query);
            $row_count = db_num_rows($result);
            for ($j = 0; $j < $row_count; $j++) {
                $row = db_fetch_array($result);
                $t_id_array[] = db_prepare_int($row['id']);
            }
        }
    }
    $t_id_array = array_unique($t_id_array);
    # Get the total number of bugs that meet the criteria.
    $bug_count = count($t_id_array);
    $rows = array();
    if ($bug_count > 0) {
        $t_where = "WHERE {$t_bug_table}.id in (" . implode(", ", $t_id_array) . ")";
    } else {
        return $rows;
    }
    $t_from = 'FROM ' . $t_bug_table;
    # write the value back in case the caller wants to know
    $p_bug_count = $bug_count;
    if (null === $p_per_page) {
        $p_per_page = (int) $t_filter['per_page'];
    } else {
        if (-1 == $p_per_page) {
            $p_per_page = $bug_count;
        }
    }
    # Guard against silly values of $f_per_page.
    if (0 == $p_per_page) {
        $p_per_page = $bug_count;
        // 0 - means show all
    }
    $p_per_page = (int) abs($p_per_page);
    # Use $bug_count and $p_per_page to determine how many pages
    # to split this list up into.
    # For the sake of consistency have at least one page, even if it
    # is empty.
    $t_page_count = ceil($bug_count / $p_per_page);
    if ($t_page_count < 1) {
        $t_page_count = 1;
    }
    # write the value back in case the caller wants to know
    $p_page_count = $t_page_count;
    # Make sure $p_page_number isn't past the last page.
    if ($p_page_number > $t_page_count) {
        $p_page_number = $t_page_count;
    }
    # Make sure $p_page_number isn't before the first page
    if ($p_page_number < 1) {
        $p_page_number = 1;
    }
    # Now add the rest of the criteria i.e. sorting, limit.
    # if sort is blank then default the sort and direction.  This is to fix the
    # symptoms of #3953.  Note that even if the main problem is fixed, we may
    # have to keep this code for a while to handle filters saved with this blank field.
    if (is_blank($t_filter['sort'])) {
        $t_filter['sort'] = 'last_updated';
        $t_filter['dir'] = 'DESC';
    }
    $t_order_array = array();
    $t_sort_fields = split(',', $t_filter['sort']);
    $t_dir_fields = split(',', $t_filter['dir']);
    if ('on' == $t_filter['sticky_issues'] && NULL !== $p_show_sticky) {
        $t_order_array[] = "sticky DESC";
    }
    $t_join = '';
    for ($i = 0; $i < count($t_sort_fields); $i++) {
        $c_sort = db_prepare_string($t_sort_fields[$i]);
        if (!in_array($t_sort_fields[$i], array_slice($t_sort_fields, $i + 1))) {
            # if sorting by a custom field
            if (strpos($c_sort, 'custom_') === 0) {
                $t_custom_field = substr($c_sort, strlen('custom_'));
                $t_custom_field_id = custom_field_get_id_from_name($t_custom_field);
                $t_join .= " LEFT JOIN {$t_custom_field_string_table} ON ( ( {$t_custom_field_string_table}.bug_id = {$t_bug_table}.id ) AND ( {$t_custom_field_string_table}.field_id = {$t_custom_field_id} ) )";
                $c_sort = "{$t_custom_field_string_table}.value";
                $t_select_clauses[] = "{$t_custom_field_string_table}.value";
            }
            if ('DESC' == $t_dir_fields[$i]) {
                $c_dir = 'DESC';
            } else {
                $c_dir = 'ASC';
            }
            $t_order_array[] = "{$c_sort} {$c_dir}";
        }
    }
    # add basic sorting if necessary
    if (!in_array('last_updated', $t_sort_fields)) {
        $t_order_array[] = 'last_updated DESC';
    }
    if (!in_array('date_submitted', $t_sort_fields)) {
        $t_order_array[] = 'date_submitted DESC';
    }
    $t_order = " ORDER BY " . implode(', ', $t_order_array);
    $t_select = implode(', ', array_unique($t_select_clauses));
    $query2 = "SELECT DISTINCT {$t_select}\r\n\t\t\t\t\t{$t_from}\r\n\t\t\t\t\t{$t_join}\r\n\t\t\t\t\t{$t_where}\r\n\t\t\t\t\t{$t_order}";
    # Figure out the offset into the db query
    #
    # for example page number 1, per page 5:
    #     t_offset = 0
    # for example page number 2, per page 5:
    #     t_offset = 5
    $c_per_page = db_prepare_int($p_per_page);
    $c_page_number = db_prepare_int($p_page_number);
    $t_offset = ($c_page_number - 1) * $c_per_page;
    # perform query
    $result2 = db_query($query2, $c_per_page, $t_offset);
    $row_count = db_num_rows($result2);
    $t_id_array_lastmod = array();
    for ($i = 0; $i < $row_count; $i++) {
        $row = db_fetch_array($result2);
        $t_id_array_lastmod[] = db_prepare_int($row['id']);
        $row['date_submitted'] = db_unixtimestamp($row['date_submitted']);
        $row['last_updated'] = db_unixtimestamp($row['last_updated']);
        array_push($rows, $row);
    }
    $t_id_array_lastmod = array_unique($t_id_array_lastmod);
    // paulr: it should be impossible for t_id_array_lastmod to be array():
    // that would imply that $t_id_array is null which aborts this function early
    //if ( count( $t_id_array_lastmod ) > 0 ) {
    $t_where = "WHERE {$t_bugnote_table}.bug_id in (" . implode(", ", $t_id_array_lastmod) . ")";
    $query3 = "SELECT DISTINCT bug_id,MAX(last_modified) as last_modified, COUNT(last_modified) as count FROM {$t_bugnote_table} {$t_where} GROUP BY bug_id";
    # perform query
    $result3 = db_query($query3);
    $row_count = db_num_rows($result3);
    for ($i = 0; $i < $row_count; $i++) {
        $row = db_fetch_array($result3);
        $t_stats[$row['bug_id']] = $row;
    }
    foreach ($rows as $row) {
        if (!isset($t_stats[$row['id']])) {
            bug_cache_database_result($row, false);
        } else {
            bug_cache_database_result($row, $t_stats[$row['id']]);
        }
    }
    return $rows;
}
 } else {
     $t_restriction = '';
 }
 $t_bugnote_table = config_get('mantis_bugnote_table');
 $t_bugnote_text_table = config_get('mantis_bugnote_text_table');
 $t_bugnote_order = current_user_get_pref('bugnote_order');
 $query6 = "SELECT *\r\n\t\t\t\tFROM {$t_bugnote_table}\r\n\t\t\t\tWHERE bug_id='{$v_id}' {$t_restriction}\r\n\t\t\t\tORDER BY date_submitted {$t_bugnote_order}";
 $result6 = db_query($query6);
 $num_notes = db_num_rows($result6);
 # save the index, and use an own bugnote_index
 $bugnote_index = $name_index;
 for ($k = 0; $k < $num_notes; $k++) {
     # prefix all bugnote data with v3_
     $row = db_fetch_array($result6);
     extract($row, EXTR_PREFIX_ALL, 'v3');
     $v3_date_submitted = date(config_get('normal_date_format'), db_unixtimestamp($v3_date_submitted));
     # grab the bugnote text and id and prefix with v3_
     $query6 = "SELECT note, id\r\n\t\t\t\t\tFROM {$t_bugnote_text_table}\r\n\t\t\t\t\tWHERE id='{$v3_bugnote_text_id}'";
     $result7 = db_query($query6);
     $v3_note = db_result($result7, 0, 0);
     $v3_bugnote_text_id = db_result($result7, 0, 1);
     $t_note = '';
     switch ($v3_note_type) {
         case REMINDER:
             $t_note .= lang_get('reminder_sent_to') . ': ';
             $v3_note_attr = substr($v3_note_attr, 1, strlen($v3_note_attr) - 2);
             $t_to = array();
             foreach (explode('|', $v3_note_attr) as $t_recipient) {
                 $t_to[] = prepare_user_name($t_recipient);
             }
             $t_note .= implode(', ', $t_to) . '|';
Example #24
0
function history_get_raw_events_array($p_bug_id, $p_user_id = null)
{
    $t_mantis_bug_history_table = config_get('mantis_bug_history_table');
    $t_mantis_user_table = config_get('mantis_user_table');
    $t_history_order = config_get('history_order');
    $c_bug_id = db_prepare_int($p_bug_id);
    $t_user_id = null === $p_user_id ? auth_get_current_user_id() : $p_user_id;
    $t_roadmap_view_access_level = config_get('roadmap_view_threshold');
    # grab history and display by date_modified then field_name
    # @@@ by MASC I guess it's better by id then by field_name. When we have more history lines with the same
    # date, it's better to respect the storing order otherwise we should risk to mix different information
    # I give you an example. We create a child of a bug with different custom fields. In the history of the child
    # bug we will find the line related to the relationship mixed with the custom fields (the history is creted
    # for the new bug with the same timestamp...)
    $query = "SELECT *\n\t\t\t\tFROM {$t_mantis_bug_history_table}\n\t\t\t\tWHERE bug_id='{$c_bug_id}'\n\t\t\t\tORDER BY date_modified {$t_history_order},id";
    $result = db_query($query);
    $raw_history_count = db_num_rows($result);
    $raw_history = array();
    $t_private_bugnote_threshold = config_get('private_bugnote_threshold');
    $t_private_bugnote_visible = access_has_bug_level(config_get('private_bugnote_threshold'), $p_bug_id, $t_user_id);
    for ($i = 0, $j = 0; $i < $raw_history_count; ++$i) {
        $row = db_fetch_array($result);
        extract($row, EXTR_PREFIX_ALL, 'v');
        // check that the item should be visible to the user
        // custom fields - we are passing 32 here to notify the API that the custom field name is truncated by the history column from 64 to 32 characters.
        $t_field_id = custom_field_get_id_from_name($v_field_name, 32);
        if (false !== $t_field_id && !custom_field_has_read_access($t_field_id, $p_bug_id, $t_user_id)) {
            continue;
        }
        if ($v_field_name == 'target_version' && !access_has_bug_level($t_roadmap_view_access_level, $p_bug_id, $t_user_id)) {
            continue;
        }
        // bugnotes
        if ($t_user_id != $v_user_id) {
            // bypass if user originated note
            if ($v_type == BUGNOTE_ADDED || $v_type == BUGNOTE_UPDATED || $v_type == BUGNOTE_DELETED) {
                if (!$t_private_bugnote_visible && bugnote_get_field($v_old_value, 'view_state') == VS_PRIVATE) {
                    continue;
                }
            }
            if ($v_type == BUGNOTE_STATE_CHANGED) {
                if (!$t_private_bugnote_visible && bugnote_get_field($v_new_value, 'view_state') == VS_PRIVATE) {
                    continue;
                }
            }
        }
        // tags
        if ($v_type == TAG_ATTACHED || $v_type == TAG_DETACHED || $v_type == TAG_RENAMED) {
            if (!access_has_global_level(config_get('tag_view_threshold'))) {
                continue;
            }
        }
        $raw_history[$j]['date'] = db_unixtimestamp($v_date_modified);
        $raw_history[$j]['userid'] = $v_user_id;
        # user_get_name handles deleted users, and username vs realname
        $raw_history[$j]['username'] = user_get_name($v_user_id);
        $raw_history[$j]['field'] = $v_field_name;
        $raw_history[$j]['type'] = $v_type;
        $raw_history[$j]['old_value'] = $v_old_value;
        $raw_history[$j]['new_value'] = $v_new_value;
        $j++;
    }
    # end for loop
    return $raw_history;
}
	<td>
		<?php 
print_manage_user_sort_link('manage_user_page.php', lang_get('last_visit'), 'last_visit', $c_dir, $c_sort, $c_hide);
?>
		<?php 
print_sort_icon($c_dir, $c_sort, 'last_visit');
?>
	</td>
</tr>
<?php 
for ($i = 0; $i < $user_count; $i++) {
    # prefix user data with u_
    $row = db_fetch_array($result);
    extract($row, EXTR_PREFIX_ALL, 'u');
    $u_date_created = date(config_get('normal_date_format'), db_unixtimestamp($u_date_created));
    $u_last_visit = date(config_get('normal_date_format'), db_unixtimestamp($u_last_visit));
    ?>
<tr <?php 
    echo helper_alternate_class($i);
    ?>
>
	<td>
		<a href="manage_user_edit_page.php?user_id=<?php 
    echo $u_id;
    ?>
"><?php 
    echo string_display($u_username);
    ?>
</a>
	</td>
	<td><?php 
echo get_enum_element('severity', $v_severity);
?>
	</td>
	<td class="print">
		<?php 
echo get_enum_element('reproducibility', $v_reproducibility);
?>
	</td>
	<td class="print">
		<?php 
print_date(config_get('normal_date_format'), db_unixtimestamp($v_date_submitted));
?>
	</td>
	<td class="print">
		<?php 
print_date(config_get('normal_date_format'), db_unixtimestamp($v_last_updated));
?>
	</td>
</tr>
<tr>
	<td class="print-spacer" colspan="6">
		<hr size="1" />
	</td>
</tr>
<tr class="print">
	<td class="print-category">
		<?php 
echo lang_get('reporter');
?>
:
	</td>
Example #27
0
/**
 * Get the attachments that belong to the specified project.
 *
 * @param string $p_username  The name of the user trying to access the versions.
 * @param string $p_password  The password of the user.
 * @param integer $p_project_id  The id of the project to retrieve the attachments for.
 * @return Array  representing a ProjectAttachmentDataArray structure.
 */
function mc_project_get_attachments($p_username, $p_password, $p_project_id)
{
    $t_user_id = mci_check_login($p_username, $p_password);
    if ($t_user_id === false) {
        return new soap_fault('Client', '', 'Access Denied');
    }
    # Check if project documentation feature is enabled.
    if (OFF == config_get('enable_project_documentation') || !file_is_uploading_enabled()) {
        return new soap_fault('Client', '', 'Access Denied');
    }
    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 new soap_fault('Client', '', 'Access Denied');
    }
    $t_project_file_table = config_get('mantis_project_file_table');
    $t_project_table = config_get('mantis_project_table');
    $t_project_user_list_table = config_get('mantis_project_user_list_table');
    $t_user_table = config_get('mantis_user_table');
    $t_pub = VS_PUBLIC;
    $t_priv = VS_PRIVATE;
    $t_admin = ADMINISTRATOR;
    if ($p_project_id == ALL_PROJECTS) {
        # Select all the projects that the user has access to
        $t_projects = user_get_accessible_projects($t_user_id);
    } else {
        # Select the specific project
        $t_projects = array($p_project_id);
    }
    $t_projects[] = ALL_PROJECTS;
    # add ALL_PROJECTS to the list of projects to fetch
    $t_reqd_access = config_get('view_proj_doc_threshold');
    if (is_array($t_reqd_access)) {
        if (1 == count($t_reqd_access)) {
            $t_access_clause = "= " . array_shift($t_reqd_access) . " ";
        } else {
            $t_access_clause = "IN (" . implode(',', $t_reqd_access) . ")";
        }
    } else {
        $t_access_clause = ">= {$t_reqd_access} ";
    }
    $query = "SELECT pft.id, pft.project_id, pft.filename, pft.file_type, pft.filesize, pft.title, pft.description, pft.date_added\r\n\t\t\t\t\tFROM {$t_project_file_table} pft\r\n\t\t\t\t\t\tLEFT JOIN {$t_project_table} pt ON pft.project_id = pt.id\r\n\t\t\t\t\t\tLEFT JOIN {$t_project_user_list_table} pult \r\n\t\t\t\t\t\t\tON pft.project_id = pult.project_id AND pult.user_id = {$t_user_id}\r\n\t\t\t\t\t\tLEFT JOIN {$t_user_table} ut ON ut.id = {$t_user_id}\r\n\t\t\t\t\tWHERE pft.project_id in (" . implode(',', $t_projects) . ") AND\r\n\t\t\t\t\t\t( ( ( pt.view_state = {$t_pub} OR pt.view_state is null ) AND pult.user_id is null AND ut.access_level {$t_access_clause} ) OR\r\n\t\t\t\t\t\t\t( ( pult.user_id = {$t_user_id} ) AND ( pult.access_level {$t_access_clause} ) ) OR\r\n\t\t\t\t\t\t\t( ut.access_level = {$t_admin} ) )\r\n\t\t\t\t\tORDER BY pt.name ASC, pft.title ASC";
    $result = db_query($query);
    $num_files = db_num_rows($result);
    $t_result = array();
    for ($i = 0; $i < $num_files; $i++) {
        $row = db_fetch_array($result);
        extract($row, EXTR_PREFIX_ALL, 'v');
        $t_attachment = array();
        $t_attachment['id'] = $v_id;
        $t_attachment['filename'] = $v_filename;
        $t_attachment['title'] = $v_title;
        $t_attachment['description'] = $v_description;
        $t_attachment['size'] = $v_filesize;
        $t_attachment['content_type'] = $v_file_type;
        $t_attachment['date_submitted'] = timestamp_to_iso8601(db_unixtimestamp($v_date_added));
        $t_attachment['download_url'] = mci_get_mantis_path() . 'file_download.php?file_id=' . $v_id . '&amp;type=doc';
        $t_result[] = $t_attachment;
    }
    return $t_result;
}
/**
 * Migrate the legacy date format.
 * @param array $p_data Array: [0] = tablename, [1] id column, [2] = old column, [3] = new column.
 * @return integer
 */
function install_date_migrate(array $p_data)
{
    # $p_data[0] = tablename, [1] id column, [2] = old column, [3] = new column
    # Disable query logging even if enabled in config, due to possibility of mass spam
    $t_log_queries = install_set_log_queries();
    $t_table = $p_data[0];
    $t_id_column = $p_data[1];
    $t_date_array = is_array($p_data[2]);
    if ($t_date_array) {
        $t_old_column = implode(',', $p_data[2]);
        $t_cnt_fields = count($p_data[2]);
        $t_query = 'SELECT ' . $t_id_column . ', ' . $t_old_column . ' FROM ' . $t_table;
        $t_first_column = true;
        # In order to handle large databases where we may timeout during the upgrade, we don't
        # start from the beginning everytime.  Here we will only pickup rows where at least one
        # of the datetime fields wasn't upgraded yet and upgrade them all.
        foreach ($p_data[3] as $t_new_column_name) {
            if ($t_first_column) {
                $t_first_column = false;
                $t_query .= ' WHERE ';
            } else {
                $t_query .= ' OR ';
            }
            $t_query .= $t_new_column_name . ' = 1';
        }
    } else {
        $t_old_column = $p_data[2];
        # The check for timestamp being = 1 is to make sure the field wasn't upgraded
        # already in a previous run - see bug #12601 for more details.
        $t_new_column_name = $p_data[3];
        $t_query = 'SELECT ' . $t_id_column . ', ' . $t_old_column . ' FROM ' . $t_table . ' WHERE ' . $t_new_column_name . ' = 1';
    }
    $t_result = db_query($t_query);
    if (db_num_rows($t_result) > 0) {
        # Build the update query
        if ($t_date_array) {
            $t_pairs = array();
            foreach ($p_data[3] as $t_var) {
                array_push($t_pairs, $t_var . '=' . db_param());
            }
            $t_new_column = implode(',', $t_pairs);
        } else {
            $t_new_column = $p_data[3] . '=' . db_param();
        }
        $t_query = 'UPDATE ' . $t_table . ' SET ' . $t_new_column . ' WHERE ' . $t_id_column . '=' . db_param();
        while ($t_row = db_fetch_array($t_result)) {
            $t_id = (int) $t_row[$t_id_column];
            if ($t_date_array) {
                for ($i = 0; $i < $t_cnt_fields; $i++) {
                    $t_old_value = $t_row[$p_data[2][$i]];
                    if (is_numeric($t_old_value)) {
                        return 1;
                        # Fatal: conversion may have already been run. If it has been run, proceeding will wipe timestamps from db
                    }
                    $t_new_value[$i] = db_unixtimestamp($t_old_value);
                    if ($t_new_value[$i] < 100000) {
                        $t_new_value[$i] = 1;
                    }
                }
                $t_values = $t_new_value;
                $t_values[] = $t_id;
            } else {
                $t_old_value = $t_row[$t_old_column];
                if (is_numeric($t_old_value)) {
                    return 1;
                    # Fatal: conversion may have already been run. If it has been run, proceeding will wipe timestamps from db
                }
                $t_new_value = db_unixtimestamp($t_old_value);
                if ($t_new_value < 100000) {
                    $t_new_value = 1;
                }
                $t_values = array($t_new_value, $t_id);
            }
            db_query($t_query, $t_values);
        }
    }
    # Re-enable query logging if we disabled it
    install_set_log_queries($t_log_queries);
    # return 2 because that's what ADOdb/DataDict does when things happen properly
    return 2;
}
    } else {
        echo '<select ', helper_get_tab_index(), ' name="user_id">';
        print_user_option_list($t_tag_row['user_id'], ALL_PROJECTS, config_get('tag_create_threshold'));
        echo '</select>';
    }
} else {
    echo user_get_name($t_tag_row['user_id']);
}
?>
</td>
	<td><?php 
echo print_date(config_get('normal_date_format'), db_unixtimestamp($t_tag_row['date_created']));
?>
 </td>
	<td><?php 
echo print_date(config_get('normal_date_format'), db_unixtimestamp($t_tag_row['date_updated']));
?>
 </td>
</tr>

<!-- spacer -->
<tr class="spacer">
	<td colspan="5"></td>
</tr>

<!-- Description -->
<tr <?php 
echo helper_alternate_class();
?>
>
	<td class="category"><?php 
Example #30
0
function file_list_attachments($p_bug_id)
{
    $t_attachment_rows = bug_get_attachments($p_bug_id);
    $num_files = sizeof($t_attachment_rows);
    if ($num_files === 0) {
        return;
    }
    $t_can_download = file_can_download_bug_attachments($p_bug_id);
    $t_can_delete = file_can_delete_bug_attachments($p_bug_id);
    $image_previewed = false;
    for ($i = 0; $i < $num_files; $i++) {
        $row = $t_attachment_rows[$i];
        extract($row, EXTR_PREFIX_ALL, 'v');
        $t_file_display_name = file_get_display_name($v_filename);
        $t_filesize = number_format($v_filesize);
        $t_date_added = date(config_get('normal_date_format'), db_unixtimestamp($v_date_added));
        if ($image_previewed) {
            $image_previewed = false;
            print '<br />';
        }
        if ($t_can_download) {
            $t_href_start = "<a href=\"file_download.php?file_id={$v_id}&amp;type=bug\">";
            $t_href_end = '</a>';
            $t_href_clicket = " [<a href=\"file_download.php?file_id={$v_id}&amp;type=bug\" target=\"_blank\">^</a>]";
        } else {
            $t_href_start = '';
            $t_href_end = '';
            $t_href_clicket = '';
        }
        print $t_href_start;
        print_file_icon($t_file_display_name);
        print $t_href_end . '</a>&nbsp;' . $t_href_start . $t_file_display_name . $t_href_end . "{$t_href_clicket} ({$t_filesize} bytes) <span class=\"italic\">{$t_date_added}</span>";
        if ($t_can_delete) {
            print " [<a class=\"small\" href=\"bug_file_delete.php?file_id={$v_id}\">" . lang_get('delete_link') . '</a>]';
        }
        if (FTP == config_get('file_upload_method') && file_exists($v_diskfile)) {
            print ' (' . lang_get('cached') . ')';
        }
        if ($t_can_download && $v_filesize <= config_get('preview_attachments_inline_max_size') && $v_filesize != 0 && in_array(strtolower(file_get_extension($t_file_display_name)), array('png', 'jpg', 'jpeg', 'gif', 'bmp'), true)) {
            print "<br /><img src=\"file_download.php?file_id={$v_id}&amp;type=bug\" />";
            $image_previewed = true;
        }
        if ($i != $num_files - 1) {
            print '<br />';
        }
    }
}