/** * Print column content for column attachment count * * @param BugData $p_bug bug object * @param int $p_columns_target see COLUMNS_TARGET_* in constant_inc.php * @return null * @access public */ function print_column_attachment_count($p_bug, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE) { global $t_icon_path; # Check for attachments $t_attachment_count = 0; if (file_can_view_bug_attachments($p_bug->id, null)) { $t_attachment_count = file_bug_attachment_count($p_bug->id); } echo '<td class="column-attachments">'; if ($t_attachment_count > 0) { $t_href = string_get_bug_view_url($p_bug->id) . '#attachments'; $t_href_title = sprintf(lang_get('view_attachments_for_issue'), $t_attachment_count, $p_bug->id); echo "<a href=\"{$t_href}\" title=\"{$t_href_title}\">{$t_attachment_count}</a>"; } else { echo '   '; } echo "</td>\n"; }
/** * Gets an array of attachments that are visible to the currently logged in user. * Each element of the array contains the following: * display_name - The attachment display name (i.e. file name dot extension) * size - The attachment size in bytes. * date_added - The date where the attachment was added. * can_download - true: logged in user has access to download the attachment, false: otherwise. * diskfile - The name of the file on disk. Typically this is a hash without an extension. * download_url - The download URL for the attachment (only set if can_download is true). * exists - Applicable for DISK attachments. true: file exists, otherwise false. * can_delete - The logged in user can delete the attachments. * preview - true: the attachment should be previewable, otherwise false. * type - Can be "image", "text" or empty for other types. * alt - The alternate text to be associated with the icon. * icon - array with icon information, contains 'url' and 'alt' elements. * @param integer $p_bug_id A bug identifier. * @return array */ 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'); $t_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 ($t_image_previewed) { $t_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(pathinfo($t_attachment['display_name'], PATHINFO_EXTENSION)); $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; }
function print_column_attachment($p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE) { global $t_icon_path; $t_show_attachments = config_get('show_attachment_indicator'); # Check for attachments $t_attachment_count = 0; if (ON == $t_show_attachments && file_can_view_bug_attachments($p_row['id'])) { $t_attachment_count = file_bug_attachment_count($p_row['id']); } if (ON == $t_show_attachments) { echo "\t<td>"; if (0 < $t_attachment_count) { echo '<a href="' . string_get_bug_view_url($p_row['id']) . '#attachments">'; echo '<img border="0" src="' . $t_icon_path . 'attachment.png' . '"'; echo ' alt="' . lang_get('attachment_alt') . '"'; echo ' title="' . $t_attachment_count . ' ' . lang_get('attachments') . '"'; echo ' />'; echo '</a>'; } else { echo ' '; } echo "</td>\n"; } }
<?php mark_time('begin loop'); # -- Loop over bug rows and create $v_* variables -- for ($i = 0; $i < sizeof($rows); $i++) { # prefix bug data with v_ extract($rows[$i], EXTR_PREFIX_ALL, 'v'); $t_summary = string_attribute($v_summary); $t_last_updated = date(config_get('normal_date_format'), $v_last_updated); # choose color based on status $status_color = get_status_color($v_status); # grab the bugnote count # @@@ thraxisp - not used??? # $bugnote_info = bug_get_bugnote_stats( $v_id ); # Check for attachments $t_attachment_count = 0; if (file_can_view_bug_attachments($v_id)) { $t_attachment_count = file_bug_attachment_count($v_id); } # grab the project name $project_name = project_get_field($v_project_id, 'name'); ?> <tr bgcolor="<?php echo $status_color; ?> "> <?php # -- Bug ID and details link + Pencil shortcut -- ?> <td class="center" valign="top" width ="0" nowrap> <span class="small">
/** * 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'] . '&type=bug'; $t_attachment['user_id'] = $t_attachment_row['user_id']; $t_result[] = $t_attachment; } return $t_result; }
# -- Loop over bug rows and create $v_* variables -- $t_count = count($rows); if ($t_count == 0) { echo '<tr><td> </td></tr>'; } for ($i = 0; $i < $t_count; $i++) { $t_bug = $rows[$i]; $t_summary = string_display_line_links($t_bug->summary); $t_last_updated = date(config_get('normal_date_format'), $t_bug->last_updated); # choose color based on status $status_label = html_get_status_css_class($t_bug->status, auth_get_current_user_id(), $t_bug->project_id); # Check for attachments $t_attachment_count = 0; # TODO: factor in the allow_view_own_attachments configuration option # instead of just using a global check. if (file_can_view_bug_attachments($t_bug->id, null)) { $t_attachment_count = file_bug_attachment_count($t_bug->id); } # grab the project name $project_name = project_get_field($t_bug->project_id, 'name'); if (VS_PRIVATE == $t_bug->view_state) { $t_bug_class = 'my-buglist-private'; } else { $t_bug_class = ''; } ?> <tr class="my-buglist-bug <?php echo $t_bug_class; ?> <?php
/** * * @param BugData $p_bug bug obect * @param int $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php * @return null * @access public */ function print_column_attachment_count( $p_bug, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) { global $t_icon_path; # Check for attachments # TODO: factor in the allow_view_own_attachments configuration option # instead of just using a global check. $t_attachment_count = 0; if( file_can_view_bug_attachments( $p_bug->id, null ) ) { $t_attachment_count = file_bug_attachment_count( $p_bug->id ); } echo '<td class="center column-attachments">'; if ( $t_attachment_count > 0 ) { $t_href = string_get_bug_view_url( $p_bug->id ) . '#attachments'; $t_href_title = sprintf( lang_get( 'view_attachments_for_issue' ), $t_attachment_count, $p_bug->id ); if ( config_get( 'show_attachment_indicator' ) ) { $t_alt_text = $t_attachment_count . lang_get( 'word_separator' ) . lang_get( 'attachments' ); echo "<a href=\"$t_href\" title=\"$t_href_title\"><img src=\"${t_icon_path}attachment.png\" alt=\"$t_alt_text\" title=\"$t_alt_text\" /></a>"; } else { echo "<a href=\"$t_href\" title=\"$t_href_title\">$t_attachment_count</a>"; } } else { echo '   '; } echo "</td>\n"; }
/** * * @param BugData $p_bug bug obect * @param int $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php * @return null * @access public */ function print_column_attachment_count($p_bug, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE) { global $t_icon_path; # Check for attachments $t_attachment_count = 0; if (file_can_view_bug_attachments($p_bug->id)) { $t_attachment_count = file_bug_attachment_count($p_bug->id); } echo '<td class="center column-attachments">'; if ($t_attachment_count > 0) { $t_href = string_get_bug_view_url($p_bug->id) . '#attachments'; $t_href_title = sprintf(lang_get('view_attachments_for_issue'), $t_attachment_count, $p_bug->id); if (config_get('show_attachment_indicator')) { $t_alt_text = $t_attachment_count . lang_get('word_separator') . lang_get('attachments'); echo "<a href=\"{$t_href}\" title=\"{$t_href_title}\"><img src=\"{$t_icon_path}attachment.png\" alt=\"{$t_alt_text}\" title=\"{$t_alt_text}\" /></a>"; } else { echo "<a href=\"{$t_href}\" title=\"{$t_href_title}\">{$t_attachment_count}</a>"; } } else { echo ' '; } echo "</td>\n"; }
/** * return the attachment count for an issue * @param BugData $p_bug A BugData object. * @return string * @access public */ function csv_format_attachment_count(BugData $p_bug) { # Check for attachments $t_attachment_count = 0; if (file_can_view_bug_attachments($p_bug->id, null)) { $t_attachment_count = file_bug_attachment_count($p_bug->id); } return csv_escape_string($t_attachment_count); }
/** * Get array of attachments associated with the specified bug id. The array will be * sorted in terms of date added (ASC). The array will include the following fields: * id, title, diskfile, filename, filesize, file_type, date_added. * @param int p_bug_id integer representing bug id * @return array array of results or null * @access public * @uses database_api.php * @uses file_api.php */ function bug_get_attachments($p_bug_id) { if (!file_can_view_bug_attachments($p_bug_id)) { return; } $c_bug_id = db_prepare_int($p_bug_id); $t_bug_file_table = db_get_table('bug_file'); $query = "SELECT id, title, diskfile, filename, filesize, file_type, date_added\n\t\t FROM {$t_bug_file_table}\n\t\t WHERE bug_id=" . db_param() . "\n\t\t 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; }
/** * Gets the attachment count for an issue * @param BugData $p_bug A bug object. * @return string * @access public */ function excel_format_attachment_count(BugData $p_bug) { # Check for attachments $t_attachment_count = 0; if (file_can_view_bug_attachments($p_bug->id, null)) { $t_attachment_count = file_bug_attachment_count($p_bug->id); } return excel_prepare_number($t_attachment_count); }
function bug_get_attachments($p_bug_id) { if (!file_can_view_bug_attachments($p_bug_id)) { return; } $c_bug_id = db_prepare_int($p_bug_id); $t_bug_file_table = config_get('mantis_bug_file_table'); $query = "SELECT id, title, diskfile, filename, filesize, file_type, date_added\r\n\t\t FROM {$t_bug_file_table}\r\n\t\t WHERE bug_id='{$c_bug_id}'\r\n\t\t ORDER BY date_added"; $db_result = db_query($query); $num_notes = db_num_rows($db_result); $t_result = array(); for ($i = 0; $i < $num_notes; $i++) { $t_result[] = db_fetch_array($db_result); } return $t_result; }