/**
 * Add an attachment to an existing issue.
 *
 * @param string $p_username  The name of the user trying to add an attachment to an issue.
 * @param string $p_password  The password of the user.
 * @param integer $p_issue_id  The id of the issue to add the attachment to.
 * @param string $p_name  The name of the file.
 * @param string $p_file_type The mime type of the file.
 * @param base64Binary $p_content  The attachment to add.
 * @return integer The id of the added attachment.
 */
function mc_issue_attachment_add( $p_username, $p_password, $p_issue_id, $p_name, $p_file_type, $p_content ) {
	$t_user_id = mci_check_login( $p_username, $p_password );
	if( $t_user_id === false ) {
		return mci_soap_fault_login_failed();
	}
	if( !file_allow_bug_upload( $p_issue_id, $t_user_id ) ) {
		return mci_soap_fault_access_denied( $t_user_id );
	}
	if( !access_has_bug_level( config_get( 'upload_bug_file_threshold' ), $p_issue_id, $t_user_id ) ) {
		return mci_soap_fault_access_denied( $t_user_id );
	}
	return mci_file_add( $p_issue_id, $p_name, $p_content, $p_file_type, 'bug', '', '', $t_user_id );
}
$t_show_priority = in_array('priority', $t_fields);
$t_show_steps_to_reproduce = in_array('steps_to_reproduce', $t_fields);
$t_show_handler = in_array('handler', $t_fields) && access_has_project_level(config_get('update_bug_assign_threshold'));
$t_show_profiles = config_get('enable_profiles');
$t_show_platform = $t_show_profiles && in_array('platform', $t_fields);
$t_show_os = $t_show_profiles && in_array('os', $t_fields);
$t_show_os_version = $t_show_profiles && in_array('os_version', $t_fields);
$t_show_resolution = in_array('resolution', $t_fields);
$t_show_status = in_array('status', $t_fields);
$t_show_versions = version_should_show_product_version($t_project_id);
$t_show_product_version = $t_show_versions && in_array('product_version', $t_fields);
$t_show_product_build = $t_show_versions && in_array('product_build', $t_fields) && config_get('enable_product_build') == ON;
$t_show_target_version = $t_show_versions && in_array('target_version', $t_fields) && access_has_project_level(config_get('roadmap_update_threshold'));
$t_show_additional_info = in_array('additional_info', $t_fields);
$t_show_due_date = in_array('due_date', $t_fields) && access_has_project_level(config_get('due_date_update_threshold'), helper_get_current_project(), auth_get_current_user_id());
$t_show_attachments = in_array('attachments', $t_fields) && file_allow_bug_upload();
$t_show_view_state = in_array('view_state', $t_fields) && access_has_project_level(config_get('set_view_status_threshold'));
if ($t_show_due_date) {
    require_js('jscalendar/calendar.js');
    require_js('jscalendar/lang/calendar-en.js');
    require_js('jscalendar/calendar-setup.js');
    require_css('calendar-blue.css');
}
# don't index bug report page
html_robots_noindex();
html_page_top(lang_get('report_bug_link'));
print_recently_visited();
$t_form_encoding = '';
if ($t_show_attachments) {
    $t_form_encoding = 'enctype="multipart/form-data"';
}
<?php 
if ($t_custom_fields_found) {
    ?>
<!-- spacer -->
<tr class="spacer">
	<td colspan="2"></td>
</tr>
<?php 
}
?>


<!-- File Upload (if enabled) -->
<?php 
if (file_allow_bug_upload()) {
    $t_max_file_size = (int) min(ini_get_number('upload_max_filesize'), ini_get_number('post_max_size'), config_get('max_file_size'));
    ?>
<tr <?php 
    echo helper_alternate_class();
    ?>
>
	<td class="category">
		<?php 
    echo lang_get('upload_file');
    ?>
		<?php 
    echo '<span class="small">(' . lang_get('max_file_size') . ': ' . number_format($t_max_file_size / 1000) . 'k)</span>';
    ?>
	</td>
	<td>
    return $t_result;
}
$f_bug_id = gpc_get_int('bug_id', -1);
$f_files = gpc_get_fileCustom('ufile', -1);
if ($f_bug_id == -1 && $f_files == -1) {
    # _POST/_FILES does not seem to get populated if you exceed size limit so check if bug_id is -1
    trigger_error(ERROR_FILE_TOO_BIG, ERROR);
}
form_security_validate('bug_file_add');
$t_bug = bug_get($f_bug_id, true);
if ($t_bug->project_id != helper_get_current_project()) {
    # in case the current project is not the same project of the bug we are viewing...
    # ... override the current project. This to avoid problems with categories and handlers lists etc.
    $g_project_override = $t_bug->project_id;
}
if (!file_allow_bug_upload($f_bug_id)) {
    access_denied();
}
access_ensure_bug_level(config_get('upload_bug_file_threshold'), $f_bug_id);
// Process array of files to upload
for ($i = 0; $i < count($f_files); $i++) {
    if (!empty($f_files[$i]['name'])) {
        $t_file['name'] = $f_files[$i]['name'];
        $t_file['tmp_name'] = $f_files[$i]['tmp_name'];
        $t_file['type'] = $f_files[$i]['type'];
        $t_file['error'] = $f_files[$i]['error'];
        $t_file['size'] = $f_files[$i]['size'];
        file_add($f_bug_id, $t_file, 'bug');
    }
}
form_security_purge('bug_file_add');
$t_columns = helper_get_columns_to_view( COLUMNS_TARGET_CSV_PAGE, /* $p_viewable_only */ false, $t_user_id );
$t_csv = implode( ', ', $t_columns );

$t_columns = helper_get_columns_to_view( COLUMNS_TARGET_VIEW_PAGE, /* $p_viewable_only */ false, $t_user_id );
$t_view_issues = implode( ', ', $t_columns );

$t_columns = helper_get_columns_to_view( COLUMNS_TARGET_PRINT_PAGE, /* $p_viewable_only */ false, $t_user_id );
$t_print_issues = implode( ', ', $t_columns );

$t_columns = helper_get_columns_to_view( COLUMNS_TARGET_EXCEL_PAGE, /* $p_viewable_only */ false, $t_user_id );
$t_excel = implode( ', ', $t_columns );
?>

<div id="manage-columns-div" class="form-container">
	<form id="manage-columns-form" method="post" <?php if ( file_allow_bug_upload() ) { echo 'enctype="multipart/form-data"'; } ?> action="manage_config_columns_set.php">
		<fieldset class="has-required">
			<legend><span><?php echo lang_get( 'manage_columns_config' ) ?></span></legend>
			<?php
			if ( $t_account_page ) {
				print_account_menu( 'account_manage_columns_page.php' );
			}
			?>
			<?php echo form_security_field( 'manage_config_columns_set' ) ?>
			<input type="hidden" name="project_id" value="<?php echo $t_project_id ?>" />
			<input type="hidden" name="form_page" value="<?php echo $t_account_page ? 'account' : 'manage'; ?>" />

			<div class="field-container <?php echo helper_alternate_class_no_attribute(); ?>">
				<label for="all-columns"><span><?php echo lang_get( 'all_columns_title' )?></span></label>
				<span class="textarea"><textarea id="all-columns" <?php echo helper_get_tab_index() ?> name="all_columns" readonly="readonly" cols="80" rows="5"><?php echo $t_all ?></textarea></span>
				<span class="label-style"></span>