示例#1
0
<?php

include "database_api.php";
function bug_get_attachments($p_bug_id)
{
    $c_bug_id = db_prepare_int($p_bug_id);
    $t_bug_file_table = db_get_table('mantis_bug_file_table');
    $query = "SELECT id, title, diskfile, filename, filesize, file_type, date_added, user_id\n                                FROM {$t_bug_file_table}\n                                WHERE bug_id=" . db_param() . "\n                                ORDER BY date_added";
    $db_result = db_query_bound($query, array($c_bug_id));
    $num_files = db_num_rows($db_result);
    $t_result = array();
    for ($i = 0; $i < $num_files; $i++) {
        $t_result[] = db_fetch_array($db_result);
    }
    return $t_result;
}
bug_get_attachments(55);
示例#2
0
         # last modified
         $writer->writeElement('last_modified', $t_bugnote->last_modified);
         # note type
         $writer->writeElement('note_type', $t_bugnote->note_type);
         # note attr
         $writer->writeElement('note_attr', $t_bugnote->note_attr);
         # time tracking
         $writer->writeElement('time_tracking', $t_bugnote->time_tracking);
         $writer->endElement();
         # bugnote
     }
     $writer->endElement();
     # bugnotes
 }
 # fetch and export attachments
 $t_attachments = bug_get_attachments($t_row->id);
 if (is_array($t_attachments) && count($t_attachments) > 0) {
     $writer->startElement('attachments');
     foreach ($t_attachments as $t_attachment) {
         $writer->startElement('attachment');
         # id
         $writer->writeElement('id', $t_attachment['id']);
         # title
         $writer->writeElement('title', $t_attachment['title']);
         # filename
         $writer->writeElement('filename', $t_attachment['filename']);
         # filesize
         $writer->writeElement('filesize', $t_attachment['filesize']);
         # file_type
         $writer->writeElement('file_type', $t_attachment['file_type']);
         # last added
示例#3
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);
    if ($t_attachment_rows == null) {
        return array();
    }
    $t_result = array();
    foreach ($t_attachment_rows as $t_attachment_row) {
        if (!file_can_view_bug_attachments($p_issue_id, (int) $t_attachment_row['user_id'])) {
            continue;
        }
        $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'] = SoapObjectsFactory::newDateTimeVar($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_attachment['user_id'] = $t_attachment_row['user_id'];
        $t_result[] = $t_attachment;
    }
    return $t_result;
}
示例#4
0
/**
 * Move any attachments as needed when a bug is moved from project to project.
 *
 * @param integer $p_bug_id        ID of bug containing attachments to be moved.
 * @param integer $p_project_id_to Destination project ID for the bug.
 * @return void
 *
 * @todo: this function can't cope with source or target storing attachments in DB
 */
function file_move_bug_attachments($p_bug_id, $p_project_id_to)
{
    $t_project_id_from = bug_get_field($p_bug_id, 'project_id');
    if ($t_project_id_from == $p_project_id_to) {
        return;
    }
    $t_method = config_get('file_upload_method');
    if ($t_method != DISK) {
        return;
    }
    if (!file_bug_has_attachments($p_bug_id)) {
        return;
    }
    $t_path_from = project_get_field($t_project_id_from, 'file_path');
    if (is_blank($t_path_from)) {
        $t_path_from = config_get('absolute_path_default_upload_folder', null, null, $t_project_id_from);
    }
    file_ensure_valid_upload_path($t_path_from);
    $t_path_to = project_get_field($p_project_id_to, 'file_path');
    if (is_blank($t_path_to)) {
        $t_path_to = config_get('absolute_path_default_upload_folder', null, null, $p_project_id_to);
    }
    file_ensure_valid_upload_path($t_path_to);
    if ($t_path_from == $t_path_to) {
        return;
    }
    # Initialize the update query to update a single row
    $c_bug_id = (int) $p_bug_id;
    $t_query_disk_attachment_update = 'UPDATE {bug_file}
	                                 SET folder=' . db_param() . '
	                                 WHERE bug_id=' . db_param() . '
	                                 AND id =' . db_param();
    $t_attachment_rows = bug_get_attachments($p_bug_id);
    $t_attachments_count = count($t_attachment_rows);
    for ($i = 0; $i < $t_attachments_count; $i++) {
        $t_row = $t_attachment_rows[$i];
        $t_basename = basename($t_row['diskfile']);
        $t_disk_file_name_from = file_path_combine($t_path_from, $t_basename);
        $t_disk_file_name_to = file_path_combine($t_path_to, $t_basename);
        if (!file_exists($t_disk_file_name_to)) {
            chmod($t_disk_file_name_from, 0775);
            if (!rename($t_disk_file_name_from, $t_disk_file_name_to)) {
                if (!copy($t_disk_file_name_from, $t_disk_file_name_to)) {
                    trigger_error(ERROR_FILE_MOVE_FAILED, ERROR);
                }
                file_delete_local($t_disk_file_name_from);
            }
            chmod($t_disk_file_name_to, config_get('attachments_file_permissions'));
            db_query($t_query_disk_attachment_update, array(db_prepare_string($t_path_to), $c_bug_id, (int) $t_row['id']));
        } else {
            trigger_error(ERROR_FILE_DUPLICATE, ERROR);
        }
    }
}
function file_get_visible_attachments($p_bug_id)
{
    $t_attachment_rows = bug_get_attachments($p_bug_id);
    $t_visible_attachments = array();
    $t_attachments_count = count($t_attachment_rows);
    if ($t_attachments_count === 0) {
        return $t_visible_attachments;
    }
    $t_attachments = array();
    $t_preview_text_ext = config_get('preview_text_extensions');
    $t_preview_image_ext = config_get('preview_image_extensions');
    $image_previewed = false;
    for ($i = 0; $i < $t_attachments_count; $i++) {
        $t_row = $t_attachment_rows[$i];
        if (!file_can_view_bug_attachments($p_bug_id, (int) $t_row['user_id'])) {
            continue;
        }
        $t_id = $t_row['id'];
        $t_filename = $t_row['filename'];
        $t_filesize = $t_row['filesize'];
        $t_diskfile = file_normalize_attachment_path($t_row['diskfile'], bug_get_field($p_bug_id, 'project_id'));
        $t_date_added = $t_row['date_added'];
        $t_attachment = array();
        $t_attachment['id'] = $t_id;
        $t_attachment['display_name'] = file_get_display_name($t_filename);
        $t_attachment['size'] = $t_filesize;
        $t_attachment['date_added'] = $t_date_added;
        $t_attachment['diskfile'] = $t_diskfile;
        $t_attachment['can_download'] = file_can_download_bug_attachments($p_bug_id, (int) $t_row['user_id']);
        $t_attachment['can_delete'] = file_can_delete_bug_attachments($p_bug_id, (int) $t_row['user_id']);
        if ($t_attachment['can_download']) {
            $t_attachment['download_url'] = "file_download.php?file_id={$t_id}&type=bug";
        }
        if ($image_previewed) {
            $image_previewed = false;
        }
        $t_attachment['exists'] = config_get('file_upload_method') != DISK || file_exists($t_diskfile);
        $t_attachment['icon'] = file_get_icon_url($t_attachment['display_name']);
        $t_attachment['preview'] = false;
        $t_attachment['type'] = '';
        $t_ext = strtolower(file_get_extension($t_attachment['display_name']));
        $t_attachment['alt'] = $t_ext;
        if ($t_attachment['exists'] && $t_attachment['can_download'] && $t_filesize != 0 && $t_filesize <= config_get('preview_attachments_inline_max_size')) {
            if (in_array($t_ext, $t_preview_text_ext, true)) {
                $t_attachment['preview'] = true;
                $t_attachment['type'] = 'text';
            } else {
                if (in_array($t_ext, $t_preview_image_ext, true)) {
                    $t_attachment['preview'] = true;
                    $t_attachment['type'] = 'image';
                }
            }
        }
        $t_attachments[] = $t_attachment;
    }
    return $t_attachments;
}
示例#6
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;
}
 /**
  * Gets and returns relevant data for a given bug and date
  *
  * @param $bug_id
  * @param $version_date
  * @return array
  */
 public function calculate_bug_data($bug_id, $version_date)
 {
     $specmanagement_database_api = new specmanagement_database_api();
     /** Initialize bug data array */
     $bug_data = array();
     /** ID */
     $bug_data[0] = $bug_id;
     /** Summary */
     $bug_data[1] = $this->get_bug_summary($bug_id, $version_date);
     /** Description */
     $bug_data[2] = $this->get_bug_description($bug_id, $version_date);
     /** Steps to reproduce */
     $bug_data[3] = $this->get_bug_stepstoreproduce($bug_id, $version_date);
     /** Additional information */
     $bug_data[4] = $this->get_bug_additionalinformation($bug_id, $version_date);
     /** Attached files */
     $bug_data[5] = bug_get_attachments($bug_id);
     /** Notes */
     $bug_data[6] = $specmanagement_database_api->calculate_last_bugnotes($bug_id, $version_date);
     /** planned duration for each bug */
     $bug_data[7] = $specmanagement_database_api->get_ptime_row($bug_id)[2];
     return $bug_data;
 }
示例#8
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 />';
        }
    }
}
示例#9
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);
    $t_preview_text_ext = config_get('preview_text_extensions');
    $t_preview_image_ext = config_get('preview_image_extensions');
    $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 = string_display_line(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 = '';
        }
        $t_exists = config_get('file_upload_method') != DISK || file_exists($v_diskfile);
        if (!$t_exists) {
            print_file_icon($t_file_display_name);
            print '&nbsp;<span class="strike">' . $t_file_display_name . '</span> (attachment missing)';
        } else {
            print $t_href_start;
            print_file_icon($t_file_display_name);
            print $t_href_end . '&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)), $t_preview_text_ext, true)) {
                $c_id = db_prepare_int($v_id);
                $t_bug_file_table = config_get('mantis_bug_file_table');
                echo "<script type=\"text/javascript\" language=\"JavaScript\">\r\n<!--\r\nfunction swap_content( span ) {\r\ndisplayType = ( document.getElementById( span ).style.display == 'none' ) ? '' : 'none';\r\ndocument.getElementById( span ).style.display = displayType;\r\n}\r\n\r\n -->\r\n </script>";
                print " <span id=\"hideSection_{$c_id}\">[<a class=\"small\" href='#' id='attmlink_" . $c_id . "' onclick='swap_content(\"hideSection_" . $c_id . "\");swap_content(\"showSection_" . $c_id . "\");return false;'>" . lang_get('show_content') . "</a>]</span>";
                print " <span style='display:none' id=\"showSection_{$c_id}\">[<a class=\"small\" href='#' id='attmlink_" . $c_id . "' onclick='swap_content(\"hideSection_" . $c_id . "\");swap_content(\"showSection_" . $c_id . "\");return false;'>" . lang_get('hide_content') . "</a>]";
                print "<pre>";
                switch (config_get('file_upload_method')) {
                    case DISK:
                        if (file_exists($v_diskfile)) {
                            $v_content = file_get_contents($v_diskfile);
                        }
                        break;
                    case FTP:
                        if (file_exists($v_diskfile)) {
                            file_get_contents($v_diskfile);
                        } else {
                            $ftp = file_ftp_connect();
                            file_ftp_get($ftp, $v_diskfile, $v_diskfile);
                            file_ftp_disconnect($ftp);
                            $v_content = file_get_contents($v_diskfile);
                        }
                        break;
                    default:
                        $query = "SELECT *\r\n\t                  \t\t\t\t\t\tFROM {$t_bug_file_table}\r\n\t\t\t\t            \t\t\tWHERE id='{$c_id}'";
                        $result = db_query($query);
                        $row = db_fetch_array($result);
                        $v_content = $row['content'];
                }
                echo htmlspecialchars($v_content);
                print "</pre></span>\n";
            }
            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)), $t_preview_image_ext, true)) {
                $t_preview_style = 'border: 0;';
                $t_max_width = config_get('preview_max_width');
                if ($t_max_width > 0) {
                    $t_preview_style .= ' max-width:' . $t_max_width . 'px;';
                }
                $t_max_height = config_get('preview_max_height');
                if ($t_max_height > 0) {
                    $t_preview_style .= ' max-height:' . $t_max_height . 'px;';
                }
                $t_preview_style = 'style="' . $t_preview_style . '"';
                $t_title = file_get_field($v_id, 'title');
                print "\n<br />{$t_href_start}<img alt=\"{$t_title}\" {$t_preview_style} src=\"file_download.php?file_id={$v_id}&amp;type=bug\" />{$t_href_end}";
                $image_previewed = true;
            }
        }
        if ($i != $num_files - 1) {
            print "<br />\n";
        }
    }
}