diff -Naur orig/admin/schema.php mantisbt/admin/schema.php
--- orig/admin/schema.php	2008-03-06 13:19:05.000000000 +0100
+++ mantisbt/admin/schema.php	2008-03-06 17:53:54.000000000 +0100
@@ -399,4 +399,8 @@
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_table' ), "inherit_global I UNSIGNED NOTNULL DEFAULT '0'" ) );
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_hierarchy_table' ), "inherit_parent I UNSIGNED NOTNULL DEFAULT '0'" ) );
 
+$upgrade[] = Array( 'AddColumnSQL', Array( db_get_Table( 'mantis_bug_file_table' ), "
+	user_id			I UNSIGNED NOTNULL DEFAULT '0',
+	patch			I NOTNULL DEFAULT \"'0'\",
+	obsolete		I NOTNULL DEFAULT \"'0'\" ") );
 ?>
diff -Naur orig/bug_file_add.php mantisbt/bug_file_add.php
--- orig/bug_file_add.php	2008-03-06 13:19:30.000000000 +0100
+++ mantisbt/bug_file_add.php	2008-03-06 17:41:39.000000000 +0100
@@ -34,6 +34,13 @@
 <?php
 	$f_bug_id	= gpc_get_int( 'bug_id', -1 );
 	$f_file		= gpc_get_file( 'file', -1 );
+	$f_action = gpc_get_int( 'action', -1 );
+	$f_field = gpc_get_string( 'field', '');
+	$f_file_id = gpc_get_int( 'file_id', -1 );
+	$f_description = gpc_get( 'description', '' );
+	$f_patch = gpc_get_int( 'patch', 0 );
+	$f_obsolete = gpc_get_int( 'obsolete', 0 );
+	
 
 	if ( $f_bug_id == -1 && $f_file	== -1 ) {
 		# _POST/_FILES does not seem to get populated if you exceed size limit so check if bug_id is -1
@@ -46,16 +53,19 @@
 
 	access_ensure_bug_level( config_get( 'upload_bug_file_threshold' ), $f_bug_id );
 
-	$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 ( $f_action == -1 || $f_file_id == -1 ) {
+		$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;
+		}
+	
+		$f_file_error =  ( isset( $f_file['error'] ) ) ? $f_file['error'] : 0;
+		file_add( $f_bug_id, $f_file['tmp_name'], $f_file['name'], $f_file['type'], 'bug', $f_file_error, '', $f_description, $f_patch, $f_obsolete );
+	} else {
+		file_mark( $f_file_id, $f_field, $f_action, $f_bug_id );
 	}
-
-    $f_file_error =  ( isset( $f_file['error'] ) ) ? $f_file['error'] : 0;
-	file_add( $f_bug_id, $f_file['tmp_name'], $f_file['name'], $f_file['type'], 'bug', $f_file_error );
-
 	# Determine which view page to redirect back to.
 	$t_redirect_url = string_get_bug_view_url( $f_bug_id );
 
diff -Naur orig/bug_file_upload_inc.php mantisbt/bug_file_upload_inc.php
--- orig/bug_file_upload_inc.php	2008-03-06 13:19:29.000000000 +0100
+++ mantisbt/bug_file_upload_inc.php	2008-03-06 18:19:58.000000000 +0100
@@ -49,6 +49,34 @@
 		echo lang_get( 'upload_file' ) ?>
 	</td>
 </tr>
+
+<!-- Attachments -->
+<?php
+	$t_show_attachments = ( $t_bug->reporter_id == auth_get_current_user_id() ) || access_has_bug_level( config_get( 'view_attachments_threshold' ), $f_bug_id );
+
+	if ( $t_show_attachments ) {
+?>
+<!--
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<a name="attachments" id="attachments" />
+		<?php echo lang_get( 'attached_files' ) ?>
+	</td>
+	<td colspan="2">
+		<?php print_bug_attachments_list( $f_bug_id ); ?>
+	</td>
+</tr>
+-->
+<tr>
+	<td colspan="2">
+		<?php print_bug_attachments_list( $f_bug_id ); ?>
+	</td>
+</tr>
+
+<?php
+	}
+?>
+
 <tr class="row-1">
 	<td class="category" width="15%">
 		<?php echo lang_get( 'select_file' ) ?><br />
@@ -61,6 +89,22 @@
 		<input type="submit" class="button" value="<?php echo lang_get( 'upload_file_button' ) ?>" />
 	</td>
 </tr>
+<tr class="row-2">
+	<td class="category" width="15%">
+		<?php echo lang_get( 'file_comment' ) ?>
+	</td>
+	<td with="85%">
+		<input type="text" name="description" size="80" />
+	</td>
+</tr>
+<tr class="row-1">
+	<td class="category"> 
+		<?php echo lang_get( 'file_remarks' ) ?>
+	</td>
+	<td with="85%">
+		<input type="checkbox" name="patch" value="1" ><?php echo lang_get( 'file_patch' ) ?></input>
+	</td>
+</tr>
 </table>
 </form>
 <?php
diff -Naur orig/bug_view_advanced_page.php mantisbt/bug_view_advanced_page.php
--- orig/bug_view_advanced_page.php	2008-03-06 13:19:30.000000000 +0100
+++ mantisbt/bug_view_advanced_page.php	2008-03-06 17:41:39.000000000 +0100
@@ -538,7 +538,7 @@
 <?php } # custom fields found ?>
 
 
-<!-- Attachments -->
+<!-- Attachments 
 <?php
 	$t_show_attachments = ( $t_bug->reporter_id == auth_get_current_user_id() ) || access_has_bug_level( config_get( 'view_attachments_threshold' ), $f_bug_id );
 
@@ -556,7 +556,7 @@
 <?php
 	}
 ?>
-
+-->
 <!-- Buttons -->
 <tr align="center">
 	<td align="center" colspan="6">
diff -Naur orig/bug_view_page.php mantisbt/bug_view_page.php
--- orig/bug_view_page.php	2008-03-06 13:19:30.000000000 +0100
+++ mantisbt/bug_view_page.php	2008-03-06 17:41:39.000000000 +0100
@@ -414,7 +414,7 @@
 <?php } # custom fields found ?>
 
 
-<!-- Attachments -->
+<!-- Attachments
 <?php
 	$t_show_attachments = ( $t_bug->reporter_id == auth_get_current_user_id() ) || access_has_bug_level( config_get( 'view_attachments_threshold' ), $f_bug_id );
 
@@ -432,7 +432,7 @@
 <?php
 	}
 ?>
-
+-->
 <!-- Buttons -->
 <tr align="center">
 	<td align="center" colspan="6">
diff -Naur orig/config_defaults_inc.php mantisbt/config_defaults_inc.php
--- orig/config_defaults_inc.php	2008-03-06 13:19:30.000000000 +0100
+++ mantisbt/config_defaults_inc.php	2008-03-06 20:14:49.000000000 +0100
@@ -877,6 +877,15 @@
 
 	# absolute path to the default upload folder.  Requires trailing / or \
 	$g_absolute_path_default_upload_folder = '';
+	
+	
+	# access level needed to mark file obsolete
+	# reporter can always mark file as an obsolete (aka request for remove)
+	$g_allow_mark_obsolete_threshold = DEVELOPER;
+	
+	# access level needed to mark file patch
+	# reporter can always mark file as a patch
+	$g_allow_mark_patch_threshold = DEVELOPER;
 
 	############################
 	# Mantis HTML Settings
diff -Naur orig/config_inc.php mantisbt/config_inc.php
--- orig/config_inc.php	1970-01-01 01:00:00.000000000 +0100
+++ mantisbt/config_inc.php	2008-03-06 19:57:36.000000000 +0100
@@ -0,0 +1,158 @@
+<?php
+    $g_hostname = 'localhost';
+    $g_db_type = 'postgres7';
+    $g_database_name = 'bugtracker3';
+    $g_db_username = 'mantis';
+    $g_db_password = 'mantis2006';
+    
+    $g_administrator_email = 'pszmigielski@systherm-info.pl';
+    $g_webmaster_email = 'pszmigielski@systherm-info.pl';
+    $g_from_email = 'mantis@systherm-info.pl';
+    $g_limit_email_doamin = 'systherm-info.pl';
+    //$g_return_path_email = 'mantis@[10.0.0.2]';
+    $g_return_path_email = 'mantis';
+    $g_smtp_host = 'systherm-info.pl';
+    $g_smtp_username = 'mantis';
+    $g_smtp_password = 'MantiS';
+    $g_phpMailer_method = 1;
+    $g_use_phpMailer = ON;
+
+    $g_default_langugae = 'polish_utf8';
+    
+    $g_window_title = 'Systherm-Info bug tracking system';
+    $g_show_footer_menu = true;
+    $g_show_realname = true;
+    $g_show_report = 'ADVANCED_ONLY';
+    $g_show_update = 'ADVANCED_ONLY';
+    $g_show_view = 'BOTH';
+    
+    $g_short_date_format = 'd-m-Y';
+    $g_normal_date_format = 'd-m-Y H:i';
+    $g_allow_file_upload = true;
+    $g_file_upload_method = DISK;
+    
+    $g_show_version = ON;
+    
+    $g_use_jpgraph = ON;
+    $g_jpgraph_path = '/usr/share/jpgraph/';
+    $g_graph_font = '/usr/share/fonts/truetype/antp/ANTPR.TTF';
+    $g_allow_signup = OFF;
+    
+    $g_default_bug_view_status = VS_PRIVATE;
+    $g_default_bugnote_view_status = VS_PRIVATE;
+    $g_default_reminder_view_status = VS_PRIVATE;
+    
+    $g_status_enum_string = '10:new,20:feedback,40:confirmed,50:assigned,60:processed,80:resolved,90:closed';    
+    $g_status_enum_workflow[NEW_]='20:feedback,40:confirmed,50:assigned,60:processed,80:resolved';
+    $g_status_enum_workflow[FEEDBACK] ='10:new,40:confirmed,50:assigned,60:processed,80:resolved';
+    #$g_status_enum_workflow[ACKNOWLEDGED] ='20:feedback,40:confirmed,50:assigned,60:processed,80:resolved';
+    $g_status_enum_workflow[CONFIRMED] ='20:feedback,50:assigned,60:processed,80:resolved';
+    $g_status_enum_workflow[ASSIGNED] ='20:feedback,60:processed,80:resolved,90:closed';
+    $g_status_enum_workflow[PROCESSED] ='20:feedback,80:resolved,90:closed';
+    $g_status_enum_workflow[RESOLVED] ='50:assigned,90:closed';
+    $g_status_enum_workflow[CLOSED] ='50:assigned';
+    $g_status_enum_workflow = array();
+
+    $g_status_colors = array('new' 		=> '#ffa0a0', # red,
+                             'feedback' 	=> '#ff50a8', # purple
+			     'acknowledged' 	=> '#ffd850', # orange
+			     'confirmed'    	=> '#ffffb0', # yellow
+			     'assigned'         => '#c8c8ff', # blue
+			     'processed'	=> '#c674fc', # magenta
+                             'resolved'         => '#cceedd', # buish-green
+                             'closed'           => '#e8e8e8'); # light gray
+																																																						          
+    
+    
+    
+							    
+    
+    $g_default_home_page = 'view_all_bug_page.php';
+    
+    $g_update_process_threshold = DEVELOPER;
+    $g_update_bug_process_threshold = DEVELOPER;
+    $g_bug_processed_status = PROCESSED;
+    
+    #$g_allow_anonymous_login = ON;
+    #$g_anonymous_account = '';
+    
+    #$g_login_method = LDAP;
+    #$g_ldap_server = 'ldap://127.0.0.1/';
+    #$g_ldap_root_dn = 'ou=Users,ou=accounts,dc=systherm-info,dc=pl';
+    #$g_ldap_organisation = '';
+    #$g_ldap_uid_field = 'uid';
+
+     $g_my_view_boxes = array (
+                'assigned'      => '1',
+                'unassigned'    => '2',
+                'reported'      => '3',
+                'resolved'      => '4',
+                'recent_mod'    => '5',
+                'monitored'     => '0',
+                'feedback'      => '0',
+                'verify'        => '0',
+		'opened'	=> '6',
+		'idea'		=> '0'
+        );
+
+#     $g_bug_resolved_status_threshold = config_get( 'bug_resolved_status_threshold' );
+     $my_view_title_opened = 'Otwarte';
+     $t_show_severity_status = Array ( '0' => 20, '1' => 30, '2' => 40, '3' => 50, '4' => 60, '5' => 70, '6' => 80 );
+     $c_filter['opened'] = array(
+                'show_category'         => Array ( '0' => META_FILTER_ANY ),
+#                'show_severity'         => Array ( '0' => META_FILTER_ANY ),
+                'show_severity'         => $t_show_severity_status,
+                'show_status'           => Array ( '0' => META_FILTER_ANY ),
+                'highlight_changed'     => Array ( '0' => META_FILTER_ANY ),
+                'reporter_id'           => Array ( '0' => META_FILTER_ANY ),
+                'handler_id'            => Array ( '0' => META_FILTER_ANY ),
+                'show_resolution'       => Array ( '0' => META_FILTER_ANY ),
+                'show_build'            => Array ( '0' => META_FILTER_ANY ),
+                'show_version'          => Array ( '0' => META_FILTER_ANY ),
+                'hide_status'           => Array ( '0' => $g_hide_status_default ),
+                'user_monitor'          => Array ( '0' => META_FILTER_ANY )
+        );
+    $url_link_parameters['opened'] = 'show_severity=' . $t_show_severity_status.'&amp;show_status='.$g_bug_resolved_status_threshold;
+
+
+     $c_filter['idea'] = array(
+                'show_category'         => Array ( '0' => META_FILTER_ANY ),
+                'show_severity'         => Array ( '0' => META_FILTER_ANY ),
+                'show_status'           => Array ( '0' => META_FILTER_ANY ),
+                'highlight_changed'     => Array ( '0' => META_FILTER_ANY ),
+                'reporter_id'           => Array ( '0' => META_FILTER_ANY ),
+                'handler_id'            => Array ( '0' => META_FILTER_ANY ),
+                'show_resolution'       => Array ( '0' => META_FILTER_ANY ),
+                'show_build'            => Array ( '0' => META_FILTER_ANY ),
+                'show_version'          => Array ( '0' => META_FILTER_ANY ),
+                'hide_status'           => Array ( '0' => $g_hide_status_default ),
+                'user_monitor'          => Array ( '0' => META_FILTER_ANY ),
+					'task'			=> Array ( '0' => META_FILTER_TASK)
+        );
+    $url_link_parameters['idea'] = 'show_severity=10&amp;hide_status='.$g_hide_status_default;
+
+    $g_default_bug_category = 'Ogólna';
+    
+    $g_view_task_page_columns = array ( 'selection', 'id', 'eta', 'deadline', 'status', 'last_updated', 'summary' );
+    	
+    
+    $g_eta_enum_string                 = '10:nieokrelona,11: 1 godzina,15: 2 godziny,19: 3 godziny,21: 4 godziny,24: 1 dzie,26: 2 dni,30: 3 dni,34: 4 dni,40: 1 tydzie,44: 10 dni,48: 2 tygodnie,52: 3 tygodnie,56: 1 miesic,60: 5 tygodni,54: 6 tygodni,58: 7 tygodni,72: 2 miesice,76: 9 tygodni,80: 10 tygodni,84: 3 miesice,88: 4 miesice,92: 5 miesicy,96: p roku';
+  	 $g_severity_enum_string				= '10:feature,20:trivial,30:text,40:tweak,50:minor,60:major,70:crash';  
+
+    $g_notify_flags['processed'] = array ( 'threshold_min' => ANYBODY,
+					    'threshold_max' => NOBODY );    
+					    
+    $g_show_avatar = ON;
+    
+    $g_preview_attachments_inline_max_size = 200000;
+    
+###########################
+# Include files
+###########################
+			
+# Specify your top/bottom include file (logos, banners, etc)
+# if a top file is supplied, the default Mantis logo at the top will be hidden
+    $g_top_include_page = '%absolute_path%/company_header.php';
+						    
+						        
+?>
\ No newline at end of file
diff -Naur orig/core/bug_api.php mantisbt/core/bug_api.php
--- orig/core/bug_api.php	2008-03-06 13:19:27.000000000 +0100
+++ mantisbt/core/bug_api.php	2008-03-06 17:41:39.000000000 +0100
@@ -662,7 +662,7 @@
 				}
 
 				$query = "INSERT INTO $t_mantis_bug_file_table
-						( bug_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content )
+						( bug_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content, patch, obsolete, user_id )
 						VALUES ( " . db_param(0) . ",
 								 " . db_param(1) . ",
 								 " . db_param(2) . ",
@@ -672,8 +672,11 @@
 								 " . db_param(6) . ",
 								 " . db_param(7) . ",
 								 " . db_param(8) . ",
-								 " . db_param(9) . ");";
-				db_query_bound( $query, Array( $t_new_bug_id, $t_bug_file['title'], $t_bug_file['description'], $t_new_diskfile_name, $t_new_file_name, $t_bug_file['folder'], $t_bug_file['filesize'], $t_bug_file['file_type'], $t_bug_file['date_added'], $t_bug_file['content'] ) );
+								 " . db_param(9) . ",
+								 " . db_param(10) . ",
+								 " . db_param(11) . ",
+								 " . db_param(12) . ");";
+				db_query_bound( $query, Array( $t_new_bug_id, $t_bug_file['title'], $t_bug_file['description'], $t_new_diskfile_name, $t_new_file_name, $t_bug_file['folder'], $t_bug_file['filesize'], $t_bug_file['file_type'], $t_bug_file['date_added'], $t_bug_file['content'], $t_bug_file['patch'], $t_bug_file['obsolete'], $t_bug_file['user_id'] ) );
 			}
 		}
 
@@ -1165,7 +1168,7 @@
 
 		$t_bug_file_table = db_get_table( 'mantis_bug_file_table' );
 
-		$query = "SELECT id, title, diskfile, filename, filesize, file_type, date_added
+		$query = "SELECT id, title, diskfile, filename, filesize, file_type, date_added, patch, obsolete, user_id, description
 		                FROM $t_bug_file_table
 		                WHERE bug_id=" . db_param(0) . "
 		                ORDER BY date_added";
diff -Naur orig/core/file_api.php mantisbt/core/file_api.php
--- orig/core/file_api.php	2008-03-06 13:19:27.000000000 +0100
+++ mantisbt/core/file_api.php	2008-03-06 18:12:03.000000000 +0100
@@ -129,15 +129,24 @@
 
 	# --------------------
 	# Check if the current user can delete attachments from the specified bug.
-	function file_can_delete_bug_attachments( $p_bug_id ) {
+	function file_can_delete_bug_attachments( $p_bug_id, $p_file_id = 0 ) {
 		if ( bug_is_readonly( $p_bug_id ) ) {
 			return false;
 		}
 
 		$t_reported_by_me	= bug_is_user_reporter( $p_bug_id, auth_get_current_user_id() );
 		$t_can_download		= access_has_bug_level( config_get( 'delete_attachments_threshold' ), $p_bug_id );
+		
+		if ( $p_file_id > 0 ) {
+			$t_owned_by_me		= file_is_user_owner( $p_file_id, auth_get_current_user_id() );
+		}
 # @@@ Fix this to be readable
-		$t_can_download		= $t_can_download || ( $t_reported_by_me && config_get( 'allow_delete_own_attachments' ) );
+		if ( $p_file_id > 0 ) {
+			$t_can_download		= $t_can_download || ( $t_owned_by_me && config_get( 'allow_delete_own_attachments' ) );
+		} else {
+			# left due to compatibility reasons. should be removed.
+			$t_can_download		= $t_can_download || ( $t_reported_by_me && config_get( 'allow_delete_own_attachments' ) );
+		}
 
 		return $t_can_download;
 	}
@@ -199,6 +208,7 @@
 			$t_attachment['date_added'] = db_unixtimestamp( $v_date_added );
 			$t_attachment['can_download'] = $t_can_download;
 			$t_attachment['diskfile'] = $v_diskfile;
+			$t_attachment['can_delete'] = file_can_delete_bug_attachments( $p_bug_id, $v_id );
 
 			if ( $t_can_download ) {
 				$t_attachment['download_url'] = "file_download.php?file_id=$v_id&amp;type=bug";
@@ -210,7 +220,6 @@
 
 			$t_attachment['exists'] = config_get( 'file_upload_method' ) != DISK || file_exists( $v_diskfile );
 			$t_attachment['icon'] = file_get_icon_url( $t_attachment['display_name'] );
-			$t_attachment['can_delete'] = $t_can_delete;
 
 			$t_attachment['preview'] = false;
 			$t_attachment['type'] = '';
@@ -302,8 +311,8 @@
 			# Delete files from disk
 			$query = "SELECT diskfile, filename
 					FROM $t_project_file_table
-					WHERE project_id=" . db_param(0);
-			$result = db_query_bound( $query, array( (int)$p_project_id ) );
+					WHERE project_id=$p_project_id";
+			$result = db_query( $query );
 
 			$file_count = db_num_rows( $result );
 
@@ -330,7 +339,7 @@
 		# Delete the corresponding db records
 		$query = "DELETE FROM $t_project_file_table
 				WHERE project_id=" . db_param(0);
-		$result = db_query_bound($query, Array( (int)$p_project_id ) );
+		$result = db_query_bound($query, Array( $p_project_id ) );
 	}
 	# --------------------
 	# Delete all cached files that are older than configured number of days.
@@ -382,14 +391,15 @@
 	# --------------------
 	# Return the specified field value
 	function file_get_field( $p_file_id, $p_field_name, $p_table = 'bug' ) {
+		$c_file_id			= db_prepare_int( $p_file_id );
 		$c_field_name		= db_prepare_string( $p_field_name );
 		$t_bug_file_table	= db_get_table( 'mantis_' . $p_table . '_file_table' );
 
 		# get info
 		$query = "SELECT $c_field_name
 				  FROM $t_bug_file_table
-				  WHERE id=" . db_param(0);
-		$result = db_query_bound( $query, Array( (int)$p_file_id ), 1 );
+				  WHERE id='$c_file_id'";
+		$result = db_query( $query, 1 );
 
 		return db_result( $result );
 	}
@@ -526,19 +536,22 @@
 	}
 
 	# --------------------
-	function file_add( $p_bug_id, $p_tmp_file, $p_file_name, $p_file_type='', $p_table = 'bug', $p_file_error = 0, $p_title = '', $p_desc = '' ) {
-	    switch ( (int) $p_file_error ) {
-	        case UPLOAD_ERR_INI_SIZE:
-	        case UPLOAD_ERR_FORM_SIZE:
-				trigger_error( ERROR_FILE_TOO_BIG, ERROR );
-				break;
-			case UPLOAD_ERR_PARTIAL:
-			case UPLOAD_ERR_NO_FILE:
-				trigger_error( ERROR_FILE_NO_UPLOAD_FAILURE, ERROR );
-				break;
-			default:
-			break;
-		}
+	function file_add( $p_bug_id, $p_tmp_file, $p_file_name, $p_file_type='', $p_table = 'bug', $p_file_error = 0, $p_title = '', $p_desc = '', $p_patch = 0, $p_obsolete = 0, $p_user_id = -1 ) {
+
+		if ( php_version_at_least( '4.2.0' ) ) {
+		    switch ( (int) $p_file_error ) {
+		        case UPLOAD_ERR_INI_SIZE:
+		        case UPLOAD_ERR_FORM_SIZE:
+                    trigger_error( ERROR_FILE_TOO_BIG, ERROR );
+                    break;
+		        case UPLOAD_ERR_PARTIAL:
+		        case UPLOAD_ERR_NO_FILE:
+                    trigger_error( ERROR_FILE_NO_UPLOAD_FAILURE, ERROR );
+                    break;
+                default:
+                    break;
+            }
+        }
 
 	    if ( ( '' == $p_tmp_file ) || ( '' == $p_file_name ) ) {
 		    trigger_error( ERROR_FILE_NO_UPLOAD_FAILURE, ERROR );
@@ -562,13 +575,21 @@
 			$t_project_id	= helper_get_current_project();
 			$t_bug_id		= 0;
 		}
-
+		
+		if ( $p_user_id == -1 )
+		{
+			$p_user_id = auth_get_current_user_id();
+		}
 		# prepare variables for insertion
 		$c_bug_id		= db_prepare_int( $p_bug_id );
 		$c_project_id		= db_prepare_int( $t_project_id );
 		$c_file_type	= db_prepare_string( $p_file_type );
 		$c_title = db_prepare_string( $p_title );
 		$c_desc = db_prepare_string( $p_desc );
+		$c_patch = db_prepare_int( $p_patch );
+		$c_obsolete = db_prepare_int( $p_obsolete );
+		$c_user_id = db_prepare_int( $p_user_id );
+		
 
 		if( $t_project_id == ALL_PROJECTS ) {
 			$t_file_path = config_get( 'absolute_path_default_upload_folder' );
@@ -630,13 +651,27 @@
 
 		$t_file_table	= db_get_table( 'mantis_' . $p_table . '_file_table' );
 		$c_id = ( 'bug' == $p_table ) ? $c_bug_id : $c_project_id;
-					
+		#'			
 		$query = "INSERT INTO $t_file_table
-						(" . $p_table . "_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content)
-					  VALUES
-						($c_id, '$c_title', '$c_desc', '$c_disk_file_name', '$c_new_file_name', '$c_file_path', $c_file_size, '$c_file_type', '" . db_now() ."', $c_content)";
-		db_query( $query );
-
+						(" . $p_table . "_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content, patch, obsolete, user_id)
+					  VALUES (". db_param(0) . ","
+						. db_param(1) . ","
+						. db_param(2) . ","
+						. db_param(3) . ","
+						. db_param(4) . ","
+						. db_param(5) . ","
+						. db_param(6) . ","
+						. db_param(7) . ","
+						. db_param(8) . ","
+						. db_param(9) . ","
+						. db_param(10) . ","
+						. db_param(11) . ","
+						. db_param(12) . ")";
+						
+		$t_params = Array ($c_id, $c_title, $c_desc, $c_disk_file_name, $c_new_file_name, 
+			$c_file_path, $c_file_size, $c_file_type,  db_now(), 
+			$c_content, $c_patch, $c_obsolete, $c_user_id);
+		db_query_bound( $query, $t_params );
 		if ( 'bug' == $p_table ) {
 			# updated the last_updated date
 			$result = bug_update_date( $p_bug_id );
@@ -748,4 +783,59 @@
 			return '';
 		}
 	}
+        # --------------------
+        # Check if the current user can mark attachment  as a patch.
+        function file_can_mark_patch( $p_bug_id, $p_file_id ) {
+                if ( bug_is_readonly( $p_bug_id ) ) {
+                        return false;
+                }
+
+                $t_submitted_by_me       = file_is_user_owner( $p_file_id, auth_get_current_user_id() );
+                $t_can_mark             = access_has_bug_level( config_get( 'allow_mark_patch_threshold' ), $p_bug_id );
+                $t_can_download         = $t_can_mark || $t_submitted_by_me;
+
+                return $t_can_download;
+        }
+
+        # --------------------
+        # Check if the current user can mark attachment as a obsolete.
+        function file_can_mark_obsolete( $p_bug_id, $p_file_id ) {
+                if ( bug_is_readonly( $p_bug_id ) ) {
+                        return false;
+                }
+
+                $t_submitted_by_me       = file_is_user_owner( $p_file_id, auth_get_current_user_id() );
+                $t_can_mark             = access_has_bug_level( config_get( 'allow_mark_obsolete_threshold' ), $p_bug_id );
+                $t_can_download         = $t_can_mark || $t_submitted_by_me;
+
+                return $t_can_download;
+        }
+
+        # --------------------
+        # Marks/unmarks file as a patch/obsolete
+        function file_mark( $p_file_id,  $p_field, $p_action, $p_bug_id ) {
+                if ( bug_is_readonly( $p_bug_id ) ) {
+                        return false;
+                }
+		$t_bug_file_table = db_get_table( 'mantis_bug_file_table' );
+		$query = "UPDATE $t_bug_file_table
+					SET $p_field = ".db_param(0)."
+					WHERE id = ".db_param(1);
+		$result = db_query_bound( $query, Array( $p_action, $p_file_id ) );
+        }
+
+		function file_is_user_owner( $p_file_id, $p_user_id ) {
+				if ( $p_user_id == file_get_field( $p_file_id, 'user_id' ) ) {
+					return true;
+				}
+                return false;		
+		}
+	# abandon files on user deletion
+	function file_user_abandon( $p_user_id ) {
+		$t_bug_file_table = db_get_table( 'mantis_bug_file_table' );
+		$query = "UPDATE $t_bug_file_table
+				SET user_id = 0
+				WHERE id = ".db_param(0);
+		$result = db_query_bound( $query, Array( $p_user_id ) );
+	}
 ?>
diff -Naur orig/core/print_api.php mantisbt/core/print_api.php
--- orig/core/print_api.php	2008-03-06 13:19:27.000000000 +0100
+++ mantisbt/core/print_api.php	2008-03-06 20:17:42.000000000 +0100
@@ -1750,18 +1750,32 @@
 		}
 
 		$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;
+	?>
+		<table width="100%">
+		  <tr class="row-category">
+		    <td><?php print lang_get( 'attachments'); ?></td>
+		    <td><?php print lang_get( 'file_type'); ?></td>
+		    <td><?php print lang_get( 'file_created'); ?></td>
+		    <td><?php print lang_get( 'file_size'); ?></td>
+		    <td><?php print lang_get( 'file_action'); ?></td>
+		</tr>
+	<?php	$image_previewed = false;
 		for ( $i = 0 ; $i < $num_files ; $i++ ) {
+			$t_current_background = helper_alternate_class();
+			print "<tr ".$t_current_background.">";
 			$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 ) );
+			$t_description = string_display_line ( $v_description );
+			$t_can_mark_delete = file_can_mark_obsolete( $p_bug_id, $v_id );
+			$t_can_mark_patch = file_can_mark_patch( $p_bug_id, $v_id );
+			$t_can_delete   = file_can_delete_bug_attachments( $p_bug_id, $v_id );
+			
 
 			if ( $image_previewed ) {
 				$image_previewed = false;
@@ -1783,22 +1797,64 @@
 			$t_exists = config_get( 'file_upload_method' ) != DISK || file_exists( $v_diskfile );
 
 			if ( !$t_exists ) {
+				print "<td>";
 				print_file_icon ( $t_file_display_name );
-				PRINT '&nbsp;<span class="strike">' . $t_file_display_name . '</span> (attachment missing)';
+				PRINT '&nbsp;<span class="strike">' . $t_file_display_name . '</span> (attachment missing)';				
+				print "</td>";
 			} else {
+				print "<td>";
+				if ( $v_patch )
+				    print "<B>P</B>";
 				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>";
-
+				PRINT $t_href_end . '&nbsp;';
+				if ( $v_obsolete ) {
+				    if ( $t_can_delete || $t_can_mark_delete) {
+		    			PRINT $t_href_start . "<span class=\"strike\">" . $t_file_display_name . "</span>" . $t_href_end . $t_href_clicket;
+				    } else {
+					PRINT "<span class=\"strike\">".$t_file_display_name."</span>";
+				    }
+				} else {
+				    PRINT $t_href_start .  $t_file_display_name . $t_href_end . $t_href_clicket;
+				}
+				print "</td>";
+				print "<td>";
+				if ( $t_can_mark_patch && !$v_patch ) {
+				    print " [<a class=\"small\" href=\"bug_file_add.php?field=patch&file_id=$v_id&action=1&bug_id=$p_bug_id\">" . lang_get( 'file_patch' ) .'</a>]';
+				} else if ( $t_can_mark_patch && $v_patch ) {
+				    print " [<a class=\"small\" href=\"bug_file_add.php?field=patch&file_id=$v_id&action=0&bug_id=$p_bug_id\">" . lang_get( 'file_unpatch' ) .'</a>]';
+				} else if ( !$t_can_mark_patch && $v_patch ) {
+				    print lang_get( 'file_is_patch' );
+				} else {
+				    print $v_file_type;
+				}
+				print "</td>";
+				print "<td>".$t_date_added."</td>";
+				print "<td>".$t_filesize." bytes</td>";
+				
+				
+				print "<td>";
+				# if can change patch status
+				# if can set to delete
 				if ( $t_can_delete ) {
 					PRINT " [<a class=\"small\" href=\"bug_file_delete.php?file_id=$v_id\">" . lang_get('delete_link') . '</a>]';
 				}
+				if ( $t_can_mark_delete && !$v_obsolete ) {
+					PRINT " [<a class=\"small\" href=\"bug_file_add.php?field=obsolete&file_id=$v_id&action=1&bug_id=$p_bug_id\">" . lang_get( 'file_obsolete' ) . '</a>]';
+				}
+				if ( $t_can_mark_delete && $v_obsolete ) {
+					PRINT " [<a class=\"small\" href=\"bug_file_add.php?field=obsolete&file_id=$v_id&action=0&bug_id=$p_bug_id\">" . lang_get( 'file_unobsolete' ) . '</a>]';
+				}				
 
 				if ( ( FTP == config_get( 'file_upload_method' ) ) && file_exists ( $v_diskfile ) ) {
 					PRINT ' (' . lang_get( 'cached' ) . ')';
 				}
-
+				print "</td>";
+				print "</tr>";
+				if ( strlen( $v_description ) > 0 ) {
+					print "<tr ".$t_current_background."><td colspan=\"5\">";
+					print $v_description . "</td></tr>";
+				}
 				if ( $t_can_download &&
 					( $v_filesize <= config_get( 'preview_attachments_inline_max_size' ) ) &&
 					( $v_filesize != 0 ) &&
@@ -1818,6 +1874,7 @@
 					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 "<tr ".$t_current_background."><td colspan=\"5\">";
 					PRINT "<pre>";
 					switch ( config_get( 'file_upload_method' ) ) {
 						case DISK:
@@ -1846,6 +1903,7 @@
 					echo htmlspecialchars($v_content);
 
 					PRINT "</pre></span>\n";
+					print "</td></tr>";
 				}
 
 
@@ -1854,6 +1912,7 @@
 					( $v_filesize != 0 ) &&
 					( in_array( strtolower( file_get_extension( $t_file_display_name ) ), $t_preview_image_ext, true ) ) ) {
 
+					print "<tr ".$t_current_background."><td colspan=\"5\">";
 					$t_preview_style = 'border: 0;';
 					$t_max_width = config_get( 'preview_max_width' );
 					if ( $t_max_width > 0 ) {
@@ -1870,12 +1929,11 @@
 
 					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;
+					print "</td></tr>";
 				}
 			}
 
-			if ( $i != ( $num_files - 1 ) ) {
-				PRINT "<br />\n";
-			}
 		}
+		print "</table>";
 	}
 ?>
diff -Naur orig/core/user_api.php mantisbt/core/user_api.php
--- orig/core/user_api.php	2008-03-06 13:19:27.000000000 +0100
+++ mantisbt/core/user_api.php	2008-03-06 17:41:39.000000000 +0100
@@ -25,6 +25,7 @@
 
 	require_once( $t_core_dir . 'email_api.php' );
 	require_once( $t_core_dir . 'ldap_api.php' );
+	require_once( $t_core_dir . 'file_api.php' );
 
 	### User API ###
 
@@ -580,6 +581,9 @@
 		}
 
 		user_clear_cache( $p_user_id );
+		
+		# abandon user file
+		file_user_abandon( $p_user_id );
 
 		# Remove account
 		$query = "DELETE FROM $t_user_table
diff -Naur orig/lang/strings_english.txt mantisbt/lang/strings_english.txt
--- orig/lang/strings_english.txt	2008-03-06 13:18:59.000000000 +0100
+++ mantisbt/lang/strings_english.txt	2008-03-06 20:09:15.000000000 +0100
@@ -1501,4 +1501,18 @@
 $s_update_columns_for_current_project = 'Update Columns For Current Project';
 $s_update_columns_as_my_default = 'Update Columns as Default for All Projects';
 $s_reset_columns_configuration = 'Reset Columns Configuration';
+
+# print_api.php
+$s_file_comment = 'File description';
+$s_file_remarks = 'Remarks';
+$s_file_patch = 'Mark patch';
+$s_file_unpatch = 'Unmark patch';
+$s_file_obsolete = 'Obsolete';
+$s_file_unobsolete = 'Not obsolete';
+$s_file_type = 'Type';
+$s_file_created = 'Created';
+$s_file_size = 'Size';
+$s_file_status = 'Status';
+$s_file_action = 'Action';
+$s_file_is_patch = 'patch';
 ?>
diff -Naur orig/lang/strings_polish.txt mantisbt/lang/strings_polish.txt
--- orig/lang/strings_polish.txt	2008-03-06 13:18:59.000000000 +0100
+++ mantisbt/lang/strings_polish.txt	2008-03-06 20:10:22.000000000 +0100
@@ -942,6 +942,20 @@
 # news_view_page.php
 $s_back_link = 'Powrt';
 
+# print_api.php
+$s_file_comment = 'Opis pliku';
+$s_file_remarks = 'Uwagi';
+$s_file_patch = 'Patch';
+$s_file_unpatch = 'Nie patch';
+$s_file_obsolete = 'Do usunicia';
+$s_file_unobsolete = 'Do pozostawienia';
+$s_file_type = 'Typ';
+$s_file_created = 'Utworzony';
+$s_file_size = 'Rozmiar';
+$s_file_status = 'Status';
+$s_file_action = 'Akcja';
+$s_file_is_patch = 'patch';
+
 # proj_doc_add.php
 $s_file_uploaded_msg = 'Plik zosta pomylnie przesany';
 
@@ -1335,5 +1349,4 @@
 
 # wiki related strings
 $s_wiki = 'Wiki';
-
 ?>
diff -Naur orig/lang/strings_polish_8859-2.txt mantisbt/lang/strings_polish_8859-2.txt
--- orig/lang/strings_polish_8859-2.txt	2008-03-06 13:18:58.000000000 +0100
+++ mantisbt/lang/strings_polish_8859-2.txt	2008-03-06 17:41:39.000000000 +0100
@@ -942,6 +942,15 @@
 # news_view_page.php
 $s_back_link = 'Powrt';
 
+# print_api.php
+$s_file_comment = 'Opis pliku';
+$s_file_remarks = 'Uwagi';
+$s_file_patch = 'Patch';
+$s_file_unpatch = 'Nie patch';
+$s_file_obsolete = 'Do usunicia';
+$s_file_unobsolete = 'Do pozostawienia';
+
+
 # proj_doc_add.php
 $s_file_uploaded_msg = 'Plik zosta pomylnie przesany';
 
@@ -1335,5 +1344,4 @@
 
 # wiki related strings
 $s_wiki = 'Wiki';
-
 ?>
