View Issue Details

IDProjectCategoryView StatusLast Update
0008942mantisbttime trackingpublic2012-08-08 15:30
Reportersmig1o Assigned Toatrol  
PrioritynormalSeveritytweakReproducibilityalways
Status closedResolutionfixed 
Fixed in Version1.2.0 
Summary0008942: due date feature
Description

I have implemented stage 1 onf due date feature (according to http://www.mantisbt.org/wiki/doku.php/mantisbt:due_date_requirements)
Patch made agains ver 1.2 (5086)

There is an icon that MUST be replaced with something more >mantisable<.

This time I've double checked the patch

Tagspatch
Attached Files
duedate_final1.zip (7,603 bytes)
duedate_stage1_final2.diff (28,076 bytes)   
diff -Naur orig/admin/schema.php mantisbt/admin/schema.php
--- orig/admin/schema.php	2008-03-31 14:05:21.000000000 +0200
+++ mantisbt/admin/schema.php	2008-03-31 15:27:04.000000000 +0200
@@ -383,6 +383,8 @@
 $upgrade[] = Array( 'InsertData', Array( db_get_table( 'mantis_category_table' ), "
 	( project_id, user_id, name, status ) VALUES
 	( '0', '0', 'General', '0' ) " ) );
+
+
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "category_id I UNSIGNED NOTNULL DEFAULT '1'" ) );
 $upgrade[] = Array( 'UpdateFunction', "category_migrate" );
 $upgrade[] = Array( 'DropColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "category" ) );
@@ -405,3 +407,5 @@
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_version_table' ), "
 	obsolete		L		NOTNULL DEFAULT \" '0' \"" ) );
 
+$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "
+	due_date 		T 		NOTNULL DEFAULT '1970-01-01 00:00:01' " ) );
diff -Naur orig/bug_change_status_page.php mantisbt/bug_change_status_page.php
--- orig/bug_change_status_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_change_status_page.php	2008-03-31 15:39:29.000000000 +0200
@@ -52,7 +52,7 @@
 			) ) {
 		access_denied();
 	}
-
+	$t_can_set_due_date = access_has_bug_level( config_get( 'due_date_set_threshold' ), $f_bug_id );
 	# get new issue handler if set, otherwise default to original handler
 	$f_handler_id = gpc_get_int( 'handler_id', bug_get_field( $f_bug_id, 'handler_id' ) );
 
@@ -161,6 +161,32 @@
 </tr>
 <?php } ?>
 
+<!-- Due date -->
+<?php if ( $t_can_set_due_date ) { 
+# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			echo "<style type=\"text/css\">@import url(javascript/jscalendar/calendar-blue.css);</style>";
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/lang/calendar-en.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar-setup.js\"></script>\n"; 	
+		}
+	$t_icon_path = config_get( 'icon_path' );
+	$cal_icon = $t_icon_path ."calendar-img.gif";
+?>
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?> <?php print_documentation_link( 'due_date' ) ?>
+	</td>
+	<td>
+	<?php
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".date( config_get( 'short_date_format' ), $t_bug->due_date)."\">";
+	?>
+	    <input type="image" class="button" id="trigger" SRC="
+	    <?php print $cal_icon;?> " onClick="return showCalendar ('sel1', '%Y-%m-%d', 24, true)" />
+	</td>
+</tr>
+<?php } ?>
+
 <!-- Custom Fields -->
 <?php
 # @@@ thraxisp - I undid part of the change for #5068 for #5527
@@ -320,6 +346,23 @@
 </form>
 </div>
 
+<?php
+if ( $t_can_set_due_date ) { 
+	$t_format = config_get( 'short_date_format' );
+	$t_new_format = str_replace( '-', '-%', $t_format );
+	$t_format = "%".$t_new_format;
+
+?>
+	<script type="text/javascript">
+		Calendar.setup (
+		{
+		 inputField 	: "due_date",
+		 ifFormat 	: "<?php print $t_format?>",
+		 button		: "trigger"
+		}
+		);
+	</script>
+<?php } ?>
 <br />
 <?php
 	include( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'bug_view_inc.php' );
diff -Naur orig/bug_report.php mantisbt/bug_report.php
--- orig/bug_report.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_report.php	2008-03-31 16:02:24.000000000 +0200
@@ -54,6 +54,10 @@
 	$t_bug_data->description			= gpc_get_string( 'description' );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
+	$t_bug_data->due_date 				= gpc_get_string( 'due_date', '');
+	if ( is_blank ( $t_bug_data->due_date ) ) {
+		$t_bug_data->due_date = date_get_null();
+	}
 
 	$f_file					= gpc_get_file( 'file', null ); #@@@ (thraxisp) Note that this always returns a structure
 															# size = 0, if no file
@@ -188,6 +192,7 @@
 		<input type="hidden" name="build" 		value="<?php echo $t_bug_data->build ?>" />
 		<input type="hidden" name="report_stay" 	value="1" />
 		<input type="hidden" name="view_state"		value="<?php echo $t_bug_data->view_state ?>" />
+		<input type="hidden" name="due_date"		value="<?php echo $t_bug_data->due_date ?>" />
 		<input type="submit" class="button" 		value="<?php echo lang_get( 'report_more_bugs' ) ?>" />
 	</form>
 	</p>
diff -Naur orig/bug_report_advanced_page.php mantisbt/bug_report_advanced_page.php
--- orig/bug_report_advanced_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_report_advanced_page.php	2008-03-31 15:10:51.000000000 +0200
@@ -44,6 +44,8 @@
 		print_header_redirect ( 'bug_report_page.php' .
 						( 0 == $f_master_bug_id ) ? '' : '?m_id=' . $f_master_bug_id );
 	}
+	
+	$t_can_set_due_date = access_has_bug_level( config_get( 'due_date_set_threshold' ), $f_master_bug_id );
 
 	if( $f_master_bug_id > 0 ) {
 		# master bug exists...
@@ -114,6 +116,7 @@
 		$f_steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 		$f_additional_info		= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
 		$f_view_state			= gpc_get_int( 'view_state', config_get( 'default_bug_view_status' ) );
+		$f_due_date				=gpc_get_string( 'due_date', '');
 
 		$t_project_id			= helper_get_current_project();
 
@@ -209,6 +212,31 @@
 </tr>
 <?php } ?>
 
+<!-- Due date -->
+<?php if ( $t_can_set_due_date ) { 
+# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			echo "<style type=\"text/css\">@import url(javascript/jscalendar/calendar-blue.css);</style>";
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/lang/calendar-en.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar-setup.js\"></script>\n"; 	
+		}
+	$t_icon_path = config_get( 'icon_path' );
+	$cal_icon = $t_icon_path ."calendar-img.gif";
+?>
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?> <?php print_documentation_link( 'due_date' ) ?>
+	</td>
+	<td>
+	<?php
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".print_date( config_get( 'short_date_format' ), $t_bug->due_date)."\">";
+	?>
+	    <input type="image" class="button" id="trigger" SRC="
+	    <?php print $cal_icon;?> " onClick="return showCalendar ('sel1', '%Y-%m-%d', 24, true)" />
+	</td>
+</tr>
+<?php } ?>
 
 <!-- spacer -->
 <tr class="spacer">
@@ -554,6 +582,22 @@
 	window.document.report_bug_form.category_id.focus();
 -->
 </script>
+<?php  }
+if ( $t_can_set_due_date ) { 
+	$t_format = config_get( 'short_date_format' );
+	$t_new_format = str_replace( '-', '-%', $t_format );
+	$t_format = "%".$t_new_format;
+
+?>
+	<script type="text/javascript">
+		Calendar.setup (
+		{
+		 inputField 	: "due_date",
+		 ifFormat 	: "<?php print $t_format?>",
+		 button		: "trigger"
+		}
+		);
+	</script>
 <?php } ?>
 
 <?php html_page_bottom1( __FILE__ ) ?>
diff -Naur orig/bug_update.php mantisbt/bug_update.php
--- orig/bug_update.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update.php	2008-03-31 16:03:04.000000000 +0200
@@ -77,7 +77,11 @@
 	$t_bug_data->target_version		= gpc_get_string( 'target_version', $t_bug_data->target_version );
 	$t_bug_data->view_state			= gpc_get_int( 'view_state', $t_bug_data->view_state );
 	$t_bug_data->summary			= gpc_get_string( 'summary', $t_bug_data->summary );
-
+	$t_bug_data->due_date 				= gpc_get_string( 'due_date', $t_bug_data->due_date);
+	if ( is_blank ( $t_bug_data->due_date ) ) {
+		$t_bug_data->due_date = date_get_null( );
+	}
+	
 	$t_bug_data->description		= gpc_get_string( 'description', $t_bug_data->description );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', $t_bug_data->steps_to_reproduce );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_information', $t_bug_data->additional_information );
diff -Naur orig/bug_update_advanced_page.php mantisbt/bug_update_advanced_page.php
--- orig/bug_update_advanced_page.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update_advanced_page.php	2008-03-31 15:55:30.000000000 +0200
@@ -35,7 +35,7 @@
 	$f_bug_id = gpc_get_int( 'bug_id' );
 
 	$t_bug = bug_prepare_edit( 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.
@@ -48,13 +48,13 @@
 	if ( SIMPLE_ONLY == config_get( 'show_update' ) ) {
 		print_header_redirect ( 'bug_update_page.php?bug_id=' . $f_bug_id );
 	}
-
+	
 	if ( bug_is_readonly( $f_bug_id ) ) {
 		error_parameters( $f_bug_id );
 		trigger_error( ERROR_BUG_READ_ONLY_ACTION_DENIED, ERROR );
 	}
 
-	access_ensure_bug_level( config_get( 'update_bug_threshold' ), $f_bug_id );
+	$t_can_set_due_date = access_has_bug_level( config_get( 'due_date_set_threshold' ), $f_bug_id );
 
 	html_page_top1( bug_format_summary( $f_bug_id, SUMMARY_CAPTION ) );
 	html_page_top2();
@@ -189,8 +189,44 @@
 ?>
 	</td>
 
-	<!-- spacer -->
-	<td colspan="2">&nbsp;</td>
+<?php if ( access_has_bug_level( config_get( 'due_date_see_threshold' ), $f_bug_id ) ) { ?>
+	<!-- Due Date -->
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?>
+	</td>
+	<?php 
+	if ( bug_is_overdue( $f_bug_id ) ) {
+		print "<td class=\"overdue\">";
+	} else {
+		print "<td>";
+	}
+	if ( $t_can_set_due_date ) {
+# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			echo "<style type=\"text/css\">@import url(javascript/jscalendar/calendar-blue.css);</style>";
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/lang/calendar-en.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar-setup.js\"></script>\n"; 	
+		}
+	$t_icon_path = config_get( 'icon_path' );
+	$cal_icon = $t_icon_path ."calendar-img.gif";
+	$t_date_to_display = '';
+	if ( ! date_is_null( $t_bug->due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
+		}
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+	?>
+	    <input type="image" class="button" id="trigger" SRC="
+	    <?php print $cal_icon;?> " onClick="return showCalendar ('sel1', '%Y-%m-%d', 24, true)" />
+	</td>
+	<?php } else {
+		if ( $t_bug->due_date != $t_null_date  ) print_date( config_get( 'short_date_format' ), $t_bug->due_date  ); }?>
+	</td>
+<?php } else { ?>
+		<!-- spacer -->
+		<td colspan="2">&nbsp;</td>
+<?php } ?>
+
 </tr>
 
 
@@ -595,6 +631,25 @@
 </form>
 
 <?php
+if ( $t_can_set_due_date ) { 
+	$t_format = config_get( 'short_date_format' );
+	$t_new_format = str_replace( '-', '-%', $t_format );
+	$t_format = "%".$t_new_format;
+
+?>
+	<script type="text/javascript">
+		Calendar.setup (
+		{
+		 inputField 	: "due_date",
+		 ifFormat 	: "<?php print $t_format?>",
+		 button		: "trigger"
+		}
+		);
+	</script>
+<?php }?>
+
+
+<?php
 	include( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'bugnote_view_inc.php' );
 	html_page_bottom1( __FILE__ );
 
diff -Naur orig/bug_update_page.php mantisbt/bug_update_page.php
--- orig/bug_update_page.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update_page.php	2008-03-31 14:06:38.000000000 +0200
@@ -280,6 +280,9 @@
 </tr>
 
 <?php
+	} else {
+		# spacer
+		echo '<td colspan="2">&nbsp;</td>';	
 	}
 ?>
 <?php /*
diff -Naur orig/bug_view_advanced_page.php mantisbt/bug_view_advanced_page.php
--- orig/bug_view_advanced_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_view_advanced_page.php	2008-03-31 15:52:27.000000000 +0200
@@ -217,8 +217,29 @@
 		<?php echo get_enum_element( 'project_view_state', $t_bug->view_state ) ?>
 	</td>
 
-	<!-- spacer -->
-	<td colspan="2">&nbsp;</td>
+	<!-- Due Date -->
+	<?php if ( access_has_bug_level( config_get( 'due_date_see_threshold' ), $f_bug_id ) ) { ?>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?>
+	</td>
+	<?php
+	if ( bug_is_overdue( $f_bug_id ) ) {
+		print "<td class=\"overdue\">";
+	} else {
+		print "<td>";
+	}
+	?>
+		<?php 
+			if ( !date_is_null( $t_bug->due_date ) ) {
+				print_date( config_get( 'short_date_format' ), $t_bug->due_date ); }
+			?>
+	</td>
+	<?php } else { ?>
+		<!-- spacer -->
+		<td colspan="2">&nbsp;</td>
+	<?php
+	}
+	?>
 
 </tr>
 
diff -Naur orig/config_defaults_inc.php mantisbt/config_defaults_inc.php
--- orig/config_defaults_inc.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/config_defaults_inc.php	2008-03-31 15:51:33.000000000 +0200
@@ -1995,4 +1995,14 @@
 	# Enables or disables the mind mapping features including ability to export Freemind files and 
 	# in browser view of generated mindmaps.
 	$g_mindmap_enabled = ON;
-?>
\ No newline at end of file
+
+	#############################
+	# Due Date 
+	#############################
+
+	# threshold to set due date_submitted
+	$g_due_date_set_threshold = REPORTER;
+	
+	$g_due_date_see_threshold = MANAGER;
+
+?>
diff -Naur orig/core/bug_api.php mantisbt/core/bug_api.php
--- orig/core/bug_api.php	2008-03-31 13:45:23.000000000 +0200
+++ mantisbt/core/bug_api.php	2008-03-31 15:46:39.000000000 +0200
@@ -79,6 +79,9 @@
 		
 		#internal helper objects
 		var $_stats = null;
+		
+		#due date
+		var $due_date = '';
 	}
 
 	#===================================
@@ -105,6 +108,8 @@
 			$p_bug_database_result['date_submitted']	= db_unixtimestamp( $p_bug_database_result['date_submitted']['date_submitted'] );
 		if( !is_int( $p_bug_database_result['last_updated'] ) )
 			$p_bug_database_result['last_updated']	= db_unixtimestamp( $p_bug_database_result['last_updated'] );
+		if( !is_int( $p_bug_datebase_result['due_date'] ) ) 
+			$p_bug_datebase_result['due_date']	= db_unixtimestamp( $p_bug_datebase_result['due_date'] );
 		$g_cache_bug[ $p_bug_database_result['id'] ] = $p_bug_database_result;
 		if( !is_null( $p_stats ) ) {
 			$g_cache_bug[ $p_bug_database_result['id'] ]['_stats'] = $p_stats;
@@ -145,6 +150,8 @@
 		$row = db_fetch_array( $result );
 		$row['date_submitted']	= db_unixtimestamp( $row['date_submitted'] );
 		$row['last_updated']	= db_unixtimestamp( $row['last_updated'] );
+		$row['due_date']	= db_unixtimestamp( $row['due_date'] );
+		
 		$g_cache_bug[$c_bug_id] = $row;
 
 		return $row;
@@ -335,6 +342,23 @@
 	}
 
 	# --------------------
+	# Check if the bug is overdue
+	function bug_is_overdue( $p_bug_id ) {
+		$t_bug_row = bug_cache_row( $p_bug_id );
+		$t_due_date = $t_bug_row[ 'due_date' ];
+		if (  ! date_is_null( $t_due_date)  ) {
+			$t_now = db_unixtimestamp();
+			if ( $t_now > $t_due_date ) {
+				if ( $t_bug_row[ 'status' ] < config_get( 'bug_resolved_status_threshold' ) ) {
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+
+
+	# --------------------
 	# Validate workflow state to see if bug can be moved to requested state
 	function bug_check_workflow( $p_bug_status, $p_wanted_status ) {
 		$t_status_enum_workflow = config_get( 'status_enum_workflow' );
@@ -393,6 +417,8 @@
 		$c_additional_info		= $p_bug_data->additional_information;
 		$c_sponsorship_total 	= 0;
 		$c_sticky 				= 0;
+		$c_due_date				= $p_bug_data->due_date;
+		
 
 		# Summary cannot be blank
 		if ( is_blank( $c_summary ) ) {
@@ -419,6 +445,14 @@
 			$c_target_version	= '';
 		}
 
+		#check due_date format
+		if ( is_blank( $c_due_date ) ) {
+			$c_due_date = date_get_null();
+		}
+		
+		$t_format = strtotime( $c_due_date);
+		$c_due_date = date ( 'Y-m-d', $t_format );
+
 		$t_bug_table				= db_get_table( 'mantis_bug_table' );
 		$t_bug_text_table			= db_get_table( 'mantis_bug_text_table' );
 		$t_category_table			= db_get_table( 'mantis_category_table' );
@@ -474,7 +508,7 @@
 				      platform, version,
 				      build,
 				      profile_id, summary, view_state, sponsorship_total, sticky, fixed_in_version,
-				      target_version 
+				      target_version, due_date 
 				    )
 				  VALUES
 				    ( " . db_param(0) . ",
@@ -503,10 +537,11 @@
 				      " . db_param(23) . ",
 				      " . db_param(24) . ",
 				      " . db_param(25) . ",
-				      " . db_param(26) . ")";
+				      " . db_param(26) . ",
+				      " . db_param(27) . ")";
 		db_query_bound( $query, Array( $c_project_id, $c_reporter_id, $c_handler_id, 0, $c_priority, $c_severity, $c_reproducibility, $t_status,
 								 $t_resolution, 10, $c_category_id, db_now(), db_now(), 10, $t_text_id, $c_os, $c_os_build, $c_platform, $c_version,$c_build,
-								 $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version ) );
+								 $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version, $c_due_date) );
 
 		$t_bug_id = db_insert_id($t_bug_table);
 
@@ -569,6 +604,7 @@
 		bug_set_field( $t_new_bug_id, 'target_version', $t_bug_data->target_version );
 		bug_set_field( $t_new_bug_id, 'sponsorship_total', 0 );
 		bug_set_field( $t_new_bug_id, 'sticky', 0 );
+		bug_set_field( $t_new_bug_id, 'due_date', $t_bug_data->due_date );
 
 		# COPY CUSTOM FIELDS
 		if ( $p_copy_custom_fields ) {
@@ -898,6 +934,11 @@
 		$t_fields[] = $c_bug_id;
 		
 		db_query_bound( $query, $t_fields );
+		if ( !is_blank( $c_bug_data->due_date ) ) {
+			$t_format = strtotime( $c_bug_data->due_date);
+			$c_bug_data->due_date = date ( 'Y-m-d', $t_format );
+			bug_set_field( $c_bug_id, 'due_date', $c_bug_data->due_date);
+		}
 
 		bug_clear_cache( $p_bug_id );
 
@@ -1190,12 +1231,24 @@
 		$c_status		=  $p_status; #generic, unknown type
 
 		$h_status = bug_get_field( $p_bug_id, $p_field_name );
+		
+		if ( $p_field_name == 'due_date' ) {
+			if ( ! date_is_null ( $h_status ) )
+				$h_status = date( config_get ( 'short_date_format' ), $h_status );
+			else
+				$h_status = '';
+			$t_new_time = strtotime( $p_status );
+			if ( ! date_is_null( $t_new_time ) )
+				$p_status = date( config_get ( 'short_date_format' ), $tmp );
+			else
+				$p_status = '';
+			$p_field_name = lang_get( 'due_date' );
+		}
 
 		# return if status is already set
 		if ( $c_status == $h_status ) {
 			return true;
 		}
-
 		$t_bug_table = db_get_table( 'mantis_bug_table' );
 
 		# Update fields
@@ -1497,6 +1550,7 @@
 		$p_bug_data->summary			= string_attribute( $p_bug_data->summary );
 		$p_bug_data->sponsorship_total	= string_attribute( $p_bug_data->sponsorship_total );
 		$p_bug_data->sticky				= string_attribute( $p_bug_data->sticky );
+		$p_bug_data->due_date			= string_attribute( $p_bug_data->due_date );
 
 		$p_bug_data->description		= string_textarea( $p_bug_data->description );
 		$p_bug_data->steps_to_reproduce	= string_textarea( $p_bug_data->steps_to_reproduce );
@@ -1522,6 +1576,7 @@
 		$p_bug_data->summary			= string_display_line_links( $p_bug_data->summary );
 		$p_bug_data->sponsorship_total	= string_display_line( $p_bug_data->sponsorship_total );
 		$p_bug_data->sticky				= string_display_line( $p_bug_data->sticky );
+		$p_bug_data->due_date			= string_display_line( $p_bug_data->due_date );
 
 		$p_bug_data->description		= string_display_links( $p_bug_data->description );
 		$p_bug_data->steps_to_reproduce	= string_display_links( $p_bug_data->steps_to_reproduce );
diff -Naur orig/core/columns_api.php mantisbt/core/columns_api.php
--- orig/core/columns_api.php	2008-03-31 13:45:24.000000000 +0200
+++ mantisbt/core/columns_api.php	2008-03-31 15:59:07.000000000 +0200
@@ -501,8 +501,12 @@
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function print_column_edit( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 		global $t_icon_path, $t_update_bug_threshold;
-
-		echo '<td>';
+		
+		if ( bug_is_overdue( $p_row['id'] ) && access_has_bug_level( config_get( 'due_date_see_threshold' ), $p_row['id'] )) {
+			print "<td class=\"overdue\">";
+		} else {
+			echo '<td>';
+		}
 		if ( !bug_is_readonly( $p_row['id'] )
 			&& access_has_bug_level( $t_update_bug_threshold, $p_row['id'] ) ) {
 			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
@@ -512,6 +516,20 @@
 		} else {
 			echo '&nbsp;';
 		}
+		if ( bug_is_overdue( $p_row['id'] ) && access_has_bug_level( config_get( 'due_date_see_threshold' ), $p_row['id'] ) ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdued.png';
+			echo '" alt="' . lang_get( 'overdue' ) . '"';
+			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
+		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && access_has_bug_level( config_get( 'due_date_see_threshold' ), $p_row['id'] )) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
+			echo '" alt="' . lang_get( 'due_date' ) . '"';
+			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
+		} else {
+			echo '&nbsp;';
+		}
+		
 		echo '</td>';
 	}
 
diff -Naur orig/core/date_api.php mantisbt/core/date_api.php
--- orig/core/date_api.php	2008-03-31 13:45:23.000000000 +0200
+++ mantisbt/core/date_api.php	2008-03-31 15:28:41.000000000 +0200
@@ -22,6 +22,20 @@
 	# --------------------------------------------------------
 
 	### Date API ###
+	# --------------------
+	# checks if date is null
+	function date_is_null ( $p_date ) {
+		if ( $p_date == date_get_null( ) ) {
+			return true;
+		}
+		return false;
+	}
+	
+	# --------------------
+	# gets null date 
+	function date_get_null ( ) {
+		return db_unixtimestamp( '1970-01-01 00:00:01' );
+	}
 
 	# --------------------
 	# prints the date given the formating string
diff -Naur orig/core/filter_api.php mantisbt/core/filter_api.php
--- orig/core/filter_api.php	2008-03-31 13:45:23.000000000 +0200
+++ mantisbt/core/filter_api.php	2008-03-31 14:06:38.000000000 +0200
@@ -1539,6 +1539,7 @@
 			
 			$row['date_submitted'] = db_unixtimestamp ( $row['date_submitted'] );
 			$row['last_updated'] = db_unixtimestamp ( $row['last_updated'] );
+			$row['due_date']	= db_unixtimestamp( $row['due_date'] );
 					
 			array_push( $rows, $row );
 		}
diff -Naur orig/core/version_api.php mantisbt/core/version_api.php
--- orig/core/version_api.php	2008-03-31 13:45:23.000000000 +0200
+++ mantisbt/core/version_api.php	2008-03-31 14:56:16.000000000 +0200
@@ -326,8 +326,9 @@
 			$t_obsolete_where = '';
 		} else {
 			$c_obsolete = db_prepare_bool( $p_obsolete );
-			$t_obsolete_where = "AND ( obsolete = $c_obsolete )";
+			$t_obsolete_where = "AND ( obsolete = ". db_param(0)." )";
 		}
+		
 
 		$t_project_version_table = db_get_table( 'mantis_project_version_table' );
 
@@ -335,7 +336,7 @@
 				  FROM $t_project_version_table
 				  WHERE $t_project_where $t_released_where $t_obsolete_where
 				  ORDER BY date_order DESC";
-		$result = db_query( $query );
+		$result = db_query_bound( $query, Array( $c_obsolete ) );
 		$count = db_num_rows( $result );
 		$rows = array();
 		for ( $i = 0 ; $i < $count ; $i++ ) {
diff -Naur orig/css/default.css mantisbt/css/default.css
--- orig/css/default.css	2008-03-31 13:44:50.000000000 +0200
+++ mantisbt/css/default.css	2008-03-31 14:06:38.000000000 +0200
@@ -49,6 +49,7 @@
 td.left				{ text-align: left; }
 td.right			{ text-align: right; }
 td.category			{ background-color: #c8c8e8; color: #000000; font-weight: bold; vertical-align : top; }
+td.overdue			{ background-color: #ff0000; color: #000000; font-weight: bold; }
 
 td.col-1			{ background-color: #d8d8d8; color: #000000; }
 td.col-2			{ background-color: #e8e8e8; color: #000000; }
diff -Naur orig/images/clock.png mantisbt/images/clock.png
--- orig/images/clock.png	1970-01-01 01:00:00.000000000 +0100
+++ mantisbt/images/clock.png	2008-03-31 14:06:38.000000000 +0200
@@ -0,0 +1,8 @@
+�PNG
+
+
IHDR�agAMA��7��tEXtSoftwareAdobe ImageReadyq�e<IDAT8�]�kHSq��}��}�(
+�E�AAЇnA��X��Vd�Y�����դ��tv���<���Z�������.�czt{z�CGu�wxx��y��?7��M#Ԅ�xGLg�ٜɽ�H��s�@����L��X�Z�^+f�?���~;��tg��o%��
+<�\FȚ<06�o�{�)��CA��:�`�߇N�29���R��_�� 8ww>l��6��׌��t�7����M}�پ��	��7EF܏&���M�s�zJf�-�K�S���0�\�u��I�!���}ً�f>Ʌ]�z��d��&�."�^õ�J,.��4���2��I3�(Pd�E�ىzG˅���מ���=�M'��QH��;e��PQxt5/ހ���G0/��v��T�\}`�gD��hc�8����	�/j�R��Tp��
+�e�x��+��J�P���/)T�;ƥ��0o��8�ާ�x^+��e��/<6�i�Fہ�� ~�G��
+��[��app�@�N��yY&^�t�R�E]�����"�taC
+��T�%}N+BŨyY&^��x�r�k���᪾6W݇$+��Ϊ�U�0�L����`��#�ZyÙZ��}���<�nY�z��<�s�c�e#dU����� I�M&~b�R�P�*���-�+�li��B���)0��	��t�����tw�f��3ោi5�¢(���ĂxAUU�L��#��+OA��D� ������ߟ��IEND�B`�
\ No newline at end of file
diff -Naur orig/images/overdued.png mantisbt/images/overdued.png
--- orig/images/overdued.png	1970-01-01 01:00:00.000000000 +0100
+++ mantisbt/images/overdued.png	2008-03-31 14:06:38.000000000 +0200
@@ -0,0 +1,5 @@
+�PNG
+
+
IHDR�agAMA��7��tEXtSoftwareAdobe ImageReadyq�e<,IDAT8�]�kHa�� �2�Z��X$a%I��E�E?�C?*��Q��.YY�M�LKk���R+��4�k��m^�5���]����qLG��|�Y4��o���0��:�rC� >�����ā�6"��92qC�3���3���~[�rK�k�'���E���}G��6M�~1I���H�M-=���(��h�'�[�R�Ǎ�6
V��Pm����zE���N^%1����Fi��tK�z{^��f�s�� |E�������&�ߑ�Ό��%�]�}��S]��r_����9�]e�ӕ3�&ܵ5�d���+! ��:�j�P��y��{��!��6'���Xm�7��|�D��#McW0FCK~P͐�J�Żq�(`g����vې]�x�ĵ�.��d��'dE�ռ|�)(�ݍ�/�Bh��X/s�d
+b��
+��8��R��G=8����	���gXž,X/sV�z.n˵A�oG��RH?��Nd��d��	��ǀ�=��`��H>��_{�}a%޹�h���FT<���$J�x�9�}��z�3�t�n��1�^�"��B-,��~��H��C�0RL�D`�x�����d�5��#%[�ic=�dڇ��pP�De�jt�\	i�2����u�ؿ����w�*=��WH�, ��)J�;ӬMd�8s&���О���ѣ�X��$�Ӊ7f�/qW.f�6`�^���4M\�mS��e�d�&&�*:��\RRC�n�E���i���GxB�o3�4ћ��o��(���PPPE�=Ĵ�e�sԨ:6�b�HM����_5�ӡ��IEND�B`�
\ No newline at end of file
diff -Naur orig/lang/strings_english.txt mantisbt/lang/strings_english.txt
--- orig/lang/strings_english.txt	2008-03-31 13:44:41.000000000 +0200
+++ mantisbt/lang/strings_english.txt	2008-03-31 14:06:38.000000000 +0200
@@ -1511,4 +1511,9 @@
 # mind mapping
 $s_mindmap = 'Mindmap';
 $s_freemind_export = 'Freemind Export';
+
+# due date
+$s_due_date = "Due Date";
+$s_overdue = "Overdue";
+
 ?>
\ No newline at end of file
diff -Naur orig/lang/strings_polish.txt mantisbt/lang/strings_polish.txt
--- orig/lang/strings_polish.txt	2008-03-31 13:44:41.000000000 +0200
+++ mantisbt/lang/strings_polish.txt	2008-03-31 14:06:38.000000000 +0200
@@ -1336,4 +1336,7 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
+$s_due_date = "Termin realizacji";
+$s_overdue = "Przeterminowane";
+
 ?>
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-31 13:44:40.000000000 +0200
+++ mantisbt/lang/strings_polish_8859-2.txt	2008-03-31 14:06:38.000000000 +0200
@@ -1336,4 +1336,7 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
+$s_due_date = "Termin realizacji";
+$s_overdue = "Przeterminowane";
+
 ?>
duedate_stage1_final2.diff (28,076 bytes)   
duedate_stage1_final3.diff (28,462 bytes)   
diff -Naur orig/admin/schema.php mantisbt/admin/schema.php
--- orig/admin/schema.php	2008-03-31 14:05:21.000000000 +0200
+++ mantisbt/admin/schema.php	2008-03-31 15:27:04.000000000 +0200
@@ -383,6 +383,8 @@
 $upgrade[] = Array( 'InsertData', Array( db_get_table( 'mantis_category_table' ), "
 	( project_id, user_id, name, status ) VALUES
 	( '0', '0', 'General', '0' ) " ) );
+
+
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "category_id I UNSIGNED NOTNULL DEFAULT '1'" ) );
 $upgrade[] = Array( 'UpdateFunction', "category_migrate" );
 $upgrade[] = Array( 'DropColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "category" ) );
@@ -405,3 +407,5 @@
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_version_table' ), "
 	obsolete		L		NOTNULL DEFAULT \" '0' \"" ) );
 
+$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "
+	due_date 		T 		NOTNULL DEFAULT '1970-01-01 00:00:01' " ) );
diff -Naur orig/bug_change_status_page.php mantisbt/bug_change_status_page.php
--- orig/bug_change_status_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_change_status_page.php	2008-04-03 11:07:19.000000000 +0200
@@ -52,7 +52,7 @@
 			) ) {
 		access_denied();
 	}
-
+	$t_can_set_due_date = access_has_bug_level( config_get( 'due_date_set_threshold' ), $f_bug_id );
 	# get new issue handler if set, otherwise default to original handler
 	$f_handler_id = gpc_get_int( 'handler_id', bug_get_field( $f_bug_id, 'handler_id' ) );
 
@@ -161,6 +161,35 @@
 </tr>
 <?php } ?>
 
+<!-- Due date -->
+<?php if ( $t_can_set_due_date ) { 
+# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			echo "<style type=\"text/css\">@import url(javascript/jscalendar/calendar-blue.css);</style>";
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/lang/calendar-en.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar-setup.js\"></script>\n"; 	
+		}
+	$t_icon_path = config_get( 'icon_path' );
+	$cal_icon = $t_icon_path ."calendar-img.gif";
+	$t_date_to_display = '';
+	if ( ! date_is_null( $t_bug->due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );	
+?>
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?> <?php print_documentation_link( 'due_date' ) ?>
+	</td>
+	<td>
+	<?php
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+	?>
+	    <input type="image" class="button" id="trigger" SRC="
+	    <?php print $cal_icon;?> " onClick="return showCalendar ('sel1', '%Y-%m-%d', 24, true)" />
+	</td>
+</tr>
+<?php } ?>
+
 <!-- Custom Fields -->
 <?php
 # @@@ thraxisp - I undid part of the change for #5068 for #5527
@@ -320,6 +349,23 @@
 </form>
 </div>
 
+<?php
+if ( $t_can_set_due_date ) { 
+	$t_format = config_get( 'short_date_format' );
+	$t_new_format = str_replace( '-', '-%', $t_format );
+	$t_format = "%".$t_new_format;
+
+?>
+	<script type="text/javascript">
+		Calendar.setup (
+		{
+		 inputField 	: "due_date",
+		 ifFormat 	: "<?php print $t_format?>",
+		 button		: "trigger"
+		}
+		);
+	</script>
+<?php } ?>
 <br />
 <?php
 	include( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'bug_view_inc.php' );
diff -Naur orig/bug_report.php mantisbt/bug_report.php
--- orig/bug_report.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_report.php	2008-03-31 16:02:24.000000000 +0200
@@ -54,6 +54,10 @@
 	$t_bug_data->description			= gpc_get_string( 'description' );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
+	$t_bug_data->due_date 				= gpc_get_string( 'due_date', '');
+	if ( is_blank ( $t_bug_data->due_date ) ) {
+		$t_bug_data->due_date = date_get_null();
+	}
 
 	$f_file					= gpc_get_file( 'file', null ); #@@@ (thraxisp) Note that this always returns a structure
 															# size = 0, if no file
@@ -188,6 +192,7 @@
 		<input type="hidden" name="build" 		value="<?php echo $t_bug_data->build ?>" />
 		<input type="hidden" name="report_stay" 	value="1" />
 		<input type="hidden" name="view_state"		value="<?php echo $t_bug_data->view_state ?>" />
+		<input type="hidden" name="due_date"		value="<?php echo $t_bug_data->due_date ?>" />
 		<input type="submit" class="button" 		value="<?php echo lang_get( 'report_more_bugs' ) ?>" />
 	</form>
 	</p>
diff -Naur orig/bug_report_advanced_page.php mantisbt/bug_report_advanced_page.php
--- orig/bug_report_advanced_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_report_advanced_page.php	2008-03-31 15:10:51.000000000 +0200
@@ -44,6 +44,8 @@
 		print_header_redirect ( 'bug_report_page.php' .
 						( 0 == $f_master_bug_id ) ? '' : '?m_id=' . $f_master_bug_id );
 	}
+	
+	$t_can_set_due_date = access_has_bug_level( config_get( 'due_date_set_threshold' ), $f_master_bug_id );
 
 	if( $f_master_bug_id > 0 ) {
 		# master bug exists...
@@ -114,6 +116,7 @@
 		$f_steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 		$f_additional_info		= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
 		$f_view_state			= gpc_get_int( 'view_state', config_get( 'default_bug_view_status' ) );
+		$f_due_date				=gpc_get_string( 'due_date', '');
 
 		$t_project_id			= helper_get_current_project();
 
@@ -209,6 +212,31 @@
 </tr>
 <?php } ?>
 
+<!-- Due date -->
+<?php if ( $t_can_set_due_date ) { 
+# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			echo "<style type=\"text/css\">@import url(javascript/jscalendar/calendar-blue.css);</style>";
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/lang/calendar-en.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar-setup.js\"></script>\n"; 	
+		}
+	$t_icon_path = config_get( 'icon_path' );
+	$cal_icon = $t_icon_path ."calendar-img.gif";
+?>
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?> <?php print_documentation_link( 'due_date' ) ?>
+	</td>
+	<td>
+	<?php
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".print_date( config_get( 'short_date_format' ), $t_bug->due_date)."\">";
+	?>
+	    <input type="image" class="button" id="trigger" SRC="
+	    <?php print $cal_icon;?> " onClick="return showCalendar ('sel1', '%Y-%m-%d', 24, true)" />
+	</td>
+</tr>
+<?php } ?>
 
 <!-- spacer -->
 <tr class="spacer">
@@ -554,6 +582,22 @@
 	window.document.report_bug_form.category_id.focus();
 -->
 </script>
+<?php  }
+if ( $t_can_set_due_date ) { 
+	$t_format = config_get( 'short_date_format' );
+	$t_new_format = str_replace( '-', '-%', $t_format );
+	$t_format = "%".$t_new_format;
+
+?>
+	<script type="text/javascript">
+		Calendar.setup (
+		{
+		 inputField 	: "due_date",
+		 ifFormat 	: "<?php print $t_format?>",
+		 button		: "trigger"
+		}
+		);
+	</script>
 <?php } ?>
 
 <?php html_page_bottom1( __FILE__ ) ?>
diff -Naur orig/bug_update.php mantisbt/bug_update.php
--- orig/bug_update.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update.php	2008-03-31 16:03:04.000000000 +0200
@@ -77,7 +77,11 @@
 	$t_bug_data->target_version		= gpc_get_string( 'target_version', $t_bug_data->target_version );
 	$t_bug_data->view_state			= gpc_get_int( 'view_state', $t_bug_data->view_state );
 	$t_bug_data->summary			= gpc_get_string( 'summary', $t_bug_data->summary );
-
+	$t_bug_data->due_date 				= gpc_get_string( 'due_date', $t_bug_data->due_date);
+	if ( is_blank ( $t_bug_data->due_date ) ) {
+		$t_bug_data->due_date = date_get_null( );
+	}
+	
 	$t_bug_data->description		= gpc_get_string( 'description', $t_bug_data->description );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', $t_bug_data->steps_to_reproduce );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_information', $t_bug_data->additional_information );
diff -Naur orig/bug_update_advanced_page.php mantisbt/bug_update_advanced_page.php
--- orig/bug_update_advanced_page.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update_advanced_page.php	2008-03-31 15:55:30.000000000 +0200
@@ -35,7 +35,7 @@
 	$f_bug_id = gpc_get_int( 'bug_id' );
 
 	$t_bug = bug_prepare_edit( 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.
@@ -48,13 +48,13 @@
 	if ( SIMPLE_ONLY == config_get( 'show_update' ) ) {
 		print_header_redirect ( 'bug_update_page.php?bug_id=' . $f_bug_id );
 	}
-
+	
 	if ( bug_is_readonly( $f_bug_id ) ) {
 		error_parameters( $f_bug_id );
 		trigger_error( ERROR_BUG_READ_ONLY_ACTION_DENIED, ERROR );
 	}
 
-	access_ensure_bug_level( config_get( 'update_bug_threshold' ), $f_bug_id );
+	$t_can_set_due_date = access_has_bug_level( config_get( 'due_date_set_threshold' ), $f_bug_id );
 
 	html_page_top1( bug_format_summary( $f_bug_id, SUMMARY_CAPTION ) );
 	html_page_top2();
@@ -189,8 +189,44 @@
 ?>
 	</td>
 
-	<!-- spacer -->
-	<td colspan="2">&nbsp;</td>
+<?php if ( access_has_bug_level( config_get( 'due_date_see_threshold' ), $f_bug_id ) ) { ?>
+	<!-- Due Date -->
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?>
+	</td>
+	<?php 
+	if ( bug_is_overdue( $f_bug_id ) ) {
+		print "<td class=\"overdue\">";
+	} else {
+		print "<td>";
+	}
+	if ( $t_can_set_due_date ) {
+# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			echo "<style type=\"text/css\">@import url(javascript/jscalendar/calendar-blue.css);</style>";
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/lang/calendar-en.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar-setup.js\"></script>\n"; 	
+		}
+	$t_icon_path = config_get( 'icon_path' );
+	$cal_icon = $t_icon_path ."calendar-img.gif";
+	$t_date_to_display = '';
+	if ( ! date_is_null( $t_bug->due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
+		}
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+	?>
+	    <input type="image" class="button" id="trigger" SRC="
+	    <?php print $cal_icon;?> " onClick="return showCalendar ('sel1', '%Y-%m-%d', 24, true)" />
+	</td>
+	<?php } else {
+		if ( $t_bug->due_date != $t_null_date  ) print_date( config_get( 'short_date_format' ), $t_bug->due_date  ); }?>
+	</td>
+<?php } else { ?>
+		<!-- spacer -->
+		<td colspan="2">&nbsp;</td>
+<?php } ?>
+
 </tr>
 
 
@@ -595,6 +631,25 @@
 </form>
 
 <?php
+if ( $t_can_set_due_date ) { 
+	$t_format = config_get( 'short_date_format' );
+	$t_new_format = str_replace( '-', '-%', $t_format );
+	$t_format = "%".$t_new_format;
+
+?>
+	<script type="text/javascript">
+		Calendar.setup (
+		{
+		 inputField 	: "due_date",
+		 ifFormat 	: "<?php print $t_format?>",
+		 button		: "trigger"
+		}
+		);
+	</script>
+<?php }?>
+
+
+<?php
 	include( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'bugnote_view_inc.php' );
 	html_page_bottom1( __FILE__ );
 
diff -Naur orig/bug_update_page.php mantisbt/bug_update_page.php
--- orig/bug_update_page.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update_page.php	2008-03-31 14:06:38.000000000 +0200
@@ -280,6 +280,9 @@
 </tr>
 
 <?php
+	} else {
+		# spacer
+		echo '<td colspan="2">&nbsp;</td>';	
 	}
 ?>
 <?php /*
diff -Naur orig/bug_view_advanced_page.php mantisbt/bug_view_advanced_page.php
--- orig/bug_view_advanced_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_view_advanced_page.php	2008-03-31 15:52:27.000000000 +0200
@@ -217,8 +217,29 @@
 		<?php echo get_enum_element( 'project_view_state', $t_bug->view_state ) ?>
 	</td>
 
-	<!-- spacer -->
-	<td colspan="2">&nbsp;</td>
+	<!-- Due Date -->
+	<?php if ( access_has_bug_level( config_get( 'due_date_see_threshold' ), $f_bug_id ) ) { ?>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?>
+	</td>
+	<?php
+	if ( bug_is_overdue( $f_bug_id ) ) {
+		print "<td class=\"overdue\">";
+	} else {
+		print "<td>";
+	}
+	?>
+		<?php 
+			if ( !date_is_null( $t_bug->due_date ) ) {
+				print_date( config_get( 'short_date_format' ), $t_bug->due_date ); }
+			?>
+	</td>
+	<?php } else { ?>
+		<!-- spacer -->
+		<td colspan="2">&nbsp;</td>
+	<?php
+	}
+	?>
 
 </tr>
 
diff -Naur orig/config_defaults_inc.php mantisbt/config_defaults_inc.php
--- orig/config_defaults_inc.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/config_defaults_inc.php	2008-04-04 10:50:51.000000000 +0200
@@ -1995,4 +1995,14 @@
 	# Enables or disables the mind mapping features including ability to export Freemind files and 
 	# in browser view of generated mindmaps.
 	$g_mindmap_enabled = ON;
-?>
\ No newline at end of file
+
+	#############################
+	# Due Date 
+	#############################
+
+	# threshold to set due date_submitted
+	$g_due_date_set_threshold = DEVELOPER;
+	
+	$g_due_date_see_threshold = REPORTER;
+
+?>
diff -Naur orig/core/bug_api.php mantisbt/core/bug_api.php
--- orig/core/bug_api.php	2008-03-31 13:45:23.000000000 +0200
+++ mantisbt/core/bug_api.php	2008-04-04 10:16:14.000000000 +0200
@@ -79,6 +79,9 @@
 		
 		#internal helper objects
 		var $_stats = null;
+		
+		#due date
+		var $due_date = '';
 	}
 
 	#===================================
@@ -105,6 +108,8 @@
 			$p_bug_database_result['date_submitted']	= db_unixtimestamp( $p_bug_database_result['date_submitted']['date_submitted'] );
 		if( !is_int( $p_bug_database_result['last_updated'] ) )
 			$p_bug_database_result['last_updated']	= db_unixtimestamp( $p_bug_database_result['last_updated'] );
+		if( !is_int( $p_bug_datebase_result['due_date'] ) ) 
+			$p_bug_datebase_result['due_date']	= db_unixtimestamp( $p_bug_datebase_result['due_date'] );
 		$g_cache_bug[ $p_bug_database_result['id'] ] = $p_bug_database_result;
 		if( !is_null( $p_stats ) ) {
 			$g_cache_bug[ $p_bug_database_result['id'] ]['_stats'] = $p_stats;
@@ -145,6 +150,8 @@
 		$row = db_fetch_array( $result );
 		$row['date_submitted']	= db_unixtimestamp( $row['date_submitted'] );
 		$row['last_updated']	= db_unixtimestamp( $row['last_updated'] );
+		$row['due_date']	= db_unixtimestamp( $row['due_date'] );
+		
 		$g_cache_bug[$c_bug_id] = $row;
 
 		return $row;
@@ -335,6 +342,23 @@
 	}
 
 	# --------------------
+	# Check if the bug is overdue
+	function bug_is_overdue( $p_bug_id ) {
+		$t_bug_row = bug_cache_row( $p_bug_id );
+		$t_due_date = $t_bug_row[ 'due_date' ];
+		if (  ! date_is_null( $t_due_date)  ) {
+			$t_now = db_unixtimestamp();
+			if ( $t_now > $t_due_date ) {
+				if ( $t_bug_row[ 'status' ] < config_get( 'bug_resolved_status_threshold' ) ) {
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+
+
+	# --------------------
 	# Validate workflow state to see if bug can be moved to requested state
 	function bug_check_workflow( $p_bug_status, $p_wanted_status ) {
 		$t_status_enum_workflow = config_get( 'status_enum_workflow' );
@@ -393,6 +417,8 @@
 		$c_additional_info		= $p_bug_data->additional_information;
 		$c_sponsorship_total 	= 0;
 		$c_sticky 				= 0;
+		$c_due_date				= $p_bug_data->due_date;
+		
 
 		# Summary cannot be blank
 		if ( is_blank( $c_summary ) ) {
@@ -419,6 +445,17 @@
 			$c_target_version	= '';
 		}
 
+		#check due_date format
+		if ( is_blank( $c_due_date ) ) {
+			$c_due_date = date_get_null();
+		}
+		
+		
+		if ( !is_int( $c_due_date ) ) {
+			$t_format = strtotime( $c_due_date);
+			$c_due_date = date ( 'Y-m-d 00:00:01', $t_format );
+		}
+
 		$t_bug_table				= db_get_table( 'mantis_bug_table' );
 		$t_bug_text_table			= db_get_table( 'mantis_bug_text_table' );
 		$t_category_table			= db_get_table( 'mantis_category_table' );
@@ -474,7 +511,7 @@
 				      platform, version,
 				      build,
 				      profile_id, summary, view_state, sponsorship_total, sticky, fixed_in_version,
-				      target_version 
+				      target_version, due_date 
 				    )
 				  VALUES
 				    ( " . db_param(0) . ",
@@ -503,10 +540,11 @@
 				      " . db_param(23) . ",
 				      " . db_param(24) . ",
 				      " . db_param(25) . ",
-				      " . db_param(26) . ")";
+				      " . db_param(26) . ",
+				      " . db_param(27) . ")";
 		db_query_bound( $query, Array( $c_project_id, $c_reporter_id, $c_handler_id, 0, $c_priority, $c_severity, $c_reproducibility, $t_status,
 								 $t_resolution, 10, $c_category_id, db_now(), db_now(), 10, $t_text_id, $c_os, $c_os_build, $c_platform, $c_version,$c_build,
-								 $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version ) );
+								 $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version, $c_due_date) );
 
 		$t_bug_id = db_insert_id($t_bug_table);
 
@@ -569,6 +607,7 @@
 		bug_set_field( $t_new_bug_id, 'target_version', $t_bug_data->target_version );
 		bug_set_field( $t_new_bug_id, 'sponsorship_total', 0 );
 		bug_set_field( $t_new_bug_id, 'sticky', 0 );
+		bug_set_field( $t_new_bug_id, 'due_date', $t_bug_data->due_date );
 
 		# COPY CUSTOM FIELDS
 		if ( $p_copy_custom_fields ) {
@@ -898,6 +937,16 @@
 		$t_fields[] = $c_bug_id;
 		
 		db_query_bound( $query, $t_fields );
+		
+		if ( !is_blank( $p_bug_data->due_date ) ) {
+			if ( !is_int( $p_bug_data->due_date ) ) {
+				$t_format = strtotime( $p_bug_data->due_date);
+				$p_bug_data->due_date = date ( 'Y-m-d H:i:s', $t_format );
+			} else {
+				$p_bug_data->due_date = date ( 'Y-m-d H:i:s', $p_bug_data->due_date );
+			}
+			bug_set_field( $p_bug_id, 'due_date', $p_bug_data->due_date);
+		}
 
 		bug_clear_cache( $p_bug_id );
 
@@ -1190,12 +1239,27 @@
 		$c_status		=  $p_status; #generic, unknown type
 
 		$h_status = bug_get_field( $p_bug_id, $p_field_name );
+		
+		if ( $p_field_name == 'due_date' ) {
+			if ( !date_is_null( $h_status )  )
+				$h_status = date( config_get ( 'short_date_format' ), $h_status );
+			else
+				$h_status = '';
+			$t_tmp = $p_status;
+			if ( !is_int( $p_status ) ) {
+				$t_tmp = strtotime( $p_status );
+			} 
+			if ( !date_is_null( $t_tmp ) )
+				$p_status = date( config_get ( 'short_date_format' ), $t_tmp );
+			else
+				$p_status = '';
+			$p_field_name = lang_get( 'due_date' );
+		}
 
 		# return if status is already set
 		if ( $c_status == $h_status ) {
 			return true;
 		}
-
 		$t_bug_table = db_get_table( 'mantis_bug_table' );
 
 		# Update fields
@@ -1497,6 +1561,7 @@
 		$p_bug_data->summary			= string_attribute( $p_bug_data->summary );
 		$p_bug_data->sponsorship_total	= string_attribute( $p_bug_data->sponsorship_total );
 		$p_bug_data->sticky				= string_attribute( $p_bug_data->sticky );
+		$p_bug_data->due_date			= string_attribute( $p_bug_data->due_date );
 
 		$p_bug_data->description		= string_textarea( $p_bug_data->description );
 		$p_bug_data->steps_to_reproduce	= string_textarea( $p_bug_data->steps_to_reproduce );
@@ -1522,6 +1587,7 @@
 		$p_bug_data->summary			= string_display_line_links( $p_bug_data->summary );
 		$p_bug_data->sponsorship_total	= string_display_line( $p_bug_data->sponsorship_total );
 		$p_bug_data->sticky				= string_display_line( $p_bug_data->sticky );
+		$p_bug_data->due_date			= string_display_line( $p_bug_data->due_date );
 
 		$p_bug_data->description		= string_display_links( $p_bug_data->description );
 		$p_bug_data->steps_to_reproduce	= string_display_links( $p_bug_data->steps_to_reproduce );
diff -Naur orig/core/columns_api.php mantisbt/core/columns_api.php
--- orig/core/columns_api.php	2008-03-31 13:45:24.000000000 +0200
+++ mantisbt/core/columns_api.php	2008-03-31 15:59:07.000000000 +0200
@@ -501,8 +501,12 @@
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function print_column_edit( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 		global $t_icon_path, $t_update_bug_threshold;
-
-		echo '<td>';
+		
+		if ( bug_is_overdue( $p_row['id'] ) && access_has_bug_level( config_get( 'due_date_see_threshold' ), $p_row['id'] )) {
+			print "<td class=\"overdue\">";
+		} else {
+			echo '<td>';
+		}
 		if ( !bug_is_readonly( $p_row['id'] )
 			&& access_has_bug_level( $t_update_bug_threshold, $p_row['id'] ) ) {
 			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
@@ -512,6 +516,20 @@
 		} else {
 			echo '&nbsp;';
 		}
+		if ( bug_is_overdue( $p_row['id'] ) && access_has_bug_level( config_get( 'due_date_see_threshold' ), $p_row['id'] ) ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdued.png';
+			echo '" alt="' . lang_get( 'overdue' ) . '"';
+			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
+		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && access_has_bug_level( config_get( 'due_date_see_threshold' ), $p_row['id'] )) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
+			echo '" alt="' . lang_get( 'due_date' ) . '"';
+			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
+		} else {
+			echo '&nbsp;';
+		}
+		
 		echo '</td>';
 	}
 
diff -Naur orig/core/date_api.php mantisbt/core/date_api.php
--- orig/core/date_api.php	2008-03-31 13:45:23.000000000 +0200
+++ mantisbt/core/date_api.php	2008-04-04 10:22:43.000000000 +0200
@@ -22,6 +22,20 @@
 	# --------------------------------------------------------
 
 	### Date API ###
+	# --------------------
+	# checks if date is null
+	function date_is_null ( $p_date ) {
+		if ( $p_date <= date_get_null( ) ) {
+			return true;
+		}
+		return false;
+	}
+	
+	# --------------------
+	# gets null date 
+	function date_get_null ( ) {
+		return db_unixtimestamp( '1970-01-01 00:00:01' );
+	}
 
 	# --------------------
 	# prints the date given the formating string
diff -Naur orig/core/filter_api.php mantisbt/core/filter_api.php
--- orig/core/filter_api.php	2008-03-31 13:45:23.000000000 +0200
+++ mantisbt/core/filter_api.php	2008-03-31 14:06:38.000000000 +0200
@@ -1539,6 +1539,7 @@
 			
 			$row['date_submitted'] = db_unixtimestamp ( $row['date_submitted'] );
 			$row['last_updated'] = db_unixtimestamp ( $row['last_updated'] );
+			$row['due_date']	= db_unixtimestamp( $row['due_date'] );
 					
 			array_push( $rows, $row );
 		}
diff -Naur orig/core/version_api.php mantisbt/core/version_api.php
--- orig/core/version_api.php	2008-03-31 13:45:23.000000000 +0200
+++ mantisbt/core/version_api.php	2008-03-31 14:56:16.000000000 +0200
@@ -326,8 +326,9 @@
 			$t_obsolete_where = '';
 		} else {
 			$c_obsolete = db_prepare_bool( $p_obsolete );
-			$t_obsolete_where = "AND ( obsolete = $c_obsolete )";
+			$t_obsolete_where = "AND ( obsolete = ". db_param(0)." )";
 		}
+		
 
 		$t_project_version_table = db_get_table( 'mantis_project_version_table' );
 
@@ -335,7 +336,7 @@
 				  FROM $t_project_version_table
 				  WHERE $t_project_where $t_released_where $t_obsolete_where
 				  ORDER BY date_order DESC";
-		$result = db_query( $query );
+		$result = db_query_bound( $query, Array( $c_obsolete ) );
 		$count = db_num_rows( $result );
 		$rows = array();
 		for ( $i = 0 ; $i < $count ; $i++ ) {
diff -Naur orig/css/default.css mantisbt/css/default.css
--- orig/css/default.css	2008-03-31 13:44:50.000000000 +0200
+++ mantisbt/css/default.css	2008-03-31 14:06:38.000000000 +0200
@@ -49,6 +49,7 @@
 td.left				{ text-align: left; }
 td.right			{ text-align: right; }
 td.category			{ background-color: #c8c8e8; color: #000000; font-weight: bold; vertical-align : top; }
+td.overdue			{ background-color: #ff0000; color: #000000; font-weight: bold; }
 
 td.col-1			{ background-color: #d8d8d8; color: #000000; }
 td.col-2			{ background-color: #e8e8e8; color: #000000; }
diff -Naur orig/images/clock.png mantisbt/images/clock.png
--- orig/images/clock.png	1970-01-01 01:00:00.000000000 +0100
+++ mantisbt/images/clock.png	2008-03-31 14:06:38.000000000 +0200
@@ -0,0 +1,8 @@
+�PNG
+
+
IHDR�agAMA��7��tEXtSoftwareAdobe ImageReadyq�e<IDAT8�]�kHSq��}��}�(
+�E�AAЇnA��X��Vd�Y�����դ��tv���<���Z�������.�czt{z�CGu�wxx��y��?7��M#Ԅ�xGLg�ٜɽ�H��s�@����L��X�Z�^+f�?���~;��tg��o%��
+<�\FȚ<06�o�{�)��CA��:�`�߇N�29���R��_�� 8ww>l��6��׌��t�7����M}�پ��	��7EF܏&���M�s�zJf�-�K�S���0�\�u��I�!���}ً�f>Ʌ]�z��d��&�."�^õ�J,.��4���2��I3�(Pd�E�ىzG˅���מ���=�M'��QH��;e��PQxt5/ހ���G0/��v��T�\}`�gD��hc�8����	�/j�R��Tp��
+�e�x��+��J�P���/)T�;ƥ��0o��8�ާ�x^+��e��/<6�i�Fہ�� ~�G��
+��[��app�@�N��yY&^�t�R�E]�����"�taC
+��T�%}N+BŨyY&^��x�r�k���᪾6W݇$+��Ϊ�U�0�L����`��#�ZyÙZ��}���<�nY�z��<�s�c�e#dU����� I�M&~b�R�P�*���-�+�li��B���)0��	��t�����tw�f��3ោi5�¢(���ĂxAUU�L��#��+OA��D� ������ߟ��IEND�B`�
\ No newline at end of file
diff -Naur orig/images/overdued.png mantisbt/images/overdued.png
--- orig/images/overdued.png	1970-01-01 01:00:00.000000000 +0100
+++ mantisbt/images/overdued.png	2008-03-31 14:06:38.000000000 +0200
@@ -0,0 +1,5 @@
+�PNG
+
+
IHDR�agAMA��7��tEXtSoftwareAdobe ImageReadyq�e<,IDAT8�]�kHa�� �2�Z��X$a%I��E�E?�C?*��Q��.YY�M�LKk���R+��4�k��m^�5���]����qLG��|�Y4��o���0��:�rC� >�����ā�6"��92qC�3���3���~[�rK�k�'���E���}G��6M�~1I���H�M-=���(��h�'�[�R�Ǎ�6
V��Pm����zE���N^%1����Fi��tK�z{^��f�s�� |E�������&�ߑ�Ό��%�]�}��S]��r_����9�]e�ӕ3�&ܵ5�d���+! ��:�j�P��y��{��!��6'���Xm�7��|�D��#McW0FCK~P͐�J�Żq�(`g����vې]�x�ĵ�.��d��'dE�ռ|�)(�ݍ�/�Bh��X/s�d
+b��
+��8��R��G=8����	���gXž,X/sV�z.n˵A�oG��RH?��Nd��d��	��ǀ�=��`��H>��_{�}a%޹�h���FT<���$J�x�9�}��z�3�t�n��1�^�"��B-,��~��H��C�0RL�D`�x�����d�5��#%[�ic=�dڇ��pP�De�jt�\	i�2����u�ؿ����w�*=��WH�, ��)J�;ӬMd�8s&���О���ѣ�X��$�Ӊ7f�/qW.f�6`�^���4M\�mS��e�d�&&�*:��\RRC�n�E���i���GxB�o3�4ћ��o��(���PPPE�=Ĵ�e�sԨ:6�b�HM����_5�ӡ��IEND�B`�
\ No newline at end of file
diff -Naur orig/lang/strings_english.txt mantisbt/lang/strings_english.txt
--- orig/lang/strings_english.txt	2008-03-31 13:44:41.000000000 +0200
+++ mantisbt/lang/strings_english.txt	2008-03-31 14:06:38.000000000 +0200
@@ -1511,4 +1511,9 @@
 # mind mapping
 $s_mindmap = 'Mindmap';
 $s_freemind_export = 'Freemind Export';
+
+# due date
+$s_due_date = "Due Date";
+$s_overdue = "Overdue";
+
 ?>
\ No newline at end of file
diff -Naur orig/lang/strings_polish.txt mantisbt/lang/strings_polish.txt
--- orig/lang/strings_polish.txt	2008-03-31 13:44:41.000000000 +0200
+++ mantisbt/lang/strings_polish.txt	2008-03-31 14:06:38.000000000 +0200
@@ -1336,4 +1336,7 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
+$s_due_date = "Termin realizacji";
+$s_overdue = "Przeterminowane";
+
 ?>
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-31 13:44:40.000000000 +0200
+++ mantisbt/lang/strings_polish_8859-2.txt	2008-03-31 14:06:38.000000000 +0200
@@ -1336,4 +1336,7 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
+$s_due_date = "Termin realizacji";
+$s_overdue = "Przeterminowane";
+
 ?>
duedate_stage1_final3.diff (28,462 bytes)   
duedate_stage1_final4.diff (27,538 bytes)   
diff -Naur orig/admin/schema.php mantisbt/admin/schema.php
--- orig/admin/schema.php	2008-03-31 14:05:21.000000000 +0200
+++ mantisbt/admin/schema.php	2008-04-09 11:51:57.000000000 +0200
@@ -383,6 +383,8 @@
 $upgrade[] = Array( 'InsertData', Array( db_get_table( 'mantis_category_table' ), "
 	( project_id, user_id, name, status ) VALUES
 	( '0', '0', 'General', '0' ) " ) );
+
+
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "category_id I UNSIGNED NOTNULL DEFAULT '1'" ) );
 $upgrade[] = Array( 'UpdateFunction', "category_migrate" );
 $upgrade[] = Array( 'DropColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "category" ) );
@@ -405,3 +407,5 @@
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_version_table' ), "
 	obsolete		L		NOTNULL DEFAULT \" '0' \"" ) );
 
+$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "
+	due_date 		T 		NOTNULL DEFAULT '1970-01-01 00:00:01' " ) );
diff -Naur orig/bug_change_status_page.php mantisbt/bug_change_status_page.php
--- orig/bug_change_status_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_change_status_page.php	2008-04-10 13:28:34.000000000 +0200
@@ -52,7 +52,7 @@
 			) ) {
 		access_denied();
 	}
-
+	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
 	# get new issue handler if set, otherwise default to original handler
 	$f_handler_id = gpc_get_int( 'handler_id', bug_get_field( $f_bug_id, 'handler_id' ) );
 
@@ -161,6 +161,27 @@
 </tr>
 <?php } ?>
 
+<!-- Due date -->
+<?php if ( $t_can_update_due_date ) { 
+	date_prepare_calendar();
+	$t_date_to_display = '';
+	if ( ! date_is_null( $t_bug->due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );	
+	}
+?>
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?> <?php print_documentation_link( 'due_date' ) ?>
+	</td>
+	<td>
+	<?php
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+		date_print_calendar( $t_date_to_display );
+	?>
+	</td>
+</tr>
+<?php } ?>
+
 <!-- Custom Fields -->
 <?php
 # @@@ thraxisp - I undid part of the change for #5068 for #5527
@@ -320,6 +341,10 @@
 </form>
 </div>
 
+<?php
+if ( $t_can_update_due_date ) { 
+	date_finish_calendar( 'due_date', 'trigger');
+} ?>
 <br />
 <?php
 	include( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'bug_view_inc.php' );
diff -Naur orig/bug_report.php mantisbt/bug_report.php
--- orig/bug_report.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_report.php	2008-04-09 11:51:57.000000000 +0200
@@ -54,6 +54,10 @@
 	$t_bug_data->description			= gpc_get_string( 'description' );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
+	$t_bug_data->due_date 				= gpc_get_string( 'due_date', '');
+	if ( is_blank ( $t_bug_data->due_date ) ) {
+		$t_bug_data->due_date = date_get_null();
+	}
 
 	$f_file					= gpc_get_file( 'file', null ); #@@@ (thraxisp) Note that this always returns a structure
 															# size = 0, if no file
@@ -188,6 +192,7 @@
 		<input type="hidden" name="build" 		value="<?php echo $t_bug_data->build ?>" />
 		<input type="hidden" name="report_stay" 	value="1" />
 		<input type="hidden" name="view_state"		value="<?php echo $t_bug_data->view_state ?>" />
+		<input type="hidden" name="due_date"		value="<?php echo $t_bug_data->due_date ?>" />
 		<input type="submit" class="button" 		value="<?php echo lang_get( 'report_more_bugs' ) ?>" />
 	</form>
 	</p>
diff -Naur orig/bug_report_advanced_page.php mantisbt/bug_report_advanced_page.php
--- orig/bug_report_advanced_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_report_advanced_page.php	2008-04-10 13:42:32.000000000 +0200
@@ -44,6 +44,8 @@
 		print_header_redirect ( 'bug_report_page.php' .
 						( 0 == $f_master_bug_id ) ? '' : '?m_id=' . $f_master_bug_id );
 	}
+	
+	$t_can_update_due_date = access_has_project_level( config_get( 'due_date_update_threshold' ), helper_get_current_project(), auth_get_current_user_id() );
 
 	if( $f_master_bug_id > 0 ) {
 		# master bug exists...
@@ -114,6 +116,11 @@
 		$f_steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 		$f_additional_info		= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
 		$f_view_state			= gpc_get_int( 'view_state', config_get( 'default_bug_view_status' ) );
+		$f_due_date				=gpc_get_string( 'due_date', '');
+		
+		if ( $f_due_date == '' ) {
+			$f_due_date = date_get_null();
+		}
 
 		$t_project_id			= helper_get_current_project();
 
@@ -209,6 +216,27 @@
 </tr>
 <?php } ?>
 
+<!-- Due date -->
+<?php if ( $t_can_update_due_date ) { 
+date_prepare_calendar();
+	$t_date_to_display = '';
+	if ( ! date_is_null( $f_due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $f_due_date );	
+	}
+
+?>
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?> <?php print_documentation_link( 'due_date' ) ?>
+	</td>
+	<td>
+	<?php
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+		date_print_calendar();
+	?>
+	</td>
+</tr>
+<?php } ?>
 
 <!-- spacer -->
 <tr class="spacer">
@@ -554,6 +582,9 @@
 	window.document.report_bug_form.category_id.focus();
 -->
 </script>
-<?php } ?>
+<?php  }
+if ( $t_can_update_due_date ) { 
+	date_finish_calendar( 'due_date', 'trigger' );
+}
 
-<?php html_page_bottom1( __FILE__ ) ?>
+html_page_bottom1( __FILE__ ) ?>
diff -Naur orig/bug_update.php mantisbt/bug_update.php
--- orig/bug_update.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update.php	2008-04-09 11:51:57.000000000 +0200
@@ -77,7 +77,11 @@
 	$t_bug_data->target_version		= gpc_get_string( 'target_version', $t_bug_data->target_version );
 	$t_bug_data->view_state			= gpc_get_int( 'view_state', $t_bug_data->view_state );
 	$t_bug_data->summary			= gpc_get_string( 'summary', $t_bug_data->summary );
-
+	$t_bug_data->due_date 				= gpc_get_string( 'due_date', $t_bug_data->due_date);
+	if ( is_blank ( $t_bug_data->due_date ) ) {
+		$t_bug_data->due_date = date_get_null( );
+	}
+	
 	$t_bug_data->description		= gpc_get_string( 'description', $t_bug_data->description );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', $t_bug_data->steps_to_reproduce );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_information', $t_bug_data->additional_information );
diff -Naur orig/bug_update_advanced_page.php mantisbt/bug_update_advanced_page.php
--- orig/bug_update_advanced_page.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update_advanced_page.php	2008-04-10 13:57:06.000000000 +0200
@@ -35,7 +35,7 @@
 	$f_bug_id = gpc_get_int( 'bug_id' );
 
 	$t_bug = bug_prepare_edit( 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.
@@ -48,13 +48,13 @@
 	if ( SIMPLE_ONLY == config_get( 'show_update' ) ) {
 		print_header_redirect ( 'bug_update_page.php?bug_id=' . $f_bug_id );
 	}
-
+	
 	if ( bug_is_readonly( $f_bug_id ) ) {
 		error_parameters( $f_bug_id );
 		trigger_error( ERROR_BUG_READ_ONLY_ACTION_DENIED, ERROR );
 	}
 
-	access_ensure_bug_level( config_get( 'update_bug_threshold' ), $f_bug_id );
+	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
 
 	html_page_top1( bug_format_summary( $f_bug_id, SUMMARY_CAPTION ) );
 	html_page_top2();
@@ -189,8 +189,35 @@
 ?>
 	</td>
 
-	<!-- spacer -->
-	<td colspan="2">&nbsp;</td>
+<?php if ( access_has_bug_level( config_get( 'due_date_view_threshold' ), $f_bug_id ) ) { ?>
+	<!-- Due Date -->
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?>
+	</td>
+	<?php 
+	if ( bug_is_overdue( $f_bug_id ) ) {
+		print "<td class=\"overdue\">";
+	} else {
+		print "<td>";
+	}
+	if ( $t_can_update_due_date ) {
+		date_prepare_calendar();
+		$t_date_to_display = '';
+		if ( ! date_is_null( $t_bug->due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
+		}
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+		date_print_calendar( $t_date_to_display );
+	?>
+	</td>
+	<?php } else {
+		if ( $t_bug->due_date != $t_null_date  ) print_date( config_get( 'short_date_format' ), $t_bug->due_date  ); }?>
+	</td>
+<?php } else { ?>
+		<!-- spacer -->
+		<td colspan="2">&nbsp;</td>
+<?php } ?>
+
 </tr>
 
 
@@ -595,6 +622,10 @@
 </form>
 
 <?php
+if ( $t_can_update_due_date ) { 
+	date_finish_calendar( 'due_date', 'trigger');
+}
+
 	include( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'bugnote_view_inc.php' );
 	html_page_bottom1( __FILE__ );
 
diff -Naur orig/bug_update_page.php mantisbt/bug_update_page.php
--- orig/bug_update_page.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update_page.php	2008-04-09 11:51:57.000000000 +0200
@@ -280,6 +280,9 @@
 </tr>
 
 <?php
+	} else {
+		# spacer
+		echo '<td colspan="2">&nbsp;</td>';	
 	}
 ?>
 <?php /*
diff -Naur orig/bug_view_advanced_page.php mantisbt/bug_view_advanced_page.php
--- orig/bug_view_advanced_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_view_advanced_page.php	2008-04-09 12:19:36.000000000 +0200
@@ -217,8 +217,29 @@
 		<?php echo get_enum_element( 'project_view_state', $t_bug->view_state ) ?>
 	</td>
 
-	<!-- spacer -->
-	<td colspan="2">&nbsp;</td>
+	<!-- Due Date -->
+	<?php if ( access_has_bug_level( config_get( 'due_date_view_threshold' ), $f_bug_id ) ) { ?>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?>
+	</td>
+	<?php
+	if ( bug_is_overdue( $f_bug_id ) ) {
+		print "<td class=\"overdue\">";
+	} else {
+		print "<td>";
+	}
+	?>
+		<?php 
+			if ( !date_is_null( $t_bug->due_date ) ) {
+				print_date( config_get( 'short_date_format' ), $t_bug->due_date ); }
+			?>
+	</td>
+	<?php } else { ?>
+		<!-- spacer -->
+		<td colspan="2">&nbsp;</td>
+	<?php
+	}
+	?>
 
 </tr>
 
diff -Naur orig/config_defaults_inc.php mantisbt/config_defaults_inc.php
--- orig/config_defaults_inc.php	2008-04-09 11:49:48.000000000 +0200
+++ mantisbt/config_defaults_inc.php	2008-04-09 12:17:07.000000000 +0200
@@ -1990,6 +1990,17 @@
 	# management threshold.
 	$g_manage_plugin_threshold = ADMINISTRATOR;
 
+ 
+ 	#############################
+ 	# Due Date 
+ 	#############################
+ 
+ 	# threshold to update due date submitted
+ 	$g_due_date_update_threshold = DEVELOPER;
+ 	
+	# threshold to see due date
+ 	$g_due_date_view_threshold = REPORTER;
+
 	#############################
 	# Mind mapping
 	#############################
diff -Naur orig/core/bug_api.php mantisbt/core/bug_api.php
--- orig/core/bug_api.php	2008-03-31 13:45:23.000000000 +0200
+++ mantisbt/core/bug_api.php	2008-04-10 13:53:29.000000000 +0200
@@ -79,6 +79,9 @@
 		
 		#internal helper objects
 		var $_stats = null;
+		
+		#due date
+		var $due_date = '';
 	}
 
 	#===================================
@@ -105,6 +108,8 @@
 			$p_bug_database_result['date_submitted']	= db_unixtimestamp( $p_bug_database_result['date_submitted']['date_submitted'] );
 		if( !is_int( $p_bug_database_result['last_updated'] ) )
 			$p_bug_database_result['last_updated']	= db_unixtimestamp( $p_bug_database_result['last_updated'] );
+		if( !is_int( $p_bug_datebase_result['due_date'] ) ) 
+			$p_bug_datebase_result['due_date']	= db_unixtimestamp( $p_bug_datebase_result['due_date'] );
 		$g_cache_bug[ $p_bug_database_result['id'] ] = $p_bug_database_result;
 		if( !is_null( $p_stats ) ) {
 			$g_cache_bug[ $p_bug_database_result['id'] ]['_stats'] = $p_stats;
@@ -145,6 +150,8 @@
 		$row = db_fetch_array( $result );
 		$row['date_submitted']	= db_unixtimestamp( $row['date_submitted'] );
 		$row['last_updated']	= db_unixtimestamp( $row['last_updated'] );
+		$row['due_date']	= db_unixtimestamp( $row['due_date'] );
+		
 		$g_cache_bug[$c_bug_id] = $row;
 
 		return $row;
@@ -335,6 +342,23 @@
 	}
 
 	# --------------------
+	# Check if the bug is overdue
+	function bug_is_overdue( $p_bug_id ) {
+		$t_bug_row = bug_cache_row( $p_bug_id );
+		$t_due_date = $t_bug_row[ 'due_date' ];
+		if (  ! date_is_null( $t_due_date)  ) {
+			$t_now = db_unixtimestamp();
+			if ( $t_now > $t_due_date ) {
+				if ( bug_is_resolved( $p_bug_id ) ) {
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+
+
+	# --------------------
 	# Validate workflow state to see if bug can be moved to requested state
 	function bug_check_workflow( $p_bug_status, $p_wanted_status ) {
 		$t_status_enum_workflow = config_get( 'status_enum_workflow' );
@@ -393,6 +417,8 @@
 		$c_additional_info		= $p_bug_data->additional_information;
 		$c_sponsorship_total 	= 0;
 		$c_sticky 				= 0;
+		$c_due_date				= $p_bug_data->due_date;
+		
 
 		# Summary cannot be blank
 		if ( is_blank( $c_summary ) ) {
@@ -419,6 +445,17 @@
 			$c_target_version	= '';
 		}
 
+		#check due_date format
+		if ( !is_blank( $p_bug_data->due_date ) ) {
+			if ( !is_int( $p_bug_data->due_date ) ) {
+				$t_tmp = strtotime( $p_bug_data->due_date);
+				$c_due_date = date ( 'Y-m-d 00:00:01', $t_tmp );
+			} else {
+				$c_due_date = date ( 'Y-m-d H:i:s', $p_bug_data->due_date );
+			}
+		}
+
+
 		$t_bug_table				= db_get_table( 'mantis_bug_table' );
 		$t_bug_text_table			= db_get_table( 'mantis_bug_text_table' );
 		$t_category_table			= db_get_table( 'mantis_category_table' );
@@ -474,7 +511,7 @@
 				      platform, version,
 				      build,
 				      profile_id, summary, view_state, sponsorship_total, sticky, fixed_in_version,
-				      target_version 
+				      target_version, due_date 
 				    )
 				  VALUES
 				    ( " . db_param(0) . ",
@@ -503,10 +540,11 @@
 				      " . db_param(23) . ",
 				      " . db_param(24) . ",
 				      " . db_param(25) . ",
-				      " . db_param(26) . ")";
+				      " . db_param(26) . ",
+				      " . db_param(27) . ")";
 		db_query_bound( $query, Array( $c_project_id, $c_reporter_id, $c_handler_id, 0, $c_priority, $c_severity, $c_reproducibility, $t_status,
 								 $t_resolution, 10, $c_category_id, db_now(), db_now(), 10, $t_text_id, $c_os, $c_os_build, $c_platform, $c_version,$c_build,
-								 $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version ) );
+								 $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version, $c_due_date) );
 
 		$t_bug_id = db_insert_id($t_bug_table);
 
@@ -569,6 +607,7 @@
 		bug_set_field( $t_new_bug_id, 'target_version', $t_bug_data->target_version );
 		bug_set_field( $t_new_bug_id, 'sponsorship_total', 0 );
 		bug_set_field( $t_new_bug_id, 'sticky', 0 );
+		bug_set_field( $t_new_bug_id, 'due_date', $t_bug_data->due_date );
 
 		# COPY CUSTOM FIELDS
 		if ( $p_copy_custom_fields ) {
@@ -898,6 +937,16 @@
 		$t_fields[] = $c_bug_id;
 		
 		db_query_bound( $query, $t_fields );
+		
+		if ( !is_blank( $p_bug_data->due_date ) ) {
+			if ( !is_int( $p_bug_data->due_date ) ) {
+				$t_format = strtotime( $p_bug_data->due_date);
+				$p_bug_data->due_date = date ( 'Y-m-d 00:00:01', $t_format );
+			} else {
+				$p_bug_data->due_date = date ( 'Y-m-d H:i:s', $p_bug_data->due_date );
+			}
+			bug_set_field( $p_bug_id, 'due_date', $p_bug_data->due_date);
+		}
 
 		bug_clear_cache( $p_bug_id );
 
@@ -1190,17 +1239,34 @@
 		$c_status		=  $p_status; #generic, unknown type
 
 		$h_status = bug_get_field( $p_bug_id, $p_field_name );
+		
+		if ( $p_field_name == 'due_date' ) {
+			if ( !date_is_null( $h_status )  ) {
+				$h_status = date( config_get ( 'short_date_format' ), $h_status );
+			} else {
+				$h_status = '';
+			}
+			$t_tmp = $p_status;
+			if ( !is_int( $p_status ) ) {
+				$t_tmp = strtotime( $p_status );
+			} 
+			if ( !date_is_null( $t_tmp ) ) {
+				$c_status = date( 'Y-m-d 00:00:01', $t_tmp );
+			} else {
+				$c_status = '';
+			}
+			$c_field_name = lang_get( 'due_date' );
+		}
 
 		# return if status is already set
 		if ( $c_status == $h_status ) {
 			return true;
 		}
-
 		$t_bug_table = db_get_table( 'mantis_bug_table' );
 
 		# Update fields
 		$query = "UPDATE $t_bug_table
-				  SET $c_field_name=" . db_param(0) . "
+				  SET $p_field_name=" . db_param(0) . "
 				  WHERE id=" .db_param(1);
 		db_query_bound( $query, Array( $c_status, $c_bug_id ) );
 
@@ -1210,7 +1276,7 @@
 		# log changes except for duplicate_id which is obsolete and should be removed in
 		# Mantis 1.3.
 		if ( $p_field_name != 'duplicate_id' ) {
-			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $p_status );
+			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $c_status );
 		}
 
 		bug_clear_cache( $p_bug_id );
@@ -1497,6 +1563,7 @@
 		$p_bug_data->summary			= string_attribute( $p_bug_data->summary );
 		$p_bug_data->sponsorship_total	= string_attribute( $p_bug_data->sponsorship_total );
 		$p_bug_data->sticky				= string_attribute( $p_bug_data->sticky );
+		$p_bug_data->due_date			= string_attribute( $p_bug_data->due_date );
 
 		$p_bug_data->description		= string_textarea( $p_bug_data->description );
 		$p_bug_data->steps_to_reproduce	= string_textarea( $p_bug_data->steps_to_reproduce );
@@ -1522,6 +1589,7 @@
 		$p_bug_data->summary			= string_display_line_links( $p_bug_data->summary );
 		$p_bug_data->sponsorship_total	= string_display_line( $p_bug_data->sponsorship_total );
 		$p_bug_data->sticky				= string_display_line( $p_bug_data->sticky );
+		$p_bug_data->due_date			= string_display_line( $p_bug_data->due_date );
 
 		$p_bug_data->description		= string_display_links( $p_bug_data->description );
 		$p_bug_data->steps_to_reproduce	= string_display_links( $p_bug_data->steps_to_reproduce );
diff -Naur orig/core/columns_api.php mantisbt/core/columns_api.php
--- orig/core/columns_api.php	2008-03-31 13:45:24.000000000 +0200
+++ mantisbt/core/columns_api.php	2008-04-09 12:27:32.000000000 +0200
@@ -501,8 +501,12 @@
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function print_column_edit( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 		global $t_icon_path, $t_update_bug_threshold;
-
-		echo '<td>';
+		
+		if ( bug_is_overdue( $p_row['id'] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] )) {
+			print "<td class=\"overdue\">";
+		} else {
+			echo '<td>';
+		}
 		if ( !bug_is_readonly( $p_row['id'] )
 			&& access_has_bug_level( $t_update_bug_threshold, $p_row['id'] ) ) {
 			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
@@ -512,6 +516,20 @@
 		} else {
 			echo '&nbsp;';
 		}
+		if ( bug_is_overdue( $p_row['id'] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] ) ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdue.png';
+			echo '" alt="' . lang_get( 'overdue' ) . '"';
+			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
+		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] )) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
+			echo '" alt="' . lang_get( 'due_date' ) . '"';
+			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
+		} else {
+			echo '&nbsp;';
+		}
+		
 		echo '</td>';
 	}
 
diff -Naur orig/core/date_api.php mantisbt/core/date_api.php
--- orig/core/date_api.php	2008-03-31 13:45:23.000000000 +0200
+++ mantisbt/core/date_api.php	2008-04-10 13:46:29.000000000 +0200
@@ -22,6 +22,20 @@
 	# --------------------------------------------------------
 
 	### Date API ###
+	# --------------------
+	# checks if date is null
+	function date_is_null ( $p_date ) {
+		if ( $p_date == date_get_null( ) ) {
+			return true;
+		}
+		return false;
+	}
+	
+	# --------------------
+	# gets null date 
+	function date_get_null ( ) {
+		return db_unixtimestamp( '1970-01-01 00:00:01' );
+	}
 
 	# --------------------
 	# prints the date given the formating string
@@ -149,4 +163,44 @@
 			}
 		}
 	}
+	
+	function date_prepare_calendar () {
+	# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			echo "<style type=\"text/css\">@import url(javascript/jscalendar/calendar-blue.css);</style>\n";
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/lang/calendar-en.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar-setup.js\"></script>\n"; 	
+		}	
+	}
+	function date_print_calendar ( $p_date = null, $p_button_name = 'trigger' ) {
+		# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			$t_icon_path = config_get( 'icon_path' );
+			$t_cal_icon = $t_icon_path ."calendar-img.gif";	
+	   	 	echo "<input type=\"image\" class=\"button\" id=\"".$p_button_name."\" SRC=\"";
+	    	echo $t_cal_icon;
+			$t_format = config_get( 'short_date_format' );
+			$t_new_format = str_replace( '-', '-%', $t_format );
+			$t_format = "%".$t_new_format;
+			echo "\" onClick=\"return showCalendar ('sel1', '".$t_format."', 24, true)\" />";
+		}
+	}
+	function date_finish_calendar ( $p_field_name, $p_button_name) {
+	# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			$t_format = config_get( 'short_date_format' );
+			$t_new_format = str_replace( '-', '-%', $t_format );
+			$t_format = "%".$t_new_format;
+			echo "<script type=\"text/javascript\">\n";
+			echo "Calendar.setup (\n";
+			echo "{\n";
+		 	echo "inputField 	: \"".$p_field_name."\",\n";
+		 	echo "ifFormat 	: \"".$t_format."\", \n";
+		 	echo "button		: \"".$p_button_name."\"\n";
+			echo "}\n";
+			echo ");\n";
+			echo "</script>\n";
+			}	
+	}
 ?>
diff -Naur orig/core/filter_api.php mantisbt/core/filter_api.php
--- orig/core/filter_api.php	2008-04-09 11:49:48.000000000 +0200
+++ mantisbt/core/filter_api.php	2008-04-09 11:51:57.000000000 +0200
@@ -1537,6 +1537,7 @@
 			
 			$row['date_submitted'] = db_unixtimestamp ( $row['date_submitted'] );
 			$row['last_updated'] = db_unixtimestamp ( $row['last_updated'] );
+			$row['due_date']	= db_unixtimestamp( $row['due_date'] );
 					
 			array_push( $rows, $row );
 		}
diff -Naur orig/css/default.css mantisbt/css/default.css
--- orig/css/default.css	2008-04-09 11:49:47.000000000 +0200
+++ mantisbt/css/default.css	2008-04-09 11:51:57.000000000 +0200
@@ -52,6 +52,7 @@
 td.left				{ text-align: left; }
 td.right			{ text-align: right; }
 td.category			{ background-color: #c8c8e8; color: #000000; font-weight: bold; vertical-align : top; }
+td.overdue			{ background-color: #ff0000; color: #000000; font-weight: bold; }
 
 td.col-1			{ background-color: #d8d8d8; color: #000000; }
 td.col-2			{ background-color: #e8e8e8; color: #000000; }
diff -Naur orig/images/clock.png mantisbt/images/clock.png
--- orig/images/clock.png	1970-01-01 01:00:00.000000000 +0100
+++ mantisbt/images/clock.png	2008-04-09 11:51:57.000000000 +0200
@@ -0,0 +1,8 @@
+�PNG
+
+
IHDR�agAMA��7��tEXtSoftwareAdobe ImageReadyq�e<IDAT8�]�kHSq��}��}�(
+�E�AAЇnA��X��Vd�Y�����դ��tv���<���Z�������.�czt{z�CGu�wxx��y��?7��M#Ԅ�xGLg�ٜɽ�H��s�@����L��X�Z�^+f�?���~;��tg��o%��
+<�\FȚ<06�o�{�)��CA��:�`�߇N�29���R��_�� 8ww>l��6��׌��t�7����M}�پ��	��7EF܏&���M�s�zJf�-�K�S���0�\�u��I�!���}ً�f>Ʌ]�z��d��&�."�^õ�J,.��4���2��I3�(Pd�E�ىzG˅���מ���=�M'��QH��;e��PQxt5/ހ���G0/��v��T�\}`�gD��hc�8����	�/j�R��Tp��
+�e�x��+��J�P���/)T�;ƥ��0o��8�ާ�x^+��e��/<6�i�Fہ�� ~�G��
+��[��app�@�N��yY&^�t�R�E]�����"�taC
+��T�%}N+BŨyY&^��x�r�k���᪾6W݇$+��Ϊ�U�0�L����`��#�ZyÙZ��}���<�nY�z��<�s�c�e#dU����� I�M&~b�R�P�*���-�+�li��B���)0��	��t�����tw�f��3ោi5�¢(���ĂxAUU�L��#��+OA��D� ������ߟ��IEND�B`�
\ No newline at end of file
diff -Naur orig/images/overdue.png mantisbt/images/overdue.png
--- orig/images/overdue.png	1970-01-01 01:00:00.000000000 +0100
+++ mantisbt/images/overdue.png	2008-04-09 11:51:57.000000000 +0200
@@ -0,0 +1,5 @@
+�PNG
+
+
IHDR�agAMA��7��tEXtSoftwareAdobe ImageReadyq�e<,IDAT8�]�kHa�� �2�Z��X$a%I��E�E?�C?*��Q��.YY�M�LKk���R+��4�k��m^�5���]����qLG��|�Y4��o���0��:�rC� >�����ā�6"��92qC�3���3���~[�rK�k�'���E���}G��6M�~1I���H�M-=���(��h�'�[�R�Ǎ�6
V��Pm����zE���N^%1����Fi��tK�z{^��f�s�� |E�������&�ߑ�Ό��%�]�}��S]��r_����9�]e�ӕ3�&ܵ5�d���+! ��:�j�P��y��{��!��6'���Xm�7��|�D��#McW0FCK~P͐�J�Żq�(`g����vې]�x�ĵ�.��d��'dE�ռ|�)(�ݍ�/�Bh��X/s�d
+b��
+��8��R��G=8����	���gXž,X/sV�z.n˵A�oG��RH?��Nd��d��	��ǀ�=��`��H>��_{�}a%޹�h���FT<���$J�x�9�}��z�3�t�n��1�^�"��B-,��~��H��C�0RL�D`�x�����d�5��#%[�ic=�dڇ��pP�De�jt�\	i�2����u�ؿ����w�*=��WH�, ��)J�;ӬMd�8s&���О���ѣ�X��$�Ӊ7f�/qW.f�6`�^���4M\�mS��e�d�&&�*:��\RRC�n�E���i���GxB�o3�4ћ��o��(���PPPE�=Ĵ�e�sԨ:6�b�HM����_5�ӡ��IEND�B`�
\ No newline at end of file
diff -Naur orig/lang/strings_english.txt mantisbt/lang/strings_english.txt
--- orig/lang/strings_english.txt	2008-04-09 11:49:47.000000000 +0200
+++ mantisbt/lang/strings_english.txt	2008-04-10 14:00:52.000000000 +0200
@@ -1511,6 +1511,10 @@
 $s_update_columns_as_my_default = 'Update Columns as Default for All Projects';
 $s_reset_columns_configuration = 'Reset Columns Configuration';
 
+# due date
+$s_due_date = "Due Date";
+$s_overdue = "Overdue";
+
 # mind mapping
 $s_mindmap = 'Mindmap';
 $s_freemind_export = 'Freemind Export';
diff -Naur orig/lang/strings_polish.txt mantisbt/lang/strings_polish.txt
--- orig/lang/strings_polish.txt	2008-03-31 13:44:41.000000000 +0200
+++ mantisbt/lang/strings_polish.txt	2008-04-09 11:51:57.000000000 +0200
@@ -1336,4 +1336,7 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
+$s_due_date = "Termin realizacji";
+$s_overdue = "Przeterminowane";
+
 ?>
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-31 13:44:40.000000000 +0200
+++ mantisbt/lang/strings_polish_8859-2.txt	2008-04-09 11:51:57.000000000 +0200
@@ -1336,4 +1336,7 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
+$s_due_date = "Termin realizacji";
+$s_overdue = "Przeterminowane";
+
 ?>
duedate_stage1_final4.diff (27,538 bytes)   
duedate_stage1_final5.diff (27,627 bytes)   
diff -Naur orig/admin/schema.php mantisbt/admin/schema.php
--- orig/admin/schema.php	2008-03-31 14:05:21.000000000 +0200
+++ mantisbt/admin/schema.php	2008-04-12 11:06:48.000000000 +0200
@@ -383,6 +383,8 @@
 $upgrade[] = Array( 'InsertData', Array( db_get_table( 'mantis_category_table' ), "
 	( project_id, user_id, name, status ) VALUES
 	( '0', '0', 'General', '0' ) " ) );
+
+
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "category_id I UNSIGNED NOTNULL DEFAULT '1'" ) );
 $upgrade[] = Array( 'UpdateFunction', "category_migrate" );
 $upgrade[] = Array( 'DropColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "category" ) );
@@ -402,6 +404,9 @@
 	protected		L		NOTNULL DEFAULT \" '0' \",
 	priority		I		UNSIGNED NOTNULL DEFAULT '3'
 	" ) );
+$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "
+	due_date 		T 		NOTNULL DEFAULT '1970-01-01' " ) );
+
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_version_table' ), "
 	obsolete		L		NOTNULL DEFAULT \" '0' \"" ) );
 
diff -Naur orig/bug_change_status_page.php mantisbt/bug_change_status_page.php
--- orig/bug_change_status_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_change_status_page.php	2008-04-10 13:28:34.000000000 +0200
@@ -52,7 +52,7 @@
 			) ) {
 		access_denied();
 	}
-
+	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
 	# get new issue handler if set, otherwise default to original handler
 	$f_handler_id = gpc_get_int( 'handler_id', bug_get_field( $f_bug_id, 'handler_id' ) );
 
@@ -161,6 +161,27 @@
 </tr>
 <?php } ?>
 
+<!-- Due date -->
+<?php if ( $t_can_update_due_date ) { 
+	date_prepare_calendar();
+	$t_date_to_display = '';
+	if ( ! date_is_null( $t_bug->due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );	
+	}
+?>
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?> <?php print_documentation_link( 'due_date' ) ?>
+	</td>
+	<td>
+	<?php
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+		date_print_calendar( $t_date_to_display );
+	?>
+	</td>
+</tr>
+<?php } ?>
+
 <!-- Custom Fields -->
 <?php
 # @@@ thraxisp - I undid part of the change for #5068 for #5527
@@ -320,6 +341,10 @@
 </form>
 </div>
 
+<?php
+if ( $t_can_update_due_date ) { 
+	date_finish_calendar( 'due_date', 'trigger');
+} ?>
 <br />
 <?php
 	include( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'bug_view_inc.php' );
diff -Naur orig/bug_report.php mantisbt/bug_report.php
--- orig/bug_report.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_report.php	2008-04-09 11:51:57.000000000 +0200
@@ -54,6 +54,10 @@
 	$t_bug_data->description			= gpc_get_string( 'description' );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
+	$t_bug_data->due_date 				= gpc_get_string( 'due_date', '');
+	if ( is_blank ( $t_bug_data->due_date ) ) {
+		$t_bug_data->due_date = date_get_null();
+	}
 
 	$f_file					= gpc_get_file( 'file', null ); #@@@ (thraxisp) Note that this always returns a structure
 															# size = 0, if no file
@@ -188,6 +192,7 @@
 		<input type="hidden" name="build" 		value="<?php echo $t_bug_data->build ?>" />
 		<input type="hidden" name="report_stay" 	value="1" />
 		<input type="hidden" name="view_state"		value="<?php echo $t_bug_data->view_state ?>" />
+		<input type="hidden" name="due_date"		value="<?php echo $t_bug_data->due_date ?>" />
 		<input type="submit" class="button" 		value="<?php echo lang_get( 'report_more_bugs' ) ?>" />
 	</form>
 	</p>
diff -Naur orig/bug_report_advanced_page.php mantisbt/bug_report_advanced_page.php
--- orig/bug_report_advanced_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_report_advanced_page.php	2008-04-10 13:42:32.000000000 +0200
@@ -44,6 +44,8 @@
 		print_header_redirect ( 'bug_report_page.php' .
 						( 0 == $f_master_bug_id ) ? '' : '?m_id=' . $f_master_bug_id );
 	}
+	
+	$t_can_update_due_date = access_has_project_level( config_get( 'due_date_update_threshold' ), helper_get_current_project(), auth_get_current_user_id() );
 
 	if( $f_master_bug_id > 0 ) {
 		# master bug exists...
@@ -114,6 +116,11 @@
 		$f_steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 		$f_additional_info		= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
 		$f_view_state			= gpc_get_int( 'view_state', config_get( 'default_bug_view_status' ) );
+		$f_due_date				=gpc_get_string( 'due_date', '');
+		
+		if ( $f_due_date == '' ) {
+			$f_due_date = date_get_null();
+		}
 
 		$t_project_id			= helper_get_current_project();
 
@@ -209,6 +216,27 @@
 </tr>
 <?php } ?>
 
+<!-- Due date -->
+<?php if ( $t_can_update_due_date ) { 
+date_prepare_calendar();
+	$t_date_to_display = '';
+	if ( ! date_is_null( $f_due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $f_due_date );	
+	}
+
+?>
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?> <?php print_documentation_link( 'due_date' ) ?>
+	</td>
+	<td>
+	<?php
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+		date_print_calendar();
+	?>
+	</td>
+</tr>
+<?php } ?>
 
 <!-- spacer -->
 <tr class="spacer">
@@ -554,6 +582,9 @@
 	window.document.report_bug_form.category_id.focus();
 -->
 </script>
-<?php } ?>
+<?php  }
+if ( $t_can_update_due_date ) { 
+	date_finish_calendar( 'due_date', 'trigger' );
+}
 
-<?php html_page_bottom1( __FILE__ ) ?>
+html_page_bottom1( __FILE__ ) ?>
diff -Naur orig/bug_update.php mantisbt/bug_update.php
--- orig/bug_update.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update.php	2008-04-09 11:51:57.000000000 +0200
@@ -77,7 +77,11 @@
 	$t_bug_data->target_version		= gpc_get_string( 'target_version', $t_bug_data->target_version );
 	$t_bug_data->view_state			= gpc_get_int( 'view_state', $t_bug_data->view_state );
 	$t_bug_data->summary			= gpc_get_string( 'summary', $t_bug_data->summary );
-
+	$t_bug_data->due_date 				= gpc_get_string( 'due_date', $t_bug_data->due_date);
+	if ( is_blank ( $t_bug_data->due_date ) ) {
+		$t_bug_data->due_date = date_get_null( );
+	}
+	
 	$t_bug_data->description		= gpc_get_string( 'description', $t_bug_data->description );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', $t_bug_data->steps_to_reproduce );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_information', $t_bug_data->additional_information );
diff -Naur orig/bug_update_advanced_page.php mantisbt/bug_update_advanced_page.php
--- orig/bug_update_advanced_page.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update_advanced_page.php	2008-04-10 13:57:06.000000000 +0200
@@ -35,7 +35,7 @@
 	$f_bug_id = gpc_get_int( 'bug_id' );
 
 	$t_bug = bug_prepare_edit( 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.
@@ -48,13 +48,13 @@
 	if ( SIMPLE_ONLY == config_get( 'show_update' ) ) {
 		print_header_redirect ( 'bug_update_page.php?bug_id=' . $f_bug_id );
 	}
-
+	
 	if ( bug_is_readonly( $f_bug_id ) ) {
 		error_parameters( $f_bug_id );
 		trigger_error( ERROR_BUG_READ_ONLY_ACTION_DENIED, ERROR );
 	}
 
-	access_ensure_bug_level( config_get( 'update_bug_threshold' ), $f_bug_id );
+	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
 
 	html_page_top1( bug_format_summary( $f_bug_id, SUMMARY_CAPTION ) );
 	html_page_top2();
@@ -189,8 +189,35 @@
 ?>
 	</td>
 
-	<!-- spacer -->
-	<td colspan="2">&nbsp;</td>
+<?php if ( access_has_bug_level( config_get( 'due_date_view_threshold' ), $f_bug_id ) ) { ?>
+	<!-- Due Date -->
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?>
+	</td>
+	<?php 
+	if ( bug_is_overdue( $f_bug_id ) ) {
+		print "<td class=\"overdue\">";
+	} else {
+		print "<td>";
+	}
+	if ( $t_can_update_due_date ) {
+		date_prepare_calendar();
+		$t_date_to_display = '';
+		if ( ! date_is_null( $t_bug->due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
+		}
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+		date_print_calendar( $t_date_to_display );
+	?>
+	</td>
+	<?php } else {
+		if ( $t_bug->due_date != $t_null_date  ) print_date( config_get( 'short_date_format' ), $t_bug->due_date  ); }?>
+	</td>
+<?php } else { ?>
+		<!-- spacer -->
+		<td colspan="2">&nbsp;</td>
+<?php } ?>
+
 </tr>
 
 
@@ -595,6 +622,10 @@
 </form>
 
 <?php
+if ( $t_can_update_due_date ) { 
+	date_finish_calendar( 'due_date', 'trigger');
+}
+
 	include( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'bugnote_view_inc.php' );
 	html_page_bottom1( __FILE__ );
 
diff -Naur orig/bug_update_page.php mantisbt/bug_update_page.php
--- orig/bug_update_page.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update_page.php	2008-04-09 11:51:57.000000000 +0200
@@ -280,6 +280,9 @@
 </tr>
 
 <?php
+	} else {
+		# spacer
+		echo '<td colspan="2">&nbsp;</td>';	
 	}
 ?>
 <?php /*
diff -Naur orig/bug_view_advanced_page.php mantisbt/bug_view_advanced_page.php
--- orig/bug_view_advanced_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_view_advanced_page.php	2008-04-09 12:19:36.000000000 +0200
@@ -217,8 +217,29 @@
 		<?php echo get_enum_element( 'project_view_state', $t_bug->view_state ) ?>
 	</td>
 
-	<!-- spacer -->
-	<td colspan="2">&nbsp;</td>
+	<!-- Due Date -->
+	<?php if ( access_has_bug_level( config_get( 'due_date_view_threshold' ), $f_bug_id ) ) { ?>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?>
+	</td>
+	<?php
+	if ( bug_is_overdue( $f_bug_id ) ) {
+		print "<td class=\"overdue\">";
+	} else {
+		print "<td>";
+	}
+	?>
+		<?php 
+			if ( !date_is_null( $t_bug->due_date ) ) {
+				print_date( config_get( 'short_date_format' ), $t_bug->due_date ); }
+			?>
+	</td>
+	<?php } else { ?>
+		<!-- spacer -->
+		<td colspan="2">&nbsp;</td>
+	<?php
+	}
+	?>
 
 </tr>
 
diff -Naur orig/config_defaults_inc.php mantisbt/config_defaults_inc.php
--- orig/config_defaults_inc.php	2008-04-09 11:49:48.000000000 +0200
+++ mantisbt/config_defaults_inc.php	2008-04-09 12:17:07.000000000 +0200
@@ -1990,6 +1990,17 @@
 	# management threshold.
 	$g_manage_plugin_threshold = ADMINISTRATOR;
 
+ 
+ 	#############################
+ 	# Due Date 
+ 	#############################
+ 
+ 	# threshold to update due date submitted
+ 	$g_due_date_update_threshold = DEVELOPER;
+ 	
+	# threshold to see due date
+ 	$g_due_date_view_threshold = REPORTER;
+
 	#############################
 	# Mind mapping
 	#############################
diff -Naur orig/core/bug_api.php mantisbt/core/bug_api.php
--- orig/core/bug_api.php	2008-03-31 13:45:23.000000000 +0200
+++ mantisbt/core/bug_api.php	2008-04-10 13:53:29.000000000 +0200
@@ -79,6 +79,9 @@
 		
 		#internal helper objects
 		var $_stats = null;
+		
+		#due date
+		var $due_date = '';
 	}
 
 	#===================================
@@ -105,6 +108,8 @@
 			$p_bug_database_result['date_submitted']	= db_unixtimestamp( $p_bug_database_result['date_submitted']['date_submitted'] );
 		if( !is_int( $p_bug_database_result['last_updated'] ) )
 			$p_bug_database_result['last_updated']	= db_unixtimestamp( $p_bug_database_result['last_updated'] );
+		if( !is_int( $p_bug_datebase_result['due_date'] ) ) 
+			$p_bug_datebase_result['due_date']	= db_unixtimestamp( $p_bug_datebase_result['due_date'] );
 		$g_cache_bug[ $p_bug_database_result['id'] ] = $p_bug_database_result;
 		if( !is_null( $p_stats ) ) {
 			$g_cache_bug[ $p_bug_database_result['id'] ]['_stats'] = $p_stats;
@@ -145,6 +150,8 @@
 		$row = db_fetch_array( $result );
 		$row['date_submitted']	= db_unixtimestamp( $row['date_submitted'] );
 		$row['last_updated']	= db_unixtimestamp( $row['last_updated'] );
+		$row['due_date']	= db_unixtimestamp( $row['due_date'] );
+		
 		$g_cache_bug[$c_bug_id] = $row;
 
 		return $row;
@@ -335,6 +342,23 @@
 	}
 
 	# --------------------
+	# Check if the bug is overdue
+	function bug_is_overdue( $p_bug_id ) {
+		$t_bug_row = bug_cache_row( $p_bug_id );
+		$t_due_date = $t_bug_row[ 'due_date' ];
+		if (  ! date_is_null( $t_due_date)  ) {
+			$t_now = db_unixtimestamp();
+			if ( $t_now > $t_due_date ) {
+				if ( bug_is_resolved( $p_bug_id ) ) {
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+
+
+	# --------------------
 	# Validate workflow state to see if bug can be moved to requested state
 	function bug_check_workflow( $p_bug_status, $p_wanted_status ) {
 		$t_status_enum_workflow = config_get( 'status_enum_workflow' );
@@ -393,6 +417,8 @@
 		$c_additional_info		= $p_bug_data->additional_information;
 		$c_sponsorship_total 	= 0;
 		$c_sticky 				= 0;
+		$c_due_date				= $p_bug_data->due_date;
+		
 
 		# Summary cannot be blank
 		if ( is_blank( $c_summary ) ) {
@@ -419,6 +445,17 @@
 			$c_target_version	= '';
 		}
 
+		#check due_date format
+		if ( !is_blank( $p_bug_data->due_date ) ) {
+			if ( !is_int( $p_bug_data->due_date ) ) {
+				$t_tmp = strtotime( $p_bug_data->due_date);
+				$c_due_date = date ( 'Y-m-d 00:00:01', $t_tmp );
+			} else {
+				$c_due_date = date ( 'Y-m-d H:i:s', $p_bug_data->due_date );
+			}
+		}
+
+
 		$t_bug_table				= db_get_table( 'mantis_bug_table' );
 		$t_bug_text_table			= db_get_table( 'mantis_bug_text_table' );
 		$t_category_table			= db_get_table( 'mantis_category_table' );
@@ -474,7 +511,7 @@
 				      platform, version,
 				      build,
 				      profile_id, summary, view_state, sponsorship_total, sticky, fixed_in_version,
-				      target_version 
+				      target_version, due_date 
 				    )
 				  VALUES
 				    ( " . db_param(0) . ",
@@ -503,10 +540,11 @@
 				      " . db_param(23) . ",
 				      " . db_param(24) . ",
 				      " . db_param(25) . ",
-				      " . db_param(26) . ")";
+				      " . db_param(26) . ",
+				      " . db_param(27) . ")";
 		db_query_bound( $query, Array( $c_project_id, $c_reporter_id, $c_handler_id, 0, $c_priority, $c_severity, $c_reproducibility, $t_status,
 								 $t_resolution, 10, $c_category_id, db_now(), db_now(), 10, $t_text_id, $c_os, $c_os_build, $c_platform, $c_version,$c_build,
-								 $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version ) );
+								 $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version, $c_due_date) );
 
 		$t_bug_id = db_insert_id($t_bug_table);
 
@@ -569,6 +607,7 @@
 		bug_set_field( $t_new_bug_id, 'target_version', $t_bug_data->target_version );
 		bug_set_field( $t_new_bug_id, 'sponsorship_total', 0 );
 		bug_set_field( $t_new_bug_id, 'sticky', 0 );
+		bug_set_field( $t_new_bug_id, 'due_date', $t_bug_data->due_date );
 
 		# COPY CUSTOM FIELDS
 		if ( $p_copy_custom_fields ) {
@@ -898,6 +937,16 @@
 		$t_fields[] = $c_bug_id;
 		
 		db_query_bound( $query, $t_fields );
+		
+		if ( !is_blank( $p_bug_data->due_date ) ) {
+			if ( !is_int( $p_bug_data->due_date ) ) {
+				$t_format = strtotime( $p_bug_data->due_date);
+				$p_bug_data->due_date = date ( 'Y-m-d 00:00:01', $t_format );
+			} else {
+				$p_bug_data->due_date = date ( 'Y-m-d H:i:s', $p_bug_data->due_date );
+			}
+			bug_set_field( $p_bug_id, 'due_date', $p_bug_data->due_date);
+		}
 
 		bug_clear_cache( $p_bug_id );
 
@@ -1190,17 +1239,34 @@
 		$c_status		=  $p_status; #generic, unknown type
 
 		$h_status = bug_get_field( $p_bug_id, $p_field_name );
+		
+		if ( $p_field_name == 'due_date' ) {
+			if ( !date_is_null( $h_status )  ) {
+				$h_status = date( config_get ( 'short_date_format' ), $h_status );
+			} else {
+				$h_status = '';
+			}
+			$t_tmp = $p_status;
+			if ( !is_int( $p_status ) ) {
+				$t_tmp = strtotime( $p_status );
+			} 
+			if ( !date_is_null( $t_tmp ) ) {
+				$c_status = date( 'Y-m-d 00:00:01', $t_tmp );
+			} else {
+				$c_status = '';
+			}
+			$c_field_name = lang_get( 'due_date' );
+		}
 
 		# return if status is already set
 		if ( $c_status == $h_status ) {
 			return true;
 		}
-
 		$t_bug_table = db_get_table( 'mantis_bug_table' );
 
 		# Update fields
 		$query = "UPDATE $t_bug_table
-				  SET $c_field_name=" . db_param(0) . "
+				  SET $p_field_name=" . db_param(0) . "
 				  WHERE id=" .db_param(1);
 		db_query_bound( $query, Array( $c_status, $c_bug_id ) );
 
@@ -1210,7 +1276,7 @@
 		# log changes except for duplicate_id which is obsolete and should be removed in
 		# Mantis 1.3.
 		if ( $p_field_name != 'duplicate_id' ) {
-			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $p_status );
+			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $c_status );
 		}
 
 		bug_clear_cache( $p_bug_id );
@@ -1497,6 +1563,7 @@
 		$p_bug_data->summary			= string_attribute( $p_bug_data->summary );
 		$p_bug_data->sponsorship_total	= string_attribute( $p_bug_data->sponsorship_total );
 		$p_bug_data->sticky				= string_attribute( $p_bug_data->sticky );
+		$p_bug_data->due_date			= string_attribute( $p_bug_data->due_date );
 
 		$p_bug_data->description		= string_textarea( $p_bug_data->description );
 		$p_bug_data->steps_to_reproduce	= string_textarea( $p_bug_data->steps_to_reproduce );
@@ -1522,6 +1589,7 @@
 		$p_bug_data->summary			= string_display_line_links( $p_bug_data->summary );
 		$p_bug_data->sponsorship_total	= string_display_line( $p_bug_data->sponsorship_total );
 		$p_bug_data->sticky				= string_display_line( $p_bug_data->sticky );
+		$p_bug_data->due_date			= string_display_line( $p_bug_data->due_date );
 
 		$p_bug_data->description		= string_display_links( $p_bug_data->description );
 		$p_bug_data->steps_to_reproduce	= string_display_links( $p_bug_data->steps_to_reproduce );
diff -Naur orig/core/columns_api.php mantisbt/core/columns_api.php
--- orig/core/columns_api.php	2008-03-31 13:45:24.000000000 +0200
+++ mantisbt/core/columns_api.php	2008-04-09 12:27:32.000000000 +0200
@@ -501,8 +501,12 @@
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function print_column_edit( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 		global $t_icon_path, $t_update_bug_threshold;
-
-		echo '<td>';
+		
+		if ( bug_is_overdue( $p_row['id'] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] )) {
+			print "<td class=\"overdue\">";
+		} else {
+			echo '<td>';
+		}
 		if ( !bug_is_readonly( $p_row['id'] )
 			&& access_has_bug_level( $t_update_bug_threshold, $p_row['id'] ) ) {
 			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
@@ -512,6 +516,20 @@
 		} else {
 			echo '&nbsp;';
 		}
+		if ( bug_is_overdue( $p_row['id'] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] ) ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdue.png';
+			echo '" alt="' . lang_get( 'overdue' ) . '"';
+			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
+		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] )) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
+			echo '" alt="' . lang_get( 'due_date' ) . '"';
+			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
+		} else {
+			echo '&nbsp;';
+		}
+		
 		echo '</td>';
 	}
 
diff -Naur orig/core/date_api.php mantisbt/core/date_api.php
--- orig/core/date_api.php	2008-03-31 13:45:23.000000000 +0200
+++ mantisbt/core/date_api.php	2008-04-10 13:46:29.000000000 +0200
@@ -22,6 +22,20 @@
 	# --------------------------------------------------------
 
 	### Date API ###
+	# --------------------
+	# checks if date is null
+	function date_is_null ( $p_date ) {
+		if ( $p_date == date_get_null( ) ) {
+			return true;
+		}
+		return false;
+	}
+	
+	# --------------------
+	# gets null date 
+	function date_get_null ( ) {
+		return db_unixtimestamp( '1970-01-01 00:00:01' );
+	}
 
 	# --------------------
 	# prints the date given the formating string
@@ -149,4 +163,44 @@
 			}
 		}
 	}
+	
+	function date_prepare_calendar () {
+	# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			echo "<style type=\"text/css\">@import url(javascript/jscalendar/calendar-blue.css);</style>\n";
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/lang/calendar-en.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar-setup.js\"></script>\n"; 	
+		}	
+	}
+	function date_print_calendar ( $p_date = null, $p_button_name = 'trigger' ) {
+		# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			$t_icon_path = config_get( 'icon_path' );
+			$t_cal_icon = $t_icon_path ."calendar-img.gif";	
+	   	 	echo "<input type=\"image\" class=\"button\" id=\"".$p_button_name."\" SRC=\"";
+	    	echo $t_cal_icon;
+			$t_format = config_get( 'short_date_format' );
+			$t_new_format = str_replace( '-', '-%', $t_format );
+			$t_format = "%".$t_new_format;
+			echo "\" onClick=\"return showCalendar ('sel1', '".$t_format."', 24, true)\" />";
+		}
+	}
+	function date_finish_calendar ( $p_field_name, $p_button_name) {
+	# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			$t_format = config_get( 'short_date_format' );
+			$t_new_format = str_replace( '-', '-%', $t_format );
+			$t_format = "%".$t_new_format;
+			echo "<script type=\"text/javascript\">\n";
+			echo "Calendar.setup (\n";
+			echo "{\n";
+		 	echo "inputField 	: \"".$p_field_name."\",\n";
+		 	echo "ifFormat 	: \"".$t_format."\", \n";
+		 	echo "button		: \"".$p_button_name."\"\n";
+			echo "}\n";
+			echo ");\n";
+			echo "</script>\n";
+			}	
+	}
 ?>
diff -Naur orig/core/filter_api.php mantisbt/core/filter_api.php
--- orig/core/filter_api.php	2008-04-09 11:49:48.000000000 +0200
+++ mantisbt/core/filter_api.php	2008-04-09 11:51:57.000000000 +0200
@@ -1537,6 +1537,7 @@
 			
 			$row['date_submitted'] = db_unixtimestamp ( $row['date_submitted'] );
 			$row['last_updated'] = db_unixtimestamp ( $row['last_updated'] );
+			$row['due_date']	= db_unixtimestamp( $row['due_date'] );
 					
 			array_push( $rows, $row );
 		}
diff -Naur orig/css/default.css mantisbt/css/default.css
--- orig/css/default.css	2008-04-09 11:49:47.000000000 +0200
+++ mantisbt/css/default.css	2008-04-09 11:51:57.000000000 +0200
@@ -52,6 +52,7 @@
 td.left				{ text-align: left; }
 td.right			{ text-align: right; }
 td.category			{ background-color: #c8c8e8; color: #000000; font-weight: bold; vertical-align : top; }
+td.overdue			{ background-color: #ff0000; color: #000000; font-weight: bold; }
 
 td.col-1			{ background-color: #d8d8d8; color: #000000; }
 td.col-2			{ background-color: #e8e8e8; color: #000000; }
diff -Naur orig/images/clock.png mantisbt/images/clock.png
--- orig/images/clock.png	1970-01-01 01:00:00.000000000 +0100
+++ mantisbt/images/clock.png	2008-04-09 11:51:57.000000000 +0200
@@ -0,0 +1,8 @@
+�PNG
+
+
IHDR�agAMA��7��tEXtSoftwareAdobe ImageReadyq�e<IDAT8�]�kHSq��}��}�(
+�E�AAЇnA��X��Vd�Y�����դ��tv���<���Z�������.�czt{z�CGu�wxx��y��?7��M#Ԅ�xGLg�ٜɽ�H��s�@����L��X�Z�^+f�?���~;��tg��o%��
+<�\FȚ<06�o�{�)��CA��:�`�߇N�29���R��_�� 8ww>l��6��׌��t�7����M}�پ��	��7EF܏&���M�s�zJf�-�K�S���0�\�u��I�!���}ً�f>Ʌ]�z��d��&�."�^õ�J,.��4���2��I3�(Pd�E�ىzG˅���מ���=�M'��QH��;e��PQxt5/ހ���G0/��v��T�\}`�gD��hc�8����	�/j�R��Tp��
+�e�x��+��J�P���/)T�;ƥ��0o��8�ާ�x^+��e��/<6�i�Fہ�� ~�G��
+��[��app�@�N��yY&^�t�R�E]�����"�taC
+��T�%}N+BŨyY&^��x�r�k���᪾6W݇$+��Ϊ�U�0�L����`��#�ZyÙZ��}���<�nY�z��<�s�c�e#dU����� I�M&~b�R�P�*���-�+�li��B���)0��	��t�����tw�f��3ោi5�¢(���ĂxAUU�L��#��+OA��D� ������ߟ��IEND�B`�
\ No newline at end of file
diff -Naur orig/images/overdue.png mantisbt/images/overdue.png
--- orig/images/overdue.png	1970-01-01 01:00:00.000000000 +0100
+++ mantisbt/images/overdue.png	2008-04-09 11:51:57.000000000 +0200
@@ -0,0 +1,5 @@
+�PNG
+
+
IHDR�agAMA��7��tEXtSoftwareAdobe ImageReadyq�e<,IDAT8�]�kHa�� �2�Z��X$a%I��E�E?�C?*��Q��.YY�M�LKk���R+��4�k��m^�5���]����qLG��|�Y4��o���0��:�rC� >�����ā�6"��92qC�3���3���~[�rK�k�'���E���}G��6M�~1I���H�M-=���(��h�'�[�R�Ǎ�6
V��Pm����zE���N^%1����Fi��tK�z{^��f�s�� |E�������&�ߑ�Ό��%�]�}��S]��r_����9�]e�ӕ3�&ܵ5�d���+! ��:�j�P��y��{��!��6'���Xm�7��|�D��#McW0FCK~P͐�J�Żq�(`g����vې]�x�ĵ�.��d��'dE�ռ|�)(�ݍ�/�Bh��X/s�d
+b��
+��8��R��G=8����	���gXž,X/sV�z.n˵A�oG��RH?��Nd��d��	��ǀ�=��`��H>��_{�}a%޹�h���FT<���$J�x�9�}��z�3�t�n��1�^�"��B-,��~��H��C�0RL�D`�x�����d�5��#%[�ic=�dڇ��pP�De�jt�\	i�2����u�ؿ����w�*=��WH�, ��)J�;ӬMd�8s&���О���ѣ�X��$�Ӊ7f�/qW.f�6`�^���4M\�mS��e�d�&&�*:��\RRC�n�E���i���GxB�o3�4ћ��o��(���PPPE�=Ĵ�e�sԨ:6�b�HM����_5�ӡ��IEND�B`�
\ No newline at end of file
diff -Naur orig/lang/strings_english.txt mantisbt/lang/strings_english.txt
--- orig/lang/strings_english.txt	2008-04-09 11:49:47.000000000 +0200
+++ mantisbt/lang/strings_english.txt	2008-04-10 14:00:52.000000000 +0200
@@ -1511,6 +1511,10 @@
 $s_update_columns_as_my_default = 'Update Columns as Default for All Projects';
 $s_reset_columns_configuration = 'Reset Columns Configuration';
 
+# due date
+$s_due_date = "Due Date";
+$s_overdue = "Overdue";
+
 # mind mapping
 $s_mindmap = 'Mindmap';
 $s_freemind_export = 'Freemind Export';
diff -Naur orig/lang/strings_polish.txt mantisbt/lang/strings_polish.txt
--- orig/lang/strings_polish.txt	2008-03-31 13:44:41.000000000 +0200
+++ mantisbt/lang/strings_polish.txt	2008-04-09 11:51:57.000000000 +0200
@@ -1336,4 +1336,7 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
+$s_due_date = "Termin realizacji";
+$s_overdue = "Przeterminowane";
+
 ?>
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-31 13:44:40.000000000 +0200
+++ mantisbt/lang/strings_polish_8859-2.txt	2008-04-09 11:51:57.000000000 +0200
@@ -1336,4 +1336,7 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
+$s_due_date = "Termin realizacji";
+$s_overdue = "Przeterminowane";
+
 ?>
duedate_stage1_final5.diff (27,627 bytes)   
duedate_stage1_final6.diff (27,639 bytes)   
diff -Naur orig/admin/schema.php mantisbt/admin/schema.php
--- orig/admin/schema.php	2008-03-31 14:05:21.000000000 +0200
+++ mantisbt/admin/schema.php	2008-04-13 10:14:02.000000000 +0200
@@ -383,6 +383,8 @@
 $upgrade[] = Array( 'InsertData', Array( db_get_table( 'mantis_category_table' ), "
 	( project_id, user_id, name, status ) VALUES
 	( '0', '0', 'General', '0' ) " ) );
+
+
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "category_id I UNSIGNED NOTNULL DEFAULT '1'" ) );
 $upgrade[] = Array( 'UpdateFunction', "category_migrate" );
 $upgrade[] = Array( 'DropColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "category" ) );
@@ -402,6 +404,9 @@
 	protected		L		NOTNULL DEFAULT \" '0' \",
 	priority		I		UNSIGNED NOTNULL DEFAULT '3'
 	" ) );
+
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_version_table' ), "
 	obsolete		L		NOTNULL DEFAULT \" '0' \"" ) );
 
+$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "
+	due_date 		T 		NOTNULL DEFAULT '1970-01-01' " ) );
diff -Naur orig/bug_change_status_page.php mantisbt/bug_change_status_page.php
--- orig/bug_change_status_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_change_status_page.php	2008-04-13 10:31:46.000000000 +0200
@@ -52,7 +52,7 @@
 			) ) {
 		access_denied();
 	}
-
+	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
 	# get new issue handler if set, otherwise default to original handler
 	$f_handler_id = gpc_get_int( 'handler_id', bug_get_field( $f_bug_id, 'handler_id' ) );
 
@@ -161,6 +161,26 @@
 </tr>
 <?php } ?>
 
+<!-- Due date -->
+<?php if ( $t_can_update_due_date ) {
+	$t_date_to_display = '';
+	if ( ! date_is_null( $t_bug->due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
+	}
+?>
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?> <?php print_documentation_link( 'due_date' ) ?>
+	</td>
+	<td>
+	<?php
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+		date_print_calendar( );
+	?>
+	</td>
+</tr>
+<?php } ?>
+
 <!-- Custom Fields -->
 <?php
 # @@@ thraxisp - I undid part of the change for #5068 for #5527
@@ -320,6 +340,10 @@
 </form>
 </div>
 
+<?php
+if ( $t_can_update_due_date ) {
+	date_finish_calendar( 'due_date', 'trigger');
+} ?>
 <br />
 <?php
 	include( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'bug_view_inc.php' );
diff -Naur orig/bug_report.php mantisbt/bug_report.php
--- orig/bug_report.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_report.php	2008-04-13 10:14:02.000000000 +0200
@@ -54,6 +54,10 @@
 	$t_bug_data->description			= gpc_get_string( 'description' );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
+	$t_bug_data->due_date 				= gpc_get_string( 'due_date', '');
+	if ( is_blank ( $t_bug_data->due_date ) ) {
+		$t_bug_data->due_date = date_get_null();
+	}
 
 	$f_file					= gpc_get_file( 'file', null ); #@@@ (thraxisp) Note that this always returns a structure
 															# size = 0, if no file
@@ -188,6 +192,7 @@
 		<input type="hidden" name="build" 		value="<?php echo $t_bug_data->build ?>" />
 		<input type="hidden" name="report_stay" 	value="1" />
 		<input type="hidden" name="view_state"		value="<?php echo $t_bug_data->view_state ?>" />
+		<input type="hidden" name="due_date"		value="<?php echo $t_bug_data->due_date ?>" />
 		<input type="submit" class="button" 		value="<?php echo lang_get( 'report_more_bugs' ) ?>" />
 	</form>
 	</p>
diff -Naur orig/bug_report_advanced_page.php mantisbt/bug_report_advanced_page.php
--- orig/bug_report_advanced_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_report_advanced_page.php	2008-04-13 10:25:43.000000000 +0200
@@ -45,6 +45,8 @@
 						( 0 == $f_master_bug_id ) ? '' : '?m_id=' . $f_master_bug_id );
 	}
 
+	$t_can_update_due_date = access_has_project_level( config_get( 'due_date_update_threshold' ), helper_get_current_project(), auth_get_current_user_id() );
+
 	if( $f_master_bug_id > 0 ) {
 		# master bug exists...
 		bug_ensure_exists( $f_master_bug_id );
@@ -114,6 +116,11 @@
 		$f_steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 		$f_additional_info		= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
 		$f_view_state			= gpc_get_int( 'view_state', config_get( 'default_bug_view_status' ) );
+		$f_due_date				=gpc_get_string( 'due_date', '');
+
+		if ( $f_due_date == '' ) {
+			$f_due_date = date_get_null();
+		}
 
 		$t_project_id			= helper_get_current_project();
 
@@ -209,6 +216,26 @@
 </tr>
 <?php } ?>
 
+<!-- Due date -->
+<?php if ( $t_can_update_due_date ) { 
+	$t_date_to_display = '';
+	if ( ! date_is_null( $f_due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $f_due_date );	
+	}
+
+?>
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?> <?php print_documentation_link( 'due_date' ) ?>
+	</td>
+	<td>
+	<?php
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+		date_print_calendar();
+	?>
+	</td>
+</tr>
+<?php } ?>
 
 <!-- spacer -->
 <tr class="spacer">
@@ -554,6 +581,9 @@
 	window.document.report_bug_form.category_id.focus();
 -->
 </script>
-<?php } ?>
+<?php  }
+if ( $t_can_update_due_date ) { 
+	date_finish_calendar( 'due_date', 'trigger' );
+}
 
-<?php html_page_bottom1( __FILE__ ) ?>
+html_page_bottom1( __FILE__ ) ?>
diff -Naur orig/bug_update.php mantisbt/bug_update.php
--- orig/bug_update.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update.php	2008-04-13 10:14:02.000000000 +0200
@@ -77,7 +77,11 @@
 	$t_bug_data->target_version		= gpc_get_string( 'target_version', $t_bug_data->target_version );
 	$t_bug_data->view_state			= gpc_get_int( 'view_state', $t_bug_data->view_state );
 	$t_bug_data->summary			= gpc_get_string( 'summary', $t_bug_data->summary );
-
+	$t_bug_data->due_date 				= gpc_get_string( 'due_date', $t_bug_data->due_date);
+	if ( is_blank ( $t_bug_data->due_date ) ) {
+		$t_bug_data->due_date = date_get_null( );
+	}
+	
 	$t_bug_data->description		= gpc_get_string( 'description', $t_bug_data->description );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', $t_bug_data->steps_to_reproduce );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_information', $t_bug_data->additional_information );
diff -Naur orig/bug_update_advanced_page.php mantisbt/bug_update_advanced_page.php
--- orig/bug_update_advanced_page.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update_advanced_page.php	2008-04-13 10:34:02.000000000 +0200
@@ -35,7 +35,7 @@
 	$f_bug_id = gpc_get_int( 'bug_id' );
 
 	$t_bug = bug_prepare_edit( 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.
@@ -48,13 +48,13 @@
 	if ( SIMPLE_ONLY == config_get( 'show_update' ) ) {
 		print_header_redirect ( 'bug_update_page.php?bug_id=' . $f_bug_id );
 	}
-
+	
 	if ( bug_is_readonly( $f_bug_id ) ) {
 		error_parameters( $f_bug_id );
 		trigger_error( ERROR_BUG_READ_ONLY_ACTION_DENIED, ERROR );
 	}
 
-	access_ensure_bug_level( config_get( 'update_bug_threshold' ), $f_bug_id );
+	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
 
 	html_page_top1( bug_format_summary( $f_bug_id, SUMMARY_CAPTION ) );
 	html_page_top2();
@@ -189,8 +189,34 @@
 ?>
 	</td>
 
-	<!-- spacer -->
-	<td colspan="2">&nbsp;</td>
+<?php if ( access_has_bug_level( config_get( 'due_date_view_threshold' ), $f_bug_id ) ) { ?>
+	<!-- Due Date -->
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?>
+	</td>
+	<?php 
+	if ( bug_is_overdue( $f_bug_id ) ) {
+		print "<td class=\"overdue\">";
+	} else {
+		print "<td>";
+	}
+	if ( $t_can_update_due_date ) {
+		$t_date_to_display = '';
+		if ( ! date_is_null( $t_bug->due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
+		}
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+		date_print_calendar( );
+	?>
+	</td>
+	<?php } else {
+		if ( $t_bug->due_date != $t_null_date  ) print_date( config_get( 'short_date_format' ), $t_bug->due_date  ); }?>
+	</td>
+<?php } else { ?>
+		<!-- spacer -->
+		<td colspan="2">&nbsp;</td>
+<?php } ?>
+
 </tr>
 
 
@@ -595,6 +621,10 @@
 </form>
 
 <?php
+if ( $t_can_update_due_date ) { 
+	date_finish_calendar( 'due_date', 'trigger');
+}
+
 	include( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'bugnote_view_inc.php' );
 	html_page_bottom1( __FILE__ );
 
diff -Naur orig/bug_update_page.php mantisbt/bug_update_page.php
--- orig/bug_update_page.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update_page.php	2008-04-13 10:14:02.000000000 +0200
@@ -280,6 +280,9 @@
 </tr>
 
 <?php
+	} else {
+		# spacer
+		echo '<td colspan="2">&nbsp;</td>';	
 	}
 ?>
 <?php /*
diff -Naur orig/bug_view_advanced_page.php mantisbt/bug_view_advanced_page.php
--- orig/bug_view_advanced_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_view_advanced_page.php	2008-04-13 10:14:02.000000000 +0200
@@ -217,8 +217,29 @@
 		<?php echo get_enum_element( 'project_view_state', $t_bug->view_state ) ?>
 	</td>
 
-	<!-- spacer -->
-	<td colspan="2">&nbsp;</td>
+	<!-- Due Date -->
+	<?php if ( access_has_bug_level( config_get( 'due_date_view_threshold' ), $f_bug_id ) ) { ?>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?>
+	</td>
+	<?php
+	if ( bug_is_overdue( $f_bug_id ) ) {
+		print "<td class=\"overdue\">";
+	} else {
+		print "<td>";
+	}
+	?>
+		<?php 
+			if ( !date_is_null( $t_bug->due_date ) ) {
+				print_date( config_get( 'short_date_format' ), $t_bug->due_date ); }
+			?>
+	</td>
+	<?php } else { ?>
+		<!-- spacer -->
+		<td colspan="2">&nbsp;</td>
+	<?php
+	}
+	?>
 
 </tr>
 
diff -Naur orig/config_defaults_inc.php mantisbt/config_defaults_inc.php
--- orig/config_defaults_inc.php	2008-04-09 11:49:48.000000000 +0200
+++ mantisbt/config_defaults_inc.php	2008-04-13 10:14:02.000000000 +0200
@@ -1990,6 +1990,17 @@
 	# management threshold.
 	$g_manage_plugin_threshold = ADMINISTRATOR;
 
+ 
+ 	#############################
+ 	# Due Date 
+ 	#############################
+ 
+ 	# threshold to update due date submitted
+ 	$g_due_date_update_threshold = DEVELOPER;
+ 	
+	# threshold to see due date
+ 	$g_due_date_view_threshold = REPORTER;
+
 	#############################
 	# Mind mapping
 	#############################
diff -Naur orig/core/bug_api.php mantisbt/core/bug_api.php
--- orig/core/bug_api.php	2008-03-31 13:45:23.000000000 +0200
+++ mantisbt/core/bug_api.php	2008-04-13 10:14:02.000000000 +0200
@@ -79,6 +79,9 @@
 		
 		#internal helper objects
 		var $_stats = null;
+		
+		#due date
+		var $due_date = '';
 	}
 
 	#===================================
@@ -105,6 +108,8 @@
 			$p_bug_database_result['date_submitted']	= db_unixtimestamp( $p_bug_database_result['date_submitted']['date_submitted'] );
 		if( !is_int( $p_bug_database_result['last_updated'] ) )
 			$p_bug_database_result['last_updated']	= db_unixtimestamp( $p_bug_database_result['last_updated'] );
+		if( !is_int( $p_bug_datebase_result['due_date'] ) ) 
+			$p_bug_datebase_result['due_date']	= db_unixtimestamp( $p_bug_datebase_result['due_date'] );
 		$g_cache_bug[ $p_bug_database_result['id'] ] = $p_bug_database_result;
 		if( !is_null( $p_stats ) ) {
 			$g_cache_bug[ $p_bug_database_result['id'] ]['_stats'] = $p_stats;
@@ -145,6 +150,8 @@
 		$row = db_fetch_array( $result );
 		$row['date_submitted']	= db_unixtimestamp( $row['date_submitted'] );
 		$row['last_updated']	= db_unixtimestamp( $row['last_updated'] );
+		$row['due_date']	= db_unixtimestamp( $row['due_date'] );
+		
 		$g_cache_bug[$c_bug_id] = $row;
 
 		return $row;
@@ -335,6 +342,23 @@
 	}
 
 	# --------------------
+	# Check if the bug is overdue
+	function bug_is_overdue( $p_bug_id ) {
+		$t_bug_row = bug_cache_row( $p_bug_id );
+		$t_due_date = $t_bug_row[ 'due_date' ];
+		if (  ! date_is_null( $t_due_date)  ) {
+			$t_now = db_unixtimestamp();
+			if ( $t_now > $t_due_date ) {
+				if ( bug_is_resolved( $p_bug_id ) ) {
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+
+
+	# --------------------
 	# Validate workflow state to see if bug can be moved to requested state
 	function bug_check_workflow( $p_bug_status, $p_wanted_status ) {
 		$t_status_enum_workflow = config_get( 'status_enum_workflow' );
@@ -393,6 +417,8 @@
 		$c_additional_info		= $p_bug_data->additional_information;
 		$c_sponsorship_total 	= 0;
 		$c_sticky 				= 0;
+		$c_due_date				= $p_bug_data->due_date;
+		
 
 		# Summary cannot be blank
 		if ( is_blank( $c_summary ) ) {
@@ -419,6 +445,17 @@
 			$c_target_version	= '';
 		}
 
+		#check due_date format
+		if ( !is_blank( $p_bug_data->due_date ) ) {
+			if ( !is_int( $p_bug_data->due_date ) ) {
+				$t_tmp = strtotime( $p_bug_data->due_date);
+				$c_due_date = date ( 'Y-m-d 00:00:01', $t_tmp );
+			} else {
+				$c_due_date = date ( 'Y-m-d H:i:s', $p_bug_data->due_date );
+			}
+		}
+
+
 		$t_bug_table				= db_get_table( 'mantis_bug_table' );
 		$t_bug_text_table			= db_get_table( 'mantis_bug_text_table' );
 		$t_category_table			= db_get_table( 'mantis_category_table' );
@@ -474,7 +511,7 @@
 				      platform, version,
 				      build,
 				      profile_id, summary, view_state, sponsorship_total, sticky, fixed_in_version,
-				      target_version 
+				      target_version, due_date 
 				    )
 				  VALUES
 				    ( " . db_param(0) . ",
@@ -503,10 +540,11 @@
 				      " . db_param(23) . ",
 				      " . db_param(24) . ",
 				      " . db_param(25) . ",
-				      " . db_param(26) . ")";
+				      " . db_param(26) . ",
+				      " . db_param(27) . ")";
 		db_query_bound( $query, Array( $c_project_id, $c_reporter_id, $c_handler_id, 0, $c_priority, $c_severity, $c_reproducibility, $t_status,
 								 $t_resolution, 10, $c_category_id, db_now(), db_now(), 10, $t_text_id, $c_os, $c_os_build, $c_platform, $c_version,$c_build,
-								 $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version ) );
+								 $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version, $c_due_date) );
 
 		$t_bug_id = db_insert_id($t_bug_table);
 
@@ -569,6 +607,7 @@
 		bug_set_field( $t_new_bug_id, 'target_version', $t_bug_data->target_version );
 		bug_set_field( $t_new_bug_id, 'sponsorship_total', 0 );
 		bug_set_field( $t_new_bug_id, 'sticky', 0 );
+		bug_set_field( $t_new_bug_id, 'due_date', $t_bug_data->due_date );
 
 		# COPY CUSTOM FIELDS
 		if ( $p_copy_custom_fields ) {
@@ -898,6 +937,16 @@
 		$t_fields[] = $c_bug_id;
 		
 		db_query_bound( $query, $t_fields );
+		
+		if ( !is_blank( $p_bug_data->due_date ) ) {
+			if ( !is_int( $p_bug_data->due_date ) ) {
+				$t_format = strtotime( $p_bug_data->due_date);
+				$p_bug_data->due_date = date ( 'Y-m-d 00:00:01', $t_format );
+			} else {
+				$p_bug_data->due_date = date ( 'Y-m-d H:i:s', $p_bug_data->due_date );
+			}
+			bug_set_field( $p_bug_id, 'due_date', $p_bug_data->due_date);
+		}
 
 		bug_clear_cache( $p_bug_id );
 
@@ -1190,17 +1239,34 @@
 		$c_status		=  $p_status; #generic, unknown type
 
 		$h_status = bug_get_field( $p_bug_id, $p_field_name );
+		
+		if ( $p_field_name == 'due_date' ) {
+			if ( !date_is_null( $h_status )  ) {
+				$h_status = date( config_get ( 'short_date_format' ), $h_status );
+			} else {
+				$h_status = '';
+			}
+			$t_tmp = $p_status;
+			if ( !is_int( $p_status ) ) {
+				$t_tmp = strtotime( $p_status );
+			} 
+			if ( !date_is_null( $t_tmp ) ) {
+				$c_status = date( 'Y-m-d 00:00:01', $t_tmp );
+			} else {
+				$c_status = '';
+			}
+			$c_field_name = lang_get( 'due_date' );
+		}
 
 		# return if status is already set
 		if ( $c_status == $h_status ) {
 			return true;
 		}
-
 		$t_bug_table = db_get_table( 'mantis_bug_table' );
 
 		# Update fields
 		$query = "UPDATE $t_bug_table
-				  SET $c_field_name=" . db_param(0) . "
+				  SET $p_field_name=" . db_param(0) . "
 				  WHERE id=" .db_param(1);
 		db_query_bound( $query, Array( $c_status, $c_bug_id ) );
 
@@ -1210,7 +1276,7 @@
 		# log changes except for duplicate_id which is obsolete and should be removed in
 		# Mantis 1.3.
 		if ( $p_field_name != 'duplicate_id' ) {
-			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $p_status );
+			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $c_status );
 		}
 
 		bug_clear_cache( $p_bug_id );
@@ -1497,6 +1563,7 @@
 		$p_bug_data->summary			= string_attribute( $p_bug_data->summary );
 		$p_bug_data->sponsorship_total	= string_attribute( $p_bug_data->sponsorship_total );
 		$p_bug_data->sticky				= string_attribute( $p_bug_data->sticky );
+		$p_bug_data->due_date			= string_attribute( $p_bug_data->due_date );
 
 		$p_bug_data->description		= string_textarea( $p_bug_data->description );
 		$p_bug_data->steps_to_reproduce	= string_textarea( $p_bug_data->steps_to_reproduce );
@@ -1522,6 +1589,7 @@
 		$p_bug_data->summary			= string_display_line_links( $p_bug_data->summary );
 		$p_bug_data->sponsorship_total	= string_display_line( $p_bug_data->sponsorship_total );
 		$p_bug_data->sticky				= string_display_line( $p_bug_data->sticky );
+		$p_bug_data->due_date			= string_display_line( $p_bug_data->due_date );
 
 		$p_bug_data->description		= string_display_links( $p_bug_data->description );
 		$p_bug_data->steps_to_reproduce	= string_display_links( $p_bug_data->steps_to_reproduce );
diff -Naur orig/core/columns_api.php mantisbt/core/columns_api.php
--- orig/core/columns_api.php	2008-04-13 10:12:16.000000000 +0200
+++ mantisbt/core/columns_api.php	2008-04-13 10:14:02.000000000 +0200
@@ -521,8 +521,12 @@
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function print_column_edit( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 		global $t_icon_path, $t_update_bug_threshold;
-
-		echo '<td>';
+		
+		if ( bug_is_overdue( $p_row['id'] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] )) {
+			print "<td class=\"overdue\">";
+		} else {
+			echo '<td>';
+		}
 		if ( !bug_is_readonly( $p_row['id'] )
 			&& access_has_bug_level( $t_update_bug_threshold, $p_row['id'] ) ) {
 			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
@@ -532,6 +536,20 @@
 		} else {
 			echo '&nbsp;';
 		}
+		if ( bug_is_overdue( $p_row['id'] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] ) ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdue.png';
+			echo '" alt="' . lang_get( 'overdue' ) . '"';
+			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
+		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] )) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
+			echo '" alt="' . lang_get( 'due_date' ) . '"';
+			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
+		} else {
+			echo '&nbsp;';
+		}
+		
 		echo '</td>';
 	}
 
diff -Naur orig/core/date_api.php mantisbt/core/date_api.php
--- orig/core/date_api.php	2008-03-31 13:45:23.000000000 +0200
+++ mantisbt/core/date_api.php	2008-04-13 10:38:12.000000000 +0200
@@ -22,6 +22,20 @@
 	# --------------------------------------------------------
 
 	### Date API ###
+	# --------------------
+	# checks if date is null
+	function date_is_null ( $p_date ) {
+		if ( $p_date == date_get_null( ) ) {
+			return true;
+		}
+		return false;
+	}
+	
+	# --------------------
+	# gets null date 
+	function date_get_null ( ) {
+		return db_unixtimestamp( '1970-01-01 00:00:01' );
+	}
 
 	# --------------------
 	# prints the date given the formating string
@@ -149,4 +163,48 @@
 			}
 		}
 	}
+	
+	# --------------------
+	# prints calendar icon and adds required javascript files.
+	# button_name is name of button that will display calendar icon
+	# in caste there are more than one calendar on page
+	function date_print_calendar ( $p_button_name = 'trigger' ) {
+		# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			echo "<style type=\"text/css\">@import url(javascript/jscalendar/calendar-blue.css);</style>\n";
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/lang/calendar-en.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar-setup.js\"></script>\n"; 	
+			$t_icon_path = config_get( 'icon_path' );
+			$t_cal_icon = $t_icon_path ."calendar-img.gif";	
+	   	 	echo "<input type=\"image\" class=\"button\" id=\"".$p_button_name."\" SRC=\"";
+	    	echo $t_cal_icon;
+			$t_format = config_get( 'short_date_format' );
+			$t_new_format = str_replace( '-', '-%', $t_format );
+			$t_format = "%".$t_new_format;
+			echo "\" onClick=\"return showCalendar ('sel1', '".$t_format."', 24, true)\" />";
+		}
+	}
+	# --------------------
+	# creates javascript calendar objects, point to input element ($p_field_name) that
+	# diaplays date, and connects it with calendar button ($p_button_name) created with
+	# date_print_calendar.
+	# should be called right after </form> tag
+	function date_finish_calendar ( $p_field_name, $p_button_name) {
+	# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			$t_format = config_get( 'short_date_format' );
+			$t_new_format = str_replace( '-', '-%', $t_format );
+			$t_format = "%".$t_new_format;
+			echo "<script type=\"text/javascript\">\n";
+			echo "Calendar.setup (\n";
+			echo "{\n";
+		 	echo "inputField 	: \"".$p_field_name."\",\n";
+		 	echo "ifFormat 	: \"".$t_format."\", \n";
+		 	echo "button		: \"".$p_button_name."\"\n";
+			echo "}\n";
+			echo ");\n";
+			echo "</script>\n";
+			}	
+	}
 ?>
diff -Naur orig/core/filter_api.php mantisbt/core/filter_api.php
--- orig/core/filter_api.php	2008-04-09 11:49:48.000000000 +0200
+++ mantisbt/core/filter_api.php	2008-04-13 10:14:02.000000000 +0200
@@ -1537,6 +1537,7 @@
 			
 			$row['date_submitted'] = db_unixtimestamp ( $row['date_submitted'] );
 			$row['last_updated'] = db_unixtimestamp ( $row['last_updated'] );
+			$row['due_date']	= db_unixtimestamp( $row['due_date'] );
 					
 			array_push( $rows, $row );
 		}
diff -Naur orig/css/default.css mantisbt/css/default.css
--- orig/css/default.css	2008-04-09 11:49:47.000000000 +0200
+++ mantisbt/css/default.css	2008-04-13 10:14:02.000000000 +0200
@@ -52,6 +52,7 @@
 td.left				{ text-align: left; }
 td.right			{ text-align: right; }
 td.category			{ background-color: #c8c8e8; color: #000000; font-weight: bold; vertical-align : top; }
+td.overdue			{ background-color: #ff0000; color: #000000; font-weight: bold; }
 
 td.col-1			{ background-color: #d8d8d8; color: #000000; }
 td.col-2			{ background-color: #e8e8e8; color: #000000; }
diff -Naur orig/images/clock.png mantisbt/images/clock.png
--- orig/images/clock.png	1970-01-01 01:00:00.000000000 +0100
+++ mantisbt/images/clock.png	2008-04-13 10:14:02.000000000 +0200
@@ -0,0 +1,8 @@
+�PNG
+
+
IHDR�agAMA��7��tEXtSoftwareAdobe ImageReadyq�e<IDAT8�]�kHSq��}��}�(
+�E�AAЇnA��X��Vd�Y�����դ��tv���<���Z�������.�czt{z�CGu�wxx��y��?7��M#Ԅ�xGLg�ٜɽ�H��s�@����L��X�Z�^+f�?���~;��tg��o%��
+<�\FȚ<06�o�{�)��CA��:�`�߇N�29���R��_�� 8ww>l��6��׌��t�7����M}�پ��	��7EF܏&���M�s�zJf�-�K�S���0�\�u��I�!���}ً�f>Ʌ]�z��d��&�."�^õ�J,.��4���2��I3�(Pd�E�ىzG˅���מ���=�M'��QH��;e��PQxt5/ހ���G0/��v��T�\}`�gD��hc�8����	�/j�R��Tp��
+�e�x��+��J�P���/)T�;ƥ��0o��8�ާ�x^+��e��/<6�i�Fہ�� ~�G��
+��[��app�@�N��yY&^�t�R�E]�����"�taC
+��T�%}N+BŨyY&^��x�r�k���᪾6W݇$+��Ϊ�U�0�L����`��#�ZyÙZ��}���<�nY�z��<�s�c�e#dU����� I�M&~b�R�P�*���-�+�li��B���)0��	��t�����tw�f��3ោi5�¢(���ĂxAUU�L��#��+OA��D� ������ߟ��IEND�B`�
\ No newline at end of file
diff -Naur orig/images/overdue.png mantisbt/images/overdue.png
--- orig/images/overdue.png	1970-01-01 01:00:00.000000000 +0100
+++ mantisbt/images/overdue.png	2008-04-13 10:14:02.000000000 +0200
@@ -0,0 +1,5 @@
+�PNG
+
+
IHDR�agAMA��7��tEXtSoftwareAdobe ImageReadyq�e<,IDAT8�]�kHa�� �2�Z��X$a%I��E�E?�C?*��Q��.YY�M�LKk���R+��4�k��m^�5���]����qLG��|�Y4��o���0��:�rC� >�����ā�6"��92qC�3���3���~[�rK�k�'���E���}G��6M�~1I���H�M-=���(��h�'�[�R�Ǎ�6
V��Pm����zE���N^%1����Fi��tK�z{^��f�s�� |E�������&�ߑ�Ό��%�]�}��S]��r_����9�]e�ӕ3�&ܵ5�d���+! ��:�j�P��y��{��!��6'���Xm�7��|�D��#McW0FCK~P͐�J�Żq�(`g����vې]�x�ĵ�.��d��'dE�ռ|�)(�ݍ�/�Bh��X/s�d
+b��
+��8��R��G=8����	���gXž,X/sV�z.n˵A�oG��RH?��Nd��d��	��ǀ�=��`��H>��_{�}a%޹�h���FT<���$J�x�9�}��z�3�t�n��1�^�"��B-,��~��H��C�0RL�D`�x�����d�5��#%[�ic=�dڇ��pP�De�jt�\	i�2����u�ؿ����w�*=��WH�, ��)J�;ӬMd�8s&���О���ѣ�X��$�Ӊ7f�/qW.f�6`�^���4M\�mS��e�d�&&�*:��\RRC�n�E���i���GxB�o3�4ћ��o��(���PPPE�=Ĵ�e�sԨ:6�b�HM����_5�ӡ��IEND�B`�
\ No newline at end of file
diff -Naur orig/lang/strings_english.txt mantisbt/lang/strings_english.txt
--- orig/lang/strings_english.txt	2008-04-13 10:12:15.000000000 +0200
+++ mantisbt/lang/strings_english.txt	2008-04-13 10:14:02.000000000 +0200
@@ -1513,6 +1513,10 @@
 $s_copy_columns_from = 'Copy Columns From';
 $s_copy_columns_to = 'Copy Columns To';
 
+# due date
+$s_due_date = "Due Date";
+$s_overdue = "Overdue";
+
 # mind mapping
 $s_mindmap = 'Mindmap';
 $s_freemind_export = 'Freemind Export';
diff -Naur orig/lang/strings_polish.txt mantisbt/lang/strings_polish.txt
--- orig/lang/strings_polish.txt	2008-03-31 13:44:41.000000000 +0200
+++ mantisbt/lang/strings_polish.txt	2008-04-13 10:14:02.000000000 +0200
@@ -1336,4 +1336,7 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
+$s_due_date = "Termin realizacji";
+$s_overdue = "Przeterminowane";
+
 ?>
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-31 13:44:40.000000000 +0200
+++ mantisbt/lang/strings_polish_8859-2.txt	2008-04-13 10:14:02.000000000 +0200
@@ -1336,4 +1336,7 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
+$s_due_date = "Termin realizacji";
+$s_overdue = "Przeterminowane";
+
 ?>
duedate_stage1_final6.diff (27,639 bytes)   
duedate_stage1_final7.diff (28,801 bytes)   
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/admin/schema.php mantisbt/admin/schema.php
--- orig/admin/schema.php	2008-03-31 14:05:21.000000000 +0200
+++ mantisbt/admin/schema.php	2008-04-15 20:44:11.000000000 +0200
@@ -405,3 +405,5 @@
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_version_table' ), "
 	obsolete		L		NOTNULL DEFAULT \" '0' \"" ) );
 
+$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "
+        due_date                T               NOTNULL DEFAULT '1970-01-01' " ) );
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/bug_change_status_page.php mantisbt/bug_change_status_page.php
--- orig/bug_change_status_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_change_status_page.php	2008-04-13 10:31:46.000000000 +0200
@@ -52,7 +52,7 @@
 			) ) {
 		access_denied();
 	}
-
+	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
 	# get new issue handler if set, otherwise default to original handler
 	$f_handler_id = gpc_get_int( 'handler_id', bug_get_field( $f_bug_id, 'handler_id' ) );
 
@@ -161,6 +161,26 @@
 </tr>
 <?php } ?>
 
+<!-- Due date -->
+<?php if ( $t_can_update_due_date ) {
+	$t_date_to_display = '';
+	if ( ! date_is_null( $t_bug->due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
+	}
+?>
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?> <?php print_documentation_link( 'due_date' ) ?>
+	</td>
+	<td>
+	<?php
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+		date_print_calendar( );
+	?>
+	</td>
+</tr>
+<?php } ?>
+
 <!-- Custom Fields -->
 <?php
 # @@@ thraxisp - I undid part of the change for #5068 for #5527
@@ -320,6 +340,10 @@
 </form>
 </div>
 
+<?php
+if ( $t_can_update_due_date ) {
+	date_finish_calendar( 'due_date', 'trigger');
+} ?>
 <br />
 <?php
 	include( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'bug_view_inc.php' );
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/bug_report.php mantisbt/bug_report.php
--- orig/bug_report.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_report.php	2008-04-13 10:14:02.000000000 +0200
@@ -54,6 +54,10 @@
 	$t_bug_data->description			= gpc_get_string( 'description' );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
+	$t_bug_data->due_date 				= gpc_get_string( 'due_date', '');
+	if ( is_blank ( $t_bug_data->due_date ) ) {
+		$t_bug_data->due_date = date_get_null();
+	}
 
 	$f_file					= gpc_get_file( 'file', null ); #@@@ (thraxisp) Note that this always returns a structure
 															# size = 0, if no file
@@ -188,6 +192,7 @@
 		<input type="hidden" name="build" 		value="<?php echo $t_bug_data->build ?>" />
 		<input type="hidden" name="report_stay" 	value="1" />
 		<input type="hidden" name="view_state"		value="<?php echo $t_bug_data->view_state ?>" />
+		<input type="hidden" name="due_date"		value="<?php echo $t_bug_data->due_date ?>" />
 		<input type="submit" class="button" 		value="<?php echo lang_get( 'report_more_bugs' ) ?>" />
 	</form>
 	</p>
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/bug_report_advanced_page.php mantisbt/bug_report_advanced_page.php
--- orig/bug_report_advanced_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_report_advanced_page.php	2008-04-13 10:25:43.000000000 +0200
@@ -45,6 +45,8 @@
 						( 0 == $f_master_bug_id ) ? '' : '?m_id=' . $f_master_bug_id );
 	}
 
+	$t_can_update_due_date = access_has_project_level( config_get( 'due_date_update_threshold' ), helper_get_current_project(), auth_get_current_user_id() );
+
 	if( $f_master_bug_id > 0 ) {
 		# master bug exists...
 		bug_ensure_exists( $f_master_bug_id );
@@ -114,6 +116,11 @@
 		$f_steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 		$f_additional_info		= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
 		$f_view_state			= gpc_get_int( 'view_state', config_get( 'default_bug_view_status' ) );
+		$f_due_date				=gpc_get_string( 'due_date', '');
+
+		if ( $f_due_date == '' ) {
+			$f_due_date = date_get_null();
+		}
 
 		$t_project_id			= helper_get_current_project();
 
@@ -209,6 +216,26 @@
 </tr>
 <?php } ?>
 
+<!-- Due date -->
+<?php if ( $t_can_update_due_date ) { 
+	$t_date_to_display = '';
+	if ( ! date_is_null( $f_due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $f_due_date );	
+	}
+
+?>
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?> <?php print_documentation_link( 'due_date' ) ?>
+	</td>
+	<td>
+	<?php
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+		date_print_calendar();
+	?>
+	</td>
+</tr>
+<?php } ?>
 
 <!-- spacer -->
 <tr class="spacer">
@@ -554,6 +581,9 @@
 	window.document.report_bug_form.category_id.focus();
 -->
 </script>
-<?php } ?>
+<?php  }
+if ( $t_can_update_due_date ) { 
+	date_finish_calendar( 'due_date', 'trigger' );
+}
 
-<?php html_page_bottom1( __FILE__ ) ?>
+html_page_bottom1( __FILE__ ) ?>
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/bug_update.php mantisbt/bug_update.php
--- orig/bug_update.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update.php	2008-04-13 10:14:02.000000000 +0200
@@ -77,7 +77,11 @@
 	$t_bug_data->target_version		= gpc_get_string( 'target_version', $t_bug_data->target_version );
 	$t_bug_data->view_state			= gpc_get_int( 'view_state', $t_bug_data->view_state );
 	$t_bug_data->summary			= gpc_get_string( 'summary', $t_bug_data->summary );
-
+	$t_bug_data->due_date 				= gpc_get_string( 'due_date', $t_bug_data->due_date);
+	if ( is_blank ( $t_bug_data->due_date ) ) {
+		$t_bug_data->due_date = date_get_null( );
+	}
+	
 	$t_bug_data->description		= gpc_get_string( 'description', $t_bug_data->description );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', $t_bug_data->steps_to_reproduce );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_information', $t_bug_data->additional_information );
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/bug_update_advanced_page.php mantisbt/bug_update_advanced_page.php
--- orig/bug_update_advanced_page.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update_advanced_page.php	2008-04-13 10:34:02.000000000 +0200
@@ -35,7 +35,7 @@
 	$f_bug_id = gpc_get_int( 'bug_id' );
 
 	$t_bug = bug_prepare_edit( 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.
@@ -48,13 +48,13 @@
 	if ( SIMPLE_ONLY == config_get( 'show_update' ) ) {
 		print_header_redirect ( 'bug_update_page.php?bug_id=' . $f_bug_id );
 	}
-
+	
 	if ( bug_is_readonly( $f_bug_id ) ) {
 		error_parameters( $f_bug_id );
 		trigger_error( ERROR_BUG_READ_ONLY_ACTION_DENIED, ERROR );
 	}
 
-	access_ensure_bug_level( config_get( 'update_bug_threshold' ), $f_bug_id );
+	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
 
 	html_page_top1( bug_format_summary( $f_bug_id, SUMMARY_CAPTION ) );
 	html_page_top2();
@@ -189,8 +189,34 @@
 ?>
 	</td>
 
-	<!-- spacer -->
-	<td colspan="2">&nbsp;</td>
+<?php if ( access_has_bug_level( config_get( 'due_date_view_threshold' ), $f_bug_id ) ) { ?>
+	<!-- Due Date -->
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?>
+	</td>
+	<?php 
+	if ( bug_is_overdue( $f_bug_id ) ) {
+		print "<td class=\"overdue\">";
+	} else {
+		print "<td>";
+	}
+	if ( $t_can_update_due_date ) {
+		$t_date_to_display = '';
+		if ( ! date_is_null( $t_bug->due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
+		}
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+		date_print_calendar( );
+	?>
+	</td>
+	<?php } else {
+		if ( $t_bug->due_date != $t_null_date  ) print_date( config_get( 'short_date_format' ), $t_bug->due_date  ); }?>
+	</td>
+<?php } else { ?>
+		<!-- spacer -->
+		<td colspan="2">&nbsp;</td>
+<?php } ?>
+
 </tr>
 
 
@@ -595,6 +621,10 @@
 </form>
 
 <?php
+if ( $t_can_update_due_date ) { 
+	date_finish_calendar( 'due_date', 'trigger');
+}
+
 	include( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'bugnote_view_inc.php' );
 	html_page_bottom1( __FILE__ );
 
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/bug_update_page.php mantisbt/bug_update_page.php
--- orig/bug_update_page.php	2008-03-31 13:45:27.000000000 +0200
+++ mantisbt/bug_update_page.php	2008-04-13 10:14:02.000000000 +0200
@@ -280,6 +280,9 @@
 </tr>
 
 <?php
+	} else {
+		# spacer
+		echo '<td colspan="2">&nbsp;</td>';	
 	}
 ?>
 <?php /*
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/bug_view_advanced_page.php mantisbt/bug_view_advanced_page.php
--- orig/bug_view_advanced_page.php	2008-03-31 13:45:26.000000000 +0200
+++ mantisbt/bug_view_advanced_page.php	2008-04-13 10:14:02.000000000 +0200
@@ -217,8 +217,29 @@
 		<?php echo get_enum_element( 'project_view_state', $t_bug->view_state ) ?>
 	</td>
 
-	<!-- spacer -->
-	<td colspan="2">&nbsp;</td>
+	<!-- Due Date -->
+	<?php if ( access_has_bug_level( config_get( 'due_date_view_threshold' ), $f_bug_id ) ) { ?>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?>
+	</td>
+	<?php
+	if ( bug_is_overdue( $f_bug_id ) ) {
+		print "<td class=\"overdue\">";
+	} else {
+		print "<td>";
+	}
+	?>
+		<?php 
+			if ( !date_is_null( $t_bug->due_date ) ) {
+				print_date( config_get( 'short_date_format' ), $t_bug->due_date ); }
+			?>
+	</td>
+	<?php } else { ?>
+		<!-- spacer -->
+		<td colspan="2">&nbsp;</td>
+	<?php
+	}
+	?>
 
 </tr>
 
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/config_defaults_inc.php mantisbt/config_defaults_inc.php
--- orig/config_defaults_inc.php	2008-04-09 11:49:48.000000000 +0200
+++ mantisbt/config_defaults_inc.php	2008-04-13 10:14:02.000000000 +0200
@@ -1990,6 +1990,17 @@
 	# management threshold.
 	$g_manage_plugin_threshold = ADMINISTRATOR;
 
+ 
+ 	#############################
+ 	# Due Date 
+ 	#############################
+ 
+ 	# threshold to update due date submitted
+ 	$g_due_date_update_threshold = DEVELOPER;
+ 	
+	# threshold to see due date
+ 	$g_due_date_view_threshold = REPORTER;
+
 	#############################
 	# Mind mapping
 	#############################
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/core/bug_api.php mantisbt/core/bug_api.php
--- orig/core/bug_api.php	2008-03-31 13:45:23.000000000 +0200
+++ mantisbt/core/bug_api.php	2008-04-13 10:14:02.000000000 +0200
@@ -79,6 +79,9 @@
 		
 		#internal helper objects
 		var $_stats = null;
+		
+		#due date
+		var $due_date = '';
 	}
 
 	#===================================
@@ -105,6 +108,8 @@
 			$p_bug_database_result['date_submitted']	= db_unixtimestamp( $p_bug_database_result['date_submitted']['date_submitted'] );
 		if( !is_int( $p_bug_database_result['last_updated'] ) )
 			$p_bug_database_result['last_updated']	= db_unixtimestamp( $p_bug_database_result['last_updated'] );
+		if( !is_int( $p_bug_datebase_result['due_date'] ) ) 
+			$p_bug_datebase_result['due_date']	= db_unixtimestamp( $p_bug_datebase_result['due_date'] );
 		$g_cache_bug[ $p_bug_database_result['id'] ] = $p_bug_database_result;
 		if( !is_null( $p_stats ) ) {
 			$g_cache_bug[ $p_bug_database_result['id'] ]['_stats'] = $p_stats;
@@ -145,6 +150,8 @@
 		$row = db_fetch_array( $result );
 		$row['date_submitted']	= db_unixtimestamp( $row['date_submitted'] );
 		$row['last_updated']	= db_unixtimestamp( $row['last_updated'] );
+		$row['due_date']	= db_unixtimestamp( $row['due_date'] );
+		
 		$g_cache_bug[$c_bug_id] = $row;
 
 		return $row;
@@ -335,6 +342,23 @@
 	}
 
 	# --------------------
+	# Check if the bug is overdue
+	function bug_is_overdue( $p_bug_id ) {
+		$t_bug_row = bug_cache_row( $p_bug_id );
+		$t_due_date = $t_bug_row[ 'due_date' ];
+		if (  ! date_is_null( $t_due_date)  ) {
+			$t_now = db_unixtimestamp();
+			if ( $t_now > $t_due_date ) {
+				if ( bug_is_resolved( $p_bug_id ) ) {
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+
+
+	# --------------------
 	# Validate workflow state to see if bug can be moved to requested state
 	function bug_check_workflow( $p_bug_status, $p_wanted_status ) {
 		$t_status_enum_workflow = config_get( 'status_enum_workflow' );
@@ -393,6 +417,8 @@
 		$c_additional_info		= $p_bug_data->additional_information;
 		$c_sponsorship_total 	= 0;
 		$c_sticky 				= 0;
+		$c_due_date				= $p_bug_data->due_date;
+		
 
 		# Summary cannot be blank
 		if ( is_blank( $c_summary ) ) {
@@ -419,6 +445,17 @@
 			$c_target_version	= '';
 		}
 
+		#check due_date format
+		if ( !is_blank( $p_bug_data->due_date ) ) {
+			if ( !is_int( $p_bug_data->due_date ) ) {
+				$t_tmp = strtotime( $p_bug_data->due_date);
+				$c_due_date = date ( 'Y-m-d 00:00:01', $t_tmp );
+			} else {
+				$c_due_date = date ( 'Y-m-d H:i:s', $p_bug_data->due_date );
+			}
+		}
+
+
 		$t_bug_table				= db_get_table( 'mantis_bug_table' );
 		$t_bug_text_table			= db_get_table( 'mantis_bug_text_table' );
 		$t_category_table			= db_get_table( 'mantis_category_table' );
@@ -474,7 +511,7 @@
 				      platform, version,
 				      build,
 				      profile_id, summary, view_state, sponsorship_total, sticky, fixed_in_version,
-				      target_version 
+				      target_version, due_date 
 				    )
 				  VALUES
 				    ( " . db_param(0) . ",
@@ -503,10 +540,11 @@
 				      " . db_param(23) . ",
 				      " . db_param(24) . ",
 				      " . db_param(25) . ",
-				      " . db_param(26) . ")";
+				      " . db_param(26) . ",
+				      " . db_param(27) . ")";
 		db_query_bound( $query, Array( $c_project_id, $c_reporter_id, $c_handler_id, 0, $c_priority, $c_severity, $c_reproducibility, $t_status,
 								 $t_resolution, 10, $c_category_id, db_now(), db_now(), 10, $t_text_id, $c_os, $c_os_build, $c_platform, $c_version,$c_build,
-								 $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version ) );
+								 $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version, $c_due_date) );
 
 		$t_bug_id = db_insert_id($t_bug_table);
 
@@ -569,6 +607,7 @@
 		bug_set_field( $t_new_bug_id, 'target_version', $t_bug_data->target_version );
 		bug_set_field( $t_new_bug_id, 'sponsorship_total', 0 );
 		bug_set_field( $t_new_bug_id, 'sticky', 0 );
+		bug_set_field( $t_new_bug_id, 'due_date', $t_bug_data->due_date );
 
 		# COPY CUSTOM FIELDS
 		if ( $p_copy_custom_fields ) {
@@ -898,6 +937,16 @@
 		$t_fields[] = $c_bug_id;
 		
 		db_query_bound( $query, $t_fields );
+		
+		if ( !is_blank( $p_bug_data->due_date ) ) {
+			if ( !is_int( $p_bug_data->due_date ) ) {
+				$t_format = strtotime( $p_bug_data->due_date);
+				$p_bug_data->due_date = date ( 'Y-m-d 00:00:01', $t_format );
+			} else {
+				$p_bug_data->due_date = date ( 'Y-m-d H:i:s', $p_bug_data->due_date );
+			}
+			bug_set_field( $p_bug_id, 'due_date', $p_bug_data->due_date);
+		}
 
 		bug_clear_cache( $p_bug_id );
 
@@ -1190,17 +1239,34 @@
 		$c_status		=  $p_status; #generic, unknown type
 
 		$h_status = bug_get_field( $p_bug_id, $p_field_name );
+		
+		if ( $p_field_name == 'due_date' ) {
+			if ( !date_is_null( $h_status )  ) {
+				$h_status = date( config_get ( 'short_date_format' ), $h_status );
+			} else {
+				$h_status = '';
+			}
+			$t_tmp = $p_status;
+			if ( !is_int( $p_status ) ) {
+				$t_tmp = strtotime( $p_status );
+			} 
+			if ( !date_is_null( $t_tmp ) ) {
+				$c_status = date( 'Y-m-d 00:00:01', $t_tmp );
+			} else {
+				$c_status = '';
+			}
+			$c_field_name = lang_get( 'due_date' );
+		}
 
 		# return if status is already set
 		if ( $c_status == $h_status ) {
 			return true;
 		}
-
 		$t_bug_table = db_get_table( 'mantis_bug_table' );
 
 		# Update fields
 		$query = "UPDATE $t_bug_table
-				  SET $c_field_name=" . db_param(0) . "
+				  SET $p_field_name=" . db_param(0) . "
 				  WHERE id=" .db_param(1);
 		db_query_bound( $query, Array( $c_status, $c_bug_id ) );
 
@@ -1210,7 +1276,7 @@
 		# log changes except for duplicate_id which is obsolete and should be removed in
 		# Mantis 1.3.
 		if ( $p_field_name != 'duplicate_id' ) {
-			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $p_status );
+			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $c_status );
 		}
 
 		bug_clear_cache( $p_bug_id );
@@ -1497,6 +1563,7 @@
 		$p_bug_data->summary			= string_attribute( $p_bug_data->summary );
 		$p_bug_data->sponsorship_total	= string_attribute( $p_bug_data->sponsorship_total );
 		$p_bug_data->sticky				= string_attribute( $p_bug_data->sticky );
+		$p_bug_data->due_date			= string_attribute( $p_bug_data->due_date );
 
 		$p_bug_data->description		= string_textarea( $p_bug_data->description );
 		$p_bug_data->steps_to_reproduce	= string_textarea( $p_bug_data->steps_to_reproduce );
@@ -1522,6 +1589,7 @@
 		$p_bug_data->summary			= string_display_line_links( $p_bug_data->summary );
 		$p_bug_data->sponsorship_total	= string_display_line( $p_bug_data->sponsorship_total );
 		$p_bug_data->sticky				= string_display_line( $p_bug_data->sticky );
+		$p_bug_data->due_date			= string_display_line( $p_bug_data->due_date );
 
 		$p_bug_data->description		= string_display_links( $p_bug_data->description );
 		$p_bug_data->steps_to_reproduce	= string_display_links( $p_bug_data->steps_to_reproduce );
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/core/columns_api.php mantisbt/core/columns_api.php
--- orig/core/columns_api.php	2008-04-13 10:12:16.000000000 +0200
+++ mantisbt/core/columns_api.php	2008-04-13 10:14:02.000000000 +0200
@@ -521,8 +521,12 @@
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function print_column_edit( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 		global $t_icon_path, $t_update_bug_threshold;
-
-		echo '<td>';
+		
+		if ( bug_is_overdue( $p_row['id'] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] )) {
+			print "<td class=\"overdue\">";
+		} else {
+			echo '<td>';
+		}
 		if ( !bug_is_readonly( $p_row['id'] )
 			&& access_has_bug_level( $t_update_bug_threshold, $p_row['id'] ) ) {
 			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
@@ -532,6 +536,20 @@
 		} else {
 			echo '&nbsp;';
 		}
+		if ( bug_is_overdue( $p_row['id'] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] ) ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdue.png';
+			echo '" alt="' . lang_get( 'overdue' ) . '"';
+			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
+		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] )) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
+			echo '" alt="' . lang_get( 'due_date' ) . '"';
+			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
+		} else {
+			echo '&nbsp;';
+		}
+		
 		echo '</td>';
 	}
 
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/core/date_api.php mantisbt/core/date_api.php
--- orig/core/date_api.php	2008-03-31 13:45:23.000000000 +0200
+++ mantisbt/core/date_api.php	2008-04-13 10:38:12.000000000 +0200
@@ -22,6 +22,20 @@
 	# --------------------------------------------------------
 
 	### Date API ###
+	# --------------------
+	# checks if date is null
+	function date_is_null ( $p_date ) {
+		if ( $p_date == date_get_null( ) ) {
+			return true;
+		}
+		return false;
+	}
+	
+	# --------------------
+	# gets null date 
+	function date_get_null ( ) {
+		return db_unixtimestamp( '1970-01-01 00:00:01' );
+	}
 
 	# --------------------
 	# prints the date given the formating string
@@ -149,4 +163,48 @@
 			}
 		}
 	}
+	
+	# --------------------
+	# prints calendar icon and adds required javascript files.
+	# button_name is name of button that will display calendar icon
+	# in caste there are more than one calendar on page
+	function date_print_calendar ( $p_button_name = 'trigger' ) {
+		# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			echo "<style type=\"text/css\">@import url(javascript/jscalendar/calendar-blue.css);</style>\n";
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/lang/calendar-en.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar-setup.js\"></script>\n"; 	
+			$t_icon_path = config_get( 'icon_path' );
+			$t_cal_icon = $t_icon_path ."calendar-img.gif";	
+	   	 	echo "<input type=\"image\" class=\"button\" id=\"".$p_button_name."\" SRC=\"";
+	    	echo $t_cal_icon;
+			$t_format = config_get( 'short_date_format' );
+			$t_new_format = str_replace( '-', '-%', $t_format );
+			$t_format = "%".$t_new_format;
+			echo "\" onClick=\"return showCalendar ('sel1', '".$t_format."', 24, true)\" />";
+		}
+	}
+	# --------------------
+	# creates javascript calendar objects, point to input element ($p_field_name) that
+	# diaplays date, and connects it with calendar button ($p_button_name) created with
+	# date_print_calendar.
+	# should be called right after </form> tag
+	function date_finish_calendar ( $p_field_name, $p_button_name) {
+	# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			$t_format = config_get( 'short_date_format' );
+			$t_new_format = str_replace( '-', '-%', $t_format );
+			$t_format = "%".$t_new_format;
+			echo "<script type=\"text/javascript\">\n";
+			echo "Calendar.setup (\n";
+			echo "{\n";
+		 	echo "inputField 	: \"".$p_field_name."\",\n";
+		 	echo "ifFormat 	: \"".$t_format."\", \n";
+		 	echo "button		: \"".$p_button_name."\"\n";
+			echo "}\n";
+			echo ");\n";
+			echo "</script>\n";
+			}	
+	}
 ?>
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/core/filter_api.php mantisbt/core/filter_api.php
--- orig/core/filter_api.php	2008-04-09 11:49:48.000000000 +0200
+++ mantisbt/core/filter_api.php	2008-04-13 10:14:02.000000000 +0200
@@ -1537,6 +1537,7 @@
 			
 			$row['date_submitted'] = db_unixtimestamp ( $row['date_submitted'] );
 			$row['last_updated'] = db_unixtimestamp ( $row['last_updated'] );
+			$row['due_date']	= db_unixtimestamp( $row['due_date'] );
 					
 			array_push( $rows, $row );
 		}
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/css/default.css mantisbt/css/default.css
--- orig/css/default.css	2008-04-09 11:49:47.000000000 +0200
+++ mantisbt/css/default.css	2008-04-13 10:14:02.000000000 +0200
@@ -52,6 +52,7 @@
 td.left				{ text-align: left; }
 td.right			{ text-align: right; }
 td.category			{ background-color: #c8c8e8; color: #000000; font-weight: bold; vertical-align : top; }
+td.overdue			{ background-color: #ff0000; color: #000000; font-weight: bold; }
 
 td.col-1			{ background-color: #d8d8d8; color: #000000; }
 td.col-2			{ background-color: #e8e8e8; color: #000000; }
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/images/clock.png mantisbt/images/clock.png
--- orig/images/clock.png	1970-01-01 01:00:00.000000000 +0100
+++ mantisbt/images/clock.png	2008-04-13 10:14:02.000000000 +0200
@@ -0,0 +1,8 @@
+�PNG
+
+
IHDR�agAMA��7��tEXtSoftwareAdobe ImageReadyq�e<IDAT8�]�kHSq��}��}�(
+�E�AAЇnA��X��Vd�Y�����դ��tv���<���Z�������.�czt{z�CGu�wxx��y��?7��M#Ԅ�xGLg�ٜɽ�H��s�@����L��X�Z�^+f�?���~;��tg��o%��
+<�\FȚ<06�o�{�)��CA��:�`�߇N�29���R��_�� 8ww>l��6��׌��t�7����M}�پ��	��7EF܏&���M�s�zJf�-�K�S���0�\�u��I�!���}ً�f>Ʌ]�z��d��&�."�^õ�J,.��4���2��I3�(Pd�E�ىzG˅���מ���=�M'��QH��;e��PQxt5/ހ���G0/��v��T�\}`�gD��hc�8����	�/j�R��Tp��
+�e�x��+��J�P���/)T�;ƥ��0o��8�ާ�x^+��e��/<6�i�Fہ�� ~�G��
+��[��app�@�N��yY&^�t�R�E]�����"�taC
+��T�%}N+BŨyY&^��x�r�k���᪾6W݇$+��Ϊ�U�0�L����`��#�ZyÙZ��}���<�nY�z��<�s�c�e#dU����� I�M&~b�R�P�*���-�+�li��B���)0��	��t�����tw�f��3ោi5�¢(���ĂxAUU�L��#��+OA��D� ������ߟ��IEND�B`�
\ No newline at end of file
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/images/overdue.png mantisbt/images/overdue.png
--- orig/images/overdue.png	1970-01-01 01:00:00.000000000 +0100
+++ mantisbt/images/overdue.png	2008-04-13 10:14:02.000000000 +0200
@@ -0,0 +1,5 @@
+�PNG
+
+
IHDR�agAMA��7��tEXtSoftwareAdobe ImageReadyq�e<,IDAT8�]�kHa�� �2�Z��X$a%I��E�E?�C?*��Q��.YY�M�LKk���R+��4�k��m^�5���]����qLG��|�Y4��o���0��:�rC� >�����ā�6"��92qC�3���3���~[�rK�k�'���E���}G��6M�~1I���H�M-=���(��h�'�[�R�Ǎ�6
V��Pm����zE���N^%1����Fi��tK�z{^��f�s�� |E�������&�ߑ�Ό��%�]�}��S]��r_����9�]e�ӕ3�&ܵ5�d���+! ��:�j�P��y��{��!��6'���Xm�7��|�D��#McW0FCK~P͐�J�Żq�(`g����vې]�x�ĵ�.��d��'dE�ռ|�)(�ݍ�/�Bh��X/s�d
+b��
+��8��R��G=8����	���gXž,X/sV�z.n˵A�oG��RH?��Nd��d��	��ǀ�=��`��H>��_{�}a%޹�h���FT<���$J�x�9�}��z�3�t�n��1�^�"��B-,��~��H��C�0RL�D`�x�����d�5��#%[�ic=�dڇ��pP�De�jt�\	i�2����u�ؿ����w�*=��WH�, ��)J�;ӬMd�8s&���О���ѣ�X��$�Ӊ7f�/qW.f�6`�^���4M\�mS��e�d�&&�*:��\RRC�n�E���i���GxB�o3�4ћ��o��(���PPPE�=Ĵ�e�sԨ:6�b�HM����_5�ӡ��IEND�B`�
\ No newline at end of file
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/lang/strings_english.txt mantisbt/lang/strings_english.txt
--- orig/lang/strings_english.txt	2008-04-13 10:12:15.000000000 +0200
+++ mantisbt/lang/strings_english.txt	2008-04-13 10:14:02.000000000 +0200
@@ -1513,6 +1513,10 @@
 $s_copy_columns_from = 'Copy Columns From';
 $s_copy_columns_to = 'Copy Columns To';
 
+# due date
+$s_due_date = "Due Date";
+$s_overdue = "Overdue";
+
 # mind mapping
 $s_mindmap = 'Mindmap';
 $s_freemind_export = 'Freemind Export';
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/lang/strings_polish.txt mantisbt/lang/strings_polish.txt
--- orig/lang/strings_polish.txt	2008-03-31 13:44:41.000000000 +0200
+++ mantisbt/lang/strings_polish.txt	2008-04-13 10:14:02.000000000 +0200
@@ -1336,4 +1336,7 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
+$s_due_date = "Termin realizacji";
+$s_overdue = "Przeterminowane";
+
 ?>
diff -Naur --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php orig/lang/strings_polish_8859-2.txt mantisbt/lang/strings_polish_8859-2.txt
--- orig/lang/strings_polish_8859-2.txt	2008-03-31 13:44:40.000000000 +0200
+++ mantisbt/lang/strings_polish_8859-2.txt	2008-04-13 10:14:02.000000000 +0200
@@ -1336,4 +1336,7 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
+$s_due_date = "Termin realizacji";
+$s_overdue = "Przeterminowane";
+
 ?>
duedate_stage1_final7.diff (28,801 bytes)   
duedate_stage1_final8.diff (29,054 bytes)   
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/admin/schema.php mbt_duedate/admin/schema.php
--- mantisbt/admin/schema.php	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/admin/schema.php	2008-04-15 15:15:14.000000000 -0500
@@ -404,3 +404,5 @@
 	" ) );
 $upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_project_version_table' ), "
 	obsolete		L		NOTNULL DEFAULT \" '0' \"" ) );
+$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "
+    due_date        T       NOTNULL DEFAULT '1970-01-01' " ) );
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/bug_change_status_page.php mbt_duedate/bug_change_status_page.php
--- mantisbt/bug_change_status_page.php	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/bug_change_status_page.php	2008-04-15 15:15:14.000000000 -0500
@@ -52,7 +52,7 @@
 			) ) {
 		access_denied();
 	}
-
+	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
 	# get new issue handler if set, otherwise default to original handler
 	$f_handler_id = gpc_get_int( 'handler_id', bug_get_field( $f_bug_id, 'handler_id' ) );
 
@@ -161,6 +161,26 @@
 </tr>
 <?php } ?>
 
+<!-- Due date -->
+<?php if ( $t_can_update_due_date ) {
+	$t_date_to_display = '';
+	if ( ! date_is_null( $t_bug->due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
+	}
+?>
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?> <?php print_documentation_link( 'due_date' ) ?>
+	</td>
+	<td>
+	<?php
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+		date_print_calendar( );
+	?>
+	</td>
+</tr>
+<?php } ?>
+
 <!-- Custom Fields -->
 <?php
 # @@@ thraxisp - I undid part of the change for #5068 for #5527
@@ -320,6 +340,10 @@
 </form>
 </div>
 
+<?php
+if ( $t_can_update_due_date ) {
+	date_finish_calendar( 'due_date', 'trigger');
+} ?>
 <br />
 <?php
 	include( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'bug_view_inc.php' );
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/bug_report_advanced_page.php mbt_duedate/bug_report_advanced_page.php
--- mantisbt/bug_report_advanced_page.php	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/bug_report_advanced_page.php	2008-04-15 15:15:18.000000000 -0500
@@ -45,6 +45,8 @@
 						( 0 == $f_master_bug_id ) ? '' : '?m_id=' . $f_master_bug_id );
 	}
 
+	$t_can_update_due_date = access_has_project_level( config_get( 'due_date_update_threshold' ), helper_get_current_project(), auth_get_current_user_id() );
+
 	if( $f_master_bug_id > 0 ) {
 		# master bug exists...
 		bug_ensure_exists( $f_master_bug_id );
@@ -114,6 +116,11 @@
 		$f_steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 		$f_additional_info		= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
 		$f_view_state			= gpc_get_int( 'view_state', config_get( 'default_bug_view_status' ) );
+		$f_due_date				=gpc_get_string( 'due_date', '');
+
+		if ( $f_due_date == '' ) {
+			$f_due_date = date_get_null();
+		}
 
 		$t_project_id			= helper_get_current_project();
 
@@ -209,6 +216,26 @@
 </tr>
 <?php } ?>
 
+<!-- Due date -->
+<?php if ( $t_can_update_due_date ) { 
+	$t_date_to_display = '';
+	if ( ! date_is_null( $f_due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $f_due_date );	
+	}
+
+?>
+<tr <?php echo helper_alternate_class() ?>>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?> <?php print_documentation_link( 'due_date' ) ?>
+	</td>
+	<td>
+	<?php
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+		date_print_calendar();
+	?>
+	</td>
+</tr>
+<?php } ?>
 
 <!-- spacer -->
 <tr class="spacer">
@@ -554,6 +581,9 @@
 	window.document.report_bug_form.category_id.focus();
 -->
 </script>
-<?php } ?>
+<?php  }
+if ( $t_can_update_due_date ) { 
+	date_finish_calendar( 'due_date', 'trigger' );
+}
 
-<?php html_page_bottom1( __FILE__ ) ?>
+html_page_bottom1( __FILE__ ) ?>
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/bug_report.php mbt_duedate/bug_report.php
--- mantisbt/bug_report.php	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/bug_report.php	2008-04-15 15:15:18.000000000 -0500
@@ -54,6 +54,10 @@
 	$t_bug_data->description			= gpc_get_string( 'description' );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', config_get( 'default_bug_steps_to_reproduce' ) );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_info', config_get ( 'default_bug_additional_info' ) );
+	$t_bug_data->due_date 				= gpc_get_string( 'due_date', '');
+	if ( is_blank ( $t_bug_data->due_date ) ) {
+		$t_bug_data->due_date = date_get_null();
+	}
 
 	$f_file					= gpc_get_file( 'file', null ); #@@@ (thraxisp) Note that this always returns a structure
 															# size = 0, if no file
@@ -188,6 +192,7 @@
 		<input type="hidden" name="build" 		value="<?php echo $t_bug_data->build ?>" />
 		<input type="hidden" name="report_stay" 	value="1" />
 		<input type="hidden" name="view_state"		value="<?php echo $t_bug_data->view_state ?>" />
+		<input type="hidden" name="due_date"		value="<?php echo $t_bug_data->due_date ?>" />
 		<input type="submit" class="button" 		value="<?php echo lang_get( 'report_more_bugs' ) ?>" />
 	</form>
 	</p>
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/bug_update_advanced_page.php mbt_duedate/bug_update_advanced_page.php
--- mantisbt/bug_update_advanced_page.php	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/bug_update_advanced_page.php	2008-04-15 15:15:18.000000000 -0500
@@ -35,7 +35,7 @@
 	$f_bug_id = gpc_get_int( 'bug_id' );
 
 	$t_bug = bug_prepare_edit( 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.
@@ -48,13 +48,13 @@
 	if ( SIMPLE_ONLY == config_get( 'show_update' ) ) {
 		print_header_redirect ( 'bug_update_page.php?bug_id=' . $f_bug_id );
 	}
-
+	
 	if ( bug_is_readonly( $f_bug_id ) ) {
 		error_parameters( $f_bug_id );
 		trigger_error( ERROR_BUG_READ_ONLY_ACTION_DENIED, ERROR );
 	}
 
-	access_ensure_bug_level( config_get( 'update_bug_threshold' ), $f_bug_id );
+	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
 
 	html_page_top1( bug_format_summary( $f_bug_id, SUMMARY_CAPTION ) );
 	html_page_top2();
@@ -189,8 +189,34 @@
 ?>
 	</td>
 
-	<!-- spacer -->
-	<td colspan="2">&nbsp;</td>
+<?php if ( access_has_bug_level( config_get( 'due_date_view_threshold' ), $f_bug_id ) ) { ?>
+	<!-- Due Date -->
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?>
+	</td>
+	<?php 
+	if ( bug_is_overdue( $f_bug_id ) ) {
+		print "<td class=\"overdue\">";
+	} else {
+		print "<td>";
+	}
+	if ( $t_can_update_due_date ) {
+		$t_date_to_display = '';
+		if ( ! date_is_null( $t_bug->due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
+		}
+	    print "<input ".helper_get_tab_index()." type=\"text\" id=\"due_date\" name=\"due_date\" size=\"20\" maxlength=\"10\" value=\"".$t_date_to_display."\">";
+		date_print_calendar( );
+	?>
+	</td>
+	<?php } else {
+		if ( $t_bug->due_date != $t_null_date  ) print_date( config_get( 'short_date_format' ), $t_bug->due_date  ); }?>
+	</td>
+<?php } else { ?>
+		<!-- spacer -->
+		<td colspan="2">&nbsp;</td>
+<?php } ?>
+
 </tr>
 
 
@@ -595,6 +621,10 @@
 </form>
 
 <?php
+if ( $t_can_update_due_date ) { 
+	date_finish_calendar( 'due_date', 'trigger');
+}
+
 	include( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'bugnote_view_inc.php' );
 	html_page_bottom1( __FILE__ );
 
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/bug_update_page.php mbt_duedate/bug_update_page.php
--- mantisbt/bug_update_page.php	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/bug_update_page.php	2008-04-15 15:15:18.000000000 -0500
@@ -280,6 +280,9 @@
 </tr>
 
 <?php
+	} else {
+		# spacer
+		echo '<td colspan="2">&nbsp;</td>';	
 	}
 ?>
 <?php /*
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/bug_update.php mbt_duedate/bug_update.php
--- mantisbt/bug_update.php	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/bug_update.php	2008-04-15 15:15:18.000000000 -0500
@@ -77,7 +77,11 @@
 	$t_bug_data->target_version		= gpc_get_string( 'target_version', $t_bug_data->target_version );
 	$t_bug_data->view_state			= gpc_get_int( 'view_state', $t_bug_data->view_state );
 	$t_bug_data->summary			= gpc_get_string( 'summary', $t_bug_data->summary );
-
+	$t_bug_data->due_date 				= gpc_get_string( 'due_date', $t_bug_data->due_date);
+	if ( is_blank ( $t_bug_data->due_date ) ) {
+		$t_bug_data->due_date = date_get_null( );
+	}
+	
 	$t_bug_data->description		= gpc_get_string( 'description', $t_bug_data->description );
 	$t_bug_data->steps_to_reproduce	= gpc_get_string( 'steps_to_reproduce', $t_bug_data->steps_to_reproduce );
 	$t_bug_data->additional_information	= gpc_get_string( 'additional_information', $t_bug_data->additional_information );
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/bug_view_advanced_page.php mbt_duedate/bug_view_advanced_page.php
--- mantisbt/bug_view_advanced_page.php	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/bug_view_advanced_page.php	2008-04-15 15:15:18.000000000 -0500
@@ -217,8 +217,29 @@
 		<?php echo get_enum_element( 'project_view_state', $t_bug->view_state ) ?>
 	</td>
 
-	<!-- spacer -->
-	<td colspan="2">&nbsp;</td>
+	<!-- Due Date -->
+	<?php if ( access_has_bug_level( config_get( 'due_date_view_threshold' ), $f_bug_id ) ) { ?>
+	<td class="category">
+		<?php echo lang_get( 'due_date' ) ?>
+	</td>
+	<?php
+	if ( bug_is_overdue( $f_bug_id ) ) {
+		print "<td class=\"overdue\">";
+	} else {
+		print "<td>";
+	}
+	?>
+		<?php 
+			if ( !date_is_null( $t_bug->due_date ) ) {
+				print_date( config_get( 'short_date_format' ), $t_bug->due_date ); }
+			?>
+	</td>
+	<?php } else { ?>
+		<!-- spacer -->
+		<td colspan="2">&nbsp;</td>
+	<?php
+	}
+	?>
 
 </tr>
 
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/config_defaults_inc.php mbt_duedate/config_defaults_inc.php
--- mantisbt/config_defaults_inc.php	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/config_defaults_inc.php	2008-04-15 15:15:19.000000000 -0500
@@ -1990,6 +1990,17 @@
 	# management threshold.
 	$g_manage_plugin_threshold = ADMINISTRATOR;
 
+ 
+ 	#############################
+ 	# Due Date 
+ 	#############################
+ 
+ 	# threshold to update due date submitted
+ 	$g_due_date_update_threshold = DEVELOPER;
+ 	
+	# threshold to see due date
+ 	$g_due_date_view_threshold = REPORTER;
+
 	#############################
 	# Mind mapping
 	#############################
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/core/bug_api.php mbt_duedate/core/bug_api.php
--- mantisbt/core/bug_api.php	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/core/bug_api.php	2008-04-15 15:15:18.000000000 -0500
@@ -79,6 +79,9 @@
 		
 		#internal helper objects
 		var $_stats = null;
+		
+		#due date
+		var $due_date = '';
 	}
 
 	#===================================
@@ -105,6 +108,8 @@
 			$p_bug_database_result['date_submitted']	= db_unixtimestamp( $p_bug_database_result['date_submitted']['date_submitted'] );
 		if( !is_int( $p_bug_database_result['last_updated'] ) )
 			$p_bug_database_result['last_updated']	= db_unixtimestamp( $p_bug_database_result['last_updated'] );
+		if( !is_int( $p_bug_datebase_result['due_date'] ) ) 
+			$p_bug_datebase_result['due_date']	= db_unixtimestamp( $p_bug_datebase_result['due_date'] );
 		$g_cache_bug[ $p_bug_database_result['id'] ] = $p_bug_database_result;
 		if( !is_null( $p_stats ) ) {
 			$g_cache_bug[ $p_bug_database_result['id'] ]['_stats'] = $p_stats;
@@ -145,6 +150,8 @@
 		$row = db_fetch_array( $result );
 		$row['date_submitted']	= db_unixtimestamp( $row['date_submitted'] );
 		$row['last_updated']	= db_unixtimestamp( $row['last_updated'] );
+		$row['due_date']	= db_unixtimestamp( $row['due_date'] );
+		
 		$g_cache_bug[$c_bug_id] = $row;
 
 		return $row;
@@ -335,6 +342,23 @@
 	}
 
 	# --------------------
+	# Check if the bug is overdue
+	function bug_is_overdue( $p_bug_id ) {
+		$t_bug_row = bug_cache_row( $p_bug_id );
+		$t_due_date = $t_bug_row[ 'due_date' ];
+		if (  ! date_is_null( $t_due_date)  ) {
+			$t_now = db_unixtimestamp();
+			if ( $t_now > $t_due_date ) {
+				if ( bug_is_resolved( $p_bug_id ) ) {
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+
+
+	# --------------------
 	# Validate workflow state to see if bug can be moved to requested state
 	function bug_check_workflow( $p_bug_status, $p_wanted_status ) {
 		$t_status_enum_workflow = config_get( 'status_enum_workflow' );
@@ -393,6 +417,8 @@
 		$c_additional_info		= $p_bug_data->additional_information;
 		$c_sponsorship_total 	= 0;
 		$c_sticky 				= 0;
+		$c_due_date				= $p_bug_data->due_date;
+		
 
 		# Summary cannot be blank
 		if ( is_blank( $c_summary ) ) {
@@ -419,6 +445,17 @@
 			$c_target_version	= '';
 		}
 
+		#check due_date format
+		if ( !is_blank( $p_bug_data->due_date ) ) {
+			if ( !is_int( $p_bug_data->due_date ) ) {
+				$t_tmp = strtotime( $p_bug_data->due_date);
+				$c_due_date = date ( 'Y-m-d 00:00:01', $t_tmp );
+			} else {
+				$c_due_date = date ( 'Y-m-d H:i:s', $p_bug_data->due_date );
+			}
+		}
+
+
 		$t_bug_table				= db_get_table( 'mantis_bug_table' );
 		$t_bug_text_table			= db_get_table( 'mantis_bug_text_table' );
 		$t_category_table			= db_get_table( 'mantis_category_table' );
@@ -474,7 +511,7 @@
 				      platform, version,
 				      build,
 				      profile_id, summary, view_state, sponsorship_total, sticky, fixed_in_version,
-				      target_version 
+				      target_version, due_date 
 				    )
 				  VALUES
 				    ( " . db_param(0) . ",
@@ -503,10 +540,11 @@
 				      " . db_param(23) . ",
 				      " . db_param(24) . ",
 				      " . db_param(25) . ",
-				      " . db_param(26) . ")";
+				      " . db_param(26) . ",
+				      " . db_param(27) . ")";
 		db_query_bound( $query, Array( $c_project_id, $c_reporter_id, $c_handler_id, 0, $c_priority, $c_severity, $c_reproducibility, $t_status,
 								 $t_resolution, 10, $c_category_id, db_now(), db_now(), 10, $t_text_id, $c_os, $c_os_build, $c_platform, $c_version,$c_build,
-								 $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version ) );
+								 $c_profile_id, $c_summary, $c_view_state, $c_sponsorship_total, $c_sticky, '', $c_target_version, $c_due_date) );
 
 		$t_bug_id = db_insert_id($t_bug_table);
 
@@ -569,6 +607,7 @@
 		bug_set_field( $t_new_bug_id, 'target_version', $t_bug_data->target_version );
 		bug_set_field( $t_new_bug_id, 'sponsorship_total', 0 );
 		bug_set_field( $t_new_bug_id, 'sticky', 0 );
+		bug_set_field( $t_new_bug_id, 'due_date', $t_bug_data->due_date );
 
 		# COPY CUSTOM FIELDS
 		if ( $p_copy_custom_fields ) {
@@ -898,6 +937,16 @@
 		$t_fields[] = $c_bug_id;
 		
 		db_query_bound( $query, $t_fields );
+		
+		if ( !is_blank( $p_bug_data->due_date ) ) {
+			if ( !is_int( $p_bug_data->due_date ) ) {
+				$t_format = strtotime( $p_bug_data->due_date);
+				$p_bug_data->due_date = date ( 'Y-m-d 00:00:01', $t_format );
+			} else {
+				$p_bug_data->due_date = date ( 'Y-m-d H:i:s', $p_bug_data->due_date );
+			}
+			bug_set_field( $p_bug_id, 'due_date', $p_bug_data->due_date);
+		}
 
 		bug_clear_cache( $p_bug_id );
 
@@ -1190,17 +1239,34 @@
 		$c_status		=  $p_status; #generic, unknown type
 
 		$h_status = bug_get_field( $p_bug_id, $p_field_name );
+		
+		if ( $p_field_name == 'due_date' ) {
+			if ( !date_is_null( $h_status )  ) {
+				$h_status = date( config_get ( 'short_date_format' ), $h_status );
+			} else {
+				$h_status = '';
+			}
+			$t_tmp = $p_status;
+			if ( !is_int( $p_status ) ) {
+				$t_tmp = strtotime( $p_status );
+			} 
+			if ( !date_is_null( $t_tmp ) ) {
+				$c_status = date( 'Y-m-d 00:00:01', $t_tmp );
+			} else {
+				$c_status = '';
+			}
+			$c_field_name = lang_get( 'due_date' );
+		}
 
 		# return if status is already set
 		if ( $c_status == $h_status ) {
 			return true;
 		}
-
 		$t_bug_table = db_get_table( 'mantis_bug_table' );
 
 		# Update fields
 		$query = "UPDATE $t_bug_table
-				  SET $c_field_name=" . db_param(0) . "
+				  SET $p_field_name=" . db_param(0) . "
 				  WHERE id=" .db_param(1);
 		db_query_bound( $query, Array( $c_status, $c_bug_id ) );
 
@@ -1210,7 +1276,7 @@
 		# log changes except for duplicate_id which is obsolete and should be removed in
 		# Mantis 1.3.
 		if ( $p_field_name != 'duplicate_id' ) {
-			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $p_status );
+			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $c_status );
 		}
 
 		bug_clear_cache( $p_bug_id );
@@ -1497,6 +1563,7 @@
 		$p_bug_data->summary			= string_attribute( $p_bug_data->summary );
 		$p_bug_data->sponsorship_total	= string_attribute( $p_bug_data->sponsorship_total );
 		$p_bug_data->sticky				= string_attribute( $p_bug_data->sticky );
+		$p_bug_data->due_date			= string_attribute( $p_bug_data->due_date );
 
 		$p_bug_data->description		= string_textarea( $p_bug_data->description );
 		$p_bug_data->steps_to_reproduce	= string_textarea( $p_bug_data->steps_to_reproduce );
@@ -1522,6 +1589,7 @@
 		$p_bug_data->summary			= string_display_line_links( $p_bug_data->summary );
 		$p_bug_data->sponsorship_total	= string_display_line( $p_bug_data->sponsorship_total );
 		$p_bug_data->sticky				= string_display_line( $p_bug_data->sticky );
+		$p_bug_data->due_date			= string_display_line( $p_bug_data->due_date );
 
 		$p_bug_data->description		= string_display_links( $p_bug_data->description );
 		$p_bug_data->steps_to_reproduce	= string_display_links( $p_bug_data->steps_to_reproduce );
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/core/columns_api.php mbt_duedate/core/columns_api.php
--- mantisbt/core/columns_api.php	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/core/columns_api.php	2008-04-15 15:15:18.000000000 -0500
@@ -521,8 +521,12 @@
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function print_column_edit( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 		global $t_icon_path, $t_update_bug_threshold;
-
-		echo '<td>';
+		
+		if ( bug_is_overdue( $p_row['id'] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] )) {
+			print "<td class=\"overdue\">";
+		} else {
+			echo '<td>';
+		}
 		if ( !bug_is_readonly( $p_row['id'] )
 			&& access_has_bug_level( $t_update_bug_threshold, $p_row['id'] ) ) {
 			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
@@ -532,6 +536,20 @@
 		} else {
 			echo '&nbsp;';
 		}
+		if ( bug_is_overdue( $p_row['id'] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] ) ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdue.png';
+			echo '" alt="' . lang_get( 'overdue' ) . '"';
+			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
+		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] )) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
+			echo '" alt="' . lang_get( 'due_date' ) . '"';
+			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
+		} else {
+			echo '&nbsp;';
+		}
+		
 		echo '</td>';
 	}
 
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/core/date_api.php mbt_duedate/core/date_api.php
--- mantisbt/core/date_api.php	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/core/date_api.php	2008-04-15 15:15:18.000000000 -0500
@@ -22,6 +22,20 @@
 	# --------------------------------------------------------
 
 	### Date API ###
+	# --------------------
+	# checks if date is null
+	function date_is_null ( $p_date ) {
+		if ( $p_date == date_get_null( ) ) {
+			return true;
+		}
+		return false;
+	}
+	
+	# --------------------
+	# gets null date 
+	function date_get_null ( ) {
+		return db_unixtimestamp( '1970-01-01 00:00:01' );
+	}
 
 	# --------------------
 	# prints the date given the formating string
@@ -149,4 +163,48 @@
 			}
 		}
 	}
+	
+	# --------------------
+	# prints calendar icon and adds required javascript files.
+	# button_name is name of button that will display calendar icon
+	# in caste there are more than one calendar on page
+	function date_print_calendar ( $p_button_name = 'trigger' ) {
+		# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			echo "<style type=\"text/css\">@import url(javascript/jscalendar/calendar-blue.css);</style>\n";
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/lang/calendar-en.js\"></script>\n"; 
+			echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar-setup.js\"></script>\n"; 	
+			$t_icon_path = config_get( 'icon_path' );
+			$t_cal_icon = $t_icon_path ."calendar-img.gif";	
+	   	 	echo "<input type=\"image\" class=\"button\" id=\"".$p_button_name."\" SRC=\"";
+	    	echo $t_cal_icon;
+			$t_format = config_get( 'short_date_format' );
+			$t_new_format = str_replace( '-', '-%', $t_format );
+			$t_format = "%".$t_new_format;
+			echo "\" onClick=\"return showCalendar ('sel1', '".$t_format."', 24, true)\" />";
+		}
+	}
+	# --------------------
+	# creates javascript calendar objects, point to input element ($p_field_name) that
+	# diaplays date, and connects it with calendar button ($p_button_name) created with
+	# date_print_calendar.
+	# should be called right after </form> tag
+	function date_finish_calendar ( $p_field_name, $p_button_name) {
+	# @@@ (thraxisp) this may want a browser check  ( MS IE >= 5.0, Mozilla >= 1.0, Safari >=1.2, ...)
+        if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
+			$t_format = config_get( 'short_date_format' );
+			$t_new_format = str_replace( '-', '-%', $t_format );
+			$t_format = "%".$t_new_format;
+			echo "<script type=\"text/javascript\">\n";
+			echo "Calendar.setup (\n";
+			echo "{\n";
+		 	echo "inputField 	: \"".$p_field_name."\",\n";
+		 	echo "ifFormat 	: \"".$t_format."\", \n";
+		 	echo "button		: \"".$p_button_name."\"\n";
+			echo "}\n";
+			echo ");\n";
+			echo "</script>\n";
+			}	
+	}
 ?>
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/core/filter_api.php mbt_duedate/core/filter_api.php
--- mantisbt/core/filter_api.php	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/core/filter_api.php	2008-04-15 15:15:18.000000000 -0500
@@ -1537,6 +1537,7 @@
 			
 			$row['date_submitted'] = db_unixtimestamp ( $row['date_submitted'] );
 			$row['last_updated'] = db_unixtimestamp ( $row['last_updated'] );
+			$row['due_date']	= db_unixtimestamp( $row['due_date'] );
 					
 			array_push( $rows, $row );
 		}
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/css/default.css mbt_duedate/css/default.css
--- mantisbt/css/default.css	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/css/default.css	2008-04-15 15:15:18.000000000 -0500
@@ -52,6 +52,7 @@
 td.left				{ text-align: left; }
 td.right			{ text-align: right; }
 td.category			{ background-color: #c8c8e8; color: #000000; font-weight: bold; vertical-align : top; }
+td.overdue			{ background-color: #ff0000; color: #000000; font-weight: bold; }
 
 td.col-1			{ background-color: #d8d8d8; color: #000000; }
 td.col-2			{ background-color: #e8e8e8; color: #000000; }
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/images/clock.png mbt_duedate/images/clock.png
--- mantisbt/images/clock.png	1969-12-31 17:00:00.000000000 -0700
+++ mbt_duedate/images/clock.png	2008-04-15 15:15:18.000000000 -0500
@@ -0,0 +1,8 @@
+�PNG
+
+
IHDR�agAMA��7��tEXtSoftwareAdobe ImageReadyq�e<IDAT8�]�kHSq��}��}�(
+�E�AAЇnA��X��Vd�Y�����դ��tv���<���Z�������.�czt{z�CGu�wxx��y��?7��M#Ԅ�xGLg�ٜɽ�H��s�@����L��X�Z�^+f�?���~;��tg��o%��
+<�\FȚ<06�o�{�)��CA��:�`�߇N�29���R��_�� 8ww>l��6��׌��t�7����M}�پ��	��7EF܏&���M�s�zJf�-�K�S���0�\�u��I�!���}ً�f>Ʌ]�z��d��&�."�^õ�J,.��4���2��I3�(Pd�E�ىzG˅���מ���=�M'��QH��;e��PQxt5/ހ���G0/��v��T�\}`�gD��hc�8����	�/j�R��Tp��
+�e�x��+��J�P���/)T�;ƥ��0o��8�ާ�x^+��e��/<6�i�Fہ�� ~�G��
+��[��app�@�N��yY&^�t�R�E]�����"�taC
+��T�%}N+BŨyY&^��x�r�k���᪾6W݇$+��Ϊ�U�0�L����`��#�ZyÙZ��}���<�nY�z��<�s�c�e#dU����� I�M&~b�R�P�*���-�+�li��B���)0��	��t�����tw�f��3ោi5�¢(���ĂxAUU�L��#��+OA��D� ������ߟ��IEND�B`�
\ No newline at end of file
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/images/overdue.png mbt_duedate/images/overdue.png
--- mantisbt/images/overdue.png	1969-12-31 17:00:00.000000000 -0700
+++ mbt_duedate/images/overdue.png	2008-04-15 15:15:18.000000000 -0500
@@ -0,0 +1,5 @@
+�PNG
+
+
IHDR�agAMA��7��tEXtSoftwareAdobe ImageReadyq�e<,IDAT8�]�kHa�� �2�Z��X$a%I��E�E?�C?*��Q��.YY�M�LKk���R+��4�k��m^�5���]����qLG��|�Y4��o���0��:�rC� >�����ā�6"��92qC�3���3���~[�rK�k�'���E���}G��6M�~1I���H�M-=���(��h�'�[�R�Ǎ�6
V��Pm����zE���N^%1����Fi��tK�z{^��f�s�� |E�������&�ߑ�Ό��%�]�}��S]��r_����9�]e�ӕ3�&ܵ5�d���+! ��:�j�P��y��{��!��6'���Xm�7��|�D��#McW0FCK~P͐�J�Żq�(`g����vې]�x�ĵ�.��d��'dE�ռ|�)(�ݍ�/�Bh��X/s�d
+b��
+��8��R��G=8����	���gXž,X/sV�z.n˵A�oG��RH?��Nd��d��	��ǀ�=��`��H>��_{�}a%޹�h���FT<���$J�x�9�}��z�3�t�n��1�^�"��B-,��~��H��C�0RL�D`�x�����d�5��#%[�ic=�dڇ��pP�De�jt�\	i�2����u�ؿ����w�*=��WH�, ��)J�;ӬMd�8s&���О���ѣ�X��$�Ӊ7f�/qW.f�6`�^���4M\�mS��e�d�&&�*:��\RRC�n�E���i���GxB�o3�4ћ��o��(���PPPE�=Ĵ�e�sԨ:6�b�HM����_5�ӡ��IEND�B`�
\ No newline at end of file
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/lang/strings_english.txt mbt_duedate/lang/strings_english.txt
--- mantisbt/lang/strings_english.txt	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/lang/strings_english.txt	2008-04-15 15:15:19.000000000 -0500
@@ -1513,6 +1513,10 @@
 $s_copy_columns_from = 'Copy Columns From';
 $s_copy_columns_to = 'Copy Columns To';
 
+# due date
+$s_due_date = "Due Date";
+$s_overdue = "Overdue";
+
 # mind mapping
 $s_mindmap = 'Mindmap';
 $s_freemind_export = 'Freemind Export';
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/lang/strings_polish_8859-2.txt mbt_duedate/lang/strings_polish_8859-2.txt
--- mantisbt/lang/strings_polish_8859-2.txt	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/lang/strings_polish_8859-2.txt	2008-04-15 15:15:19.000000000 -0500
@@ -1336,4 +1336,7 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
+$s_due_date = "Termin realizacji";
+$s_overdue = "Przeterminowane";
+
 ?>
diff -auNr --exclude=CVS --exclude=.svn --exclude='.git*' --exclude='*.swp' --exclude=config_inc.php mantisbt/lang/strings_polish.txt mbt_duedate/lang/strings_polish.txt
--- mantisbt/lang/strings_polish.txt	2008-04-15 15:15:31.000000000 -0500
+++ mbt_duedate/lang/strings_polish.txt	2008-04-15 15:15:19.000000000 -0500
@@ -1336,4 +1336,7 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
+$s_due_date = "Termin realizacji";
+$s_overdue = "Przeterminowane";
+
 ?>
duedate_stage1_final8.diff (29,054 bytes)   
duedate_stage1_fix1.diff (5,260 bytes)   
Index: core/date_api.php
===================================================================
--- core/date_api.php	(revision 5175)
+++ core/date_api.php	(working copy)
@@ -25,7 +25,7 @@
 	# --------------------
 	# checks if date is null
 	function date_is_null ( $p_date ) {
-		if ( $p_date == date_get_null( ) ) {
+		if ( $p_date <= date_get_null( ) ) {
 			return true;
 		}
 		return false;
Index: core/bug_api.php
===================================================================
--- core/bug_api.php	(revision 5175)
+++ core/bug_api.php	(working copy)
@@ -109,7 +109,7 @@
 		if( !is_int( $p_bug_database_result['last_updated'] ) )
 			$p_bug_database_result['last_updated']	= db_unixtimestamp( $p_bug_database_result['last_updated'] );
 		if( !is_int( $p_bug_database_result['due_date'] ) ) 
-			$p_bug_datebase_result['due_date']	= db_unixtimestamp( $p_bug_datebase_result['due_date'] );
+			$p_bug_database_result['due_date']	= db_unixtimestamp( $p_bug_database_result['due_date'] );
 		$g_cache_bug[ $p_bug_database_result['id'] ] = $p_bug_database_result;
 		if( !is_null( $p_stats ) ) {
 			$g_cache_bug[ $p_bug_database_result['id'] ]['_stats'] = $p_stats;
@@ -1242,7 +1242,7 @@
 		
 		if ( $p_field_name == 'due_date' ) {
 			if ( !date_is_null( $h_status )  ) {
-				$h_status = date( config_get ( 'short_date_format' ), $h_status );
+				$h_status = date( config_get( 'short_date_format' ), $h_status );
 			} else {
 				$h_status = '';
 			}
@@ -1251,7 +1251,7 @@
 				$t_tmp = strtotime( $p_status );
 			} 
 			if ( !date_is_null( $t_tmp ) ) {
-				$c_status = date( 'Y-m-d', $t_tmp );
+				$c_status = date( config_get( 'short_date_format' ), $t_tmp );
 			} else {
 				$c_status = '';
 			}
Index: core/version_api.php
===================================================================
--- core/version_api.php	(revision 5175)
+++ core/version_api.php	(working copy)
@@ -315,18 +315,22 @@
 	function version_get_all_rows_with_subs( $p_project_id, $p_released = null, $p_obsolete = false ) {
 		$t_project_where = helper_project_specific_where( $p_project_id );
 
+		$t_param_count = 0;
+
 		if ( $p_released === null ) {
 			$t_released_where = '';
 		} else {
 			$c_released = db_prepare_int( $p_released );
-			$t_released_where = "AND ( released = $c_released )";
+			$t_released_where = "AND ( released = ". db_param($t_param_count++)." )";
+			$query_params[] = $c_released;
 		}
 
 		if ( $p_obsolete === null ) {
 			$t_obsolete_where = '';
 		} else {
 			$c_obsolete = db_prepare_bool( $p_obsolete );
-			$t_obsolete_where = "AND ( obsolete = $c_obsolete )";
+			$t_obsolete_where = "AND ( obsolete = ". db_param($t_param_count++)." )";
+			$query_params[] = $c_obsolete;
 		}
 
 		$t_project_version_table = db_get_table( 'mantis_project_version_table' );
@@ -335,7 +339,7 @@
 				  FROM $t_project_version_table
 				  WHERE $t_project_where $t_released_where $t_obsolete_where
 				  ORDER BY date_order DESC";
-		$result = db_query( $query );
+		$result = db_query_bound( $query, $query_params );
 		$count = db_num_rows( $result );
 		$rows = array();
 		for ( $i = 0 ; $i < $count ; $i++ ) {
Index: core/columns_api.php
===================================================================
--- core/columns_api.php	(revision 5175)
+++ core/columns_api.php	(working copy)
@@ -521,14 +521,16 @@
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function print_column_edit( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 		global $t_icon_path, $t_update_bug_threshold;
+		$t_is_overdue = bug_is_overdue( $p_row[ 'id' ] );
+		$t_view_level = access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] );
 		
-		if ( bug_is_overdue( $p_row['id'] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] )) {
+		if ( $t_is_overdue && $t_view_level ) {
 			print "<td class=\"overdue\">";
 		} else {
 			echo '<td>';
 		}
 		if ( !bug_is_readonly( $p_row['id'] )
-			&& access_has_bug_level( $t_update_bug_threshold, $p_row['id'] ) ) {
+			&& access_has_bug_level( config_get( 'update_bug_threshold' ), $p_row['id'] ) ) {
 			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
 			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'update.png';
 			echo '" alt="' . lang_get( 'update_bug_button' ) . '"';
@@ -536,12 +538,12 @@
 		} else {
 			echo '&nbsp;';
 		}
-		if ( bug_is_overdue( $p_row['id'] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] ) ) {
+		if ( $t_is_overdue && $t_view_level ) {
 			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
 			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdue.png';
 			echo '" alt="' . lang_get( 'overdue' ) . '"';
 			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
-		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] )) {
+		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && $t_view_level ) {
 			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
 			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
 			echo '" alt="' . lang_get( 'due_date' ) . '"';
duedate_stage1_fix1.diff (5,260 bytes)   
duedate_stage3_22_04_2008.diff (17,221 bytes)   
Index: bug_change_status_page.php
===================================================================
--- bug_change_status_page.php	(revision 5190)
+++ bug_change_status_page.php	(working copy)
@@ -53,6 +53,7 @@
 		access_denied();
 	}
 	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
+	
 	# get new issue handler if set, otherwise default to original handler
 	$f_handler_id = gpc_get_int( 'handler_id', bug_get_field( $f_bug_id, 'handler_id' ) );
 
@@ -162,7 +163,7 @@
 <?php } ?>
 
 <!-- Due date -->
-<?php if ( $t_can_update_due_date ) {
+<?php if ( $t_can_update_due_date && $f_new_status < $t_resolved ) {
 	$t_date_to_display = '';
 	if ( ! date_is_null( $t_bug->due_date ) ) {
 			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
@@ -341,7 +342,7 @@
 </div>
 
 <?php
-if ( $t_can_update_due_date ) {
+if ( $t_can_update_due_date && $f_new_status < $t_resolved ) {
 	date_finish_calendar( 'due_date', 'trigger');
 } ?>
 <br />
Index: lang/strings_english.txt
===================================================================
--- lang/strings_english.txt	(revision 5190)
+++ lang/strings_english.txt	(working copy)
@@ -1516,8 +1516,9 @@
 # due date
 $s_due_date = "Due Date";
 $s_overdue = "Overdue";
+$s_due_days = "Due days";
 
 # mind mapping
 $s_mindmap = 'Mindmap';
 $s_freemind_export = 'Freemind Export';
-?>
\ No newline at end of file
+?>
Index: lang/strings_polish.txt
===================================================================
--- lang/strings_polish.txt	(revision 5190)
+++ lang/strings_polish.txt	(working copy)
@@ -1338,5 +1338,5 @@
 
 $s_due_date = "Termin realizacji";
 $s_overdue = "Przeterminowane";
-
+$s_due_days = "Due days";
 ?>
Index: print_all_bug_page_word.php
===================================================================
--- print_all_bug_page_word.php	(revision 5190)
+++ print_all_bug_page_word.php	(working copy)
@@ -93,6 +93,9 @@
 		# prefix bug data with v_
 		# extract( $result[$j], EXTR_PREFIX_ALL, 'v' );
 		$t_id = $result[$j]['id'];
+		
+		$t_can_view_due_date = access_has_bug_level( config_get( 'due_date_view_threshold' ), $t_id );
+		$t_overdue = bug_is_overdue( $t_id );
 
 		# display the available and selected bugs
 		if ( in_array( $t_id, $f_bug_arr ) || !$f_show_flag ) {
@@ -185,7 +188,25 @@
 	<td class="print">
 		<?php echo $t_bug->platform ?>
 	</td>
+<?php if ( $t_can_view_due_date ) { ?>
+	<td class="print-category">
+		<?php echo lang_get( 'due_date' ) ?>:
+	</td>
+<?php
+		if ( $t_overdue ) { ?>
+		<td class="print-overdue">
+<?php
+		} else	{ ?>
+		<td class="print">
+<?php
+		}
+		if ( !date_is_null( $t_bug->due_date ) ) {
+				print_date( config_get( 'short_date_format' ), $t_bug->due_date ); }
+	} else {
+?>
 	<td class="print" colspan="2">&nbsp;</td>
+<?php } 
+?>
 </tr>
 <tr class="print">
 	<td class="print-category">
Index: excel_xml_export.php
===================================================================
--- excel_xml_export.php	(revision 5190)
+++ excel_xml_export.php	(working copy)
@@ -95,7 +95,13 @@
 							echo excel_format_custom_field( $t_row['id'], $t_row['project_id'], $t_custom_field );
 						} else {
 							$t_function = 'excel_format_' . $t_column;
-							echo $t_function( $t_row[$t_column] );
+							if ( $t_column === 'overdue' ) {
+								echo $t_function( $t_row[ 'id' ], $t_row[ $t_column ] );
+							} else if ( $t_column === 'due_days' ) {
+								echo $t_function( $t_row[ 'due_date' ] );
+							} else {
+								echo $t_function( $t_row[ $t_column ] );
+							}
 						}
 					}
 				}
@@ -122,4 +128,4 @@
 	} while ( $t_more );
 
 	echo excel_get_footer();
-?>
\ No newline at end of file
+?>
Index: css/default.css
===================================================================
--- css/default.css	(revision 5190)
+++ css/default.css	(working copy)
@@ -53,6 +53,8 @@
 td.right			{ text-align: right; }
 td.category			{ background-color: #c8c8e8; color: #000000; font-weight: bold; vertical-align : top; }
 td.overdue			{ background-color: #ff0000; color: #000000; font-weight: bold; }
+td.overdue2			{ background-color: #ff0000; color: #000000; font-weight: bold; text-align: center}
+td.due2				{ text-align: center}
 
 td.col-1			{ background-color: #d8d8d8; color: #000000; }
 td.col-2			{ background-color: #e8e8e8; color: #000000; }
@@ -61,6 +63,7 @@
 td.small-caption	{ font-size: 8pt; }
 td.print			{ font-size: 8pt; text-align: left; padding: 2px; }
 td.print-category	{ font-size: 8pt; color: #000000; font-weight: bold; text-align: right; padding: 2px; }
+td.print-overdue	{ font-size: 8pt; color: #000000; font-weight: bold; padding: 2px; }
 td.print-bottom		{ border-bottom: 1px solid #000000; }
 td.print-spacer		{ background-color: #ffffff; color: #000000; font-size: 1pt; line-height: 0.1; padding: 0px;}
 
Index: config_defaults_inc.php
===================================================================
--- config_defaults_inc.php	(revision 5190)
+++ config_defaults_inc.php	(working copy)
@@ -528,7 +528,7 @@
 	# selection, edit, id, project_id, reporter_id, handler_id, priority, reproducibility, projection, eta,
 	# resolution, fixed_in_version, view_state, os, os_build, build (for product build), platform, version, date_submitted, attachment,
 	# category, sponsorship_total, severity, status, last_updated, summary, bugnotes_count, description,
-	# steps_to_reproduce, additional_information
+	# steps_to_reproduce, additional_information, due_date, overdue, due_days
 	$g_view_issues_page_columns = array ( 'selection', 'edit', 'priority', 'id', 'sponsorship_total', 'bugnotes_count', 'attachment', 'category', 'severity', 'status', 'last_updated', 'summary' );
 	
 	# The default columns to be included in the Print Issues Page.
Index: csv_export.php
===================================================================
--- csv_export.php	(revision 5190)
+++ csv_export.php	(working copy)
@@ -121,7 +121,13 @@
 				}
 
 				$t_function = 'csv_format_' . $t_column;
-				echo $t_function( $t_row[ $t_column ] );
+				if ( $t_column === 'overdue' ) {
+					echo $t_function( $t_row[ 'id' ], $t_row[ $t_column ] );
+				} else if ( $t_column === 'due_days' ) {
+					echo $t_function( $t_row[ 'due_date' ] );
+				} else {
+					echo $t_function( $t_row[ $t_column ] );
+				}
 			}
 		}
 
Index: core/bug_api.php
===================================================================
--- core/bug_api.php	(revision 5190)
+++ core/bug_api.php	(working copy)
@@ -350,6 +350,8 @@
 			$t_now = db_unixtimestamp();
 			if ( $t_now > $t_due_date ) {
 				if ( bug_is_resolved( $p_bug_id ) ) {
+					return false;
+				} else {
 					return true;
 				}
 			}
@@ -1238,11 +1240,12 @@
 		$c_field_name		= db_prepare_string( $p_field_name );
 		$c_status		=  $p_status; #generic, unknown type
 
+		$t_log_status = $c_status;
 		$h_status = bug_get_field( $p_bug_id, $p_field_name );
 		
 		if ( $p_field_name == 'due_date' ) {
 			if ( !date_is_null( $h_status )  ) {
-				$h_status = date( config_get( 'short_date_format' ), $h_status );
+				$h_status = date( config_get( 'Y-m-d' ), $h_status );
 			} else {
 				$h_status = '';
 			}
@@ -1251,9 +1254,11 @@
 				$t_tmp = strtotime( $p_status );
 			} 
 			if ( !date_is_null( $t_tmp ) ) {
-				$c_status = date( config_get( 'short_date_format' ), $t_tmp );
+				$c_status = date(  'Y-m-d 00:00:01', $t_tmp );
+				$t_log_status = date( config_get( 'short_date_format' ), $t_tmp );
 			} else {
 				$c_status = '';
+				$t_log_status = '';
 			}
 			$c_field_name = lang_get( 'due_date' );
 		}
@@ -1276,7 +1281,7 @@
 		# log changes except for duplicate_id which is obsolete and should be removed in
 		# Mantis 1.3.
 		if ( $p_field_name != 'duplicate_id' ) {
-			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $c_status );
+			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $t_log_status );
 		}
 
 		bug_clear_cache( $p_bug_id );
Index: core/csv_api.php
===================================================================
--- core/csv_api.php	(revision 5190)
+++ core/csv_api.php	(working copy)
@@ -249,4 +249,41 @@
 	function csv_format_selection( $p_duplicate_id ) {
 		return csv_escape_string( '' );
 	}
+	
+	# --------------------
+	# return due_date
+	function csv_format_due_date( $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $p_due_date );
+		}
+		return csv_escape_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return overdue
+	function csv_format_overdue( $p_bug_id, $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			if ( bug_is_overdue( $p_bug_id ) ) {
+				$t_date_to_display = lang_get( 'yes' );
+			} else {
+				$t_date_to_display = lang_get( 'no' );
+			}
+		}
+		return csv_escape_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return due days
+	function csv_format_due_days( $p_due_date ) {
+		$t_date_to_display = '';
+		
+		$t_date = number_format(floor((date("U")-$p_due_date)/86400),0);
+		
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = -(number_format(floor((date("U")-$p_due_date)/86400),0));
+		}
+		return csv_escape_string( $t_date_to_display );
+	}
 ?>
Index: core/excel_api.php
===================================================================
--- core/excel_api.php	(revision 5190)
+++ core/excel_api.php	(working copy)
@@ -423,4 +423,42 @@
 		// field is not linked to project
 		return excel_prepare_string( '' );
 	}
-?>
\ No newline at end of file
+	
+	# --------------------
+	# return due_date
+	function excel_format_due_date( $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $p_due_date );
+		}
+		return excel_prepare_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return overdue
+	function excel_format_overdue( $p_bug_id, $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			if ( bug_is_overdue( $p_bug_id ) ) {
+				$t_date_to_display = lang_get( 'yes' );
+			} else {
+				$t_date_to_display = lang_get( 'no' );
+			}
+		}
+		return excel_prepare_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return due days
+	function excel_format_due_days( $p_due_date ) {
+		$t_date_to_display = '';
+		
+		$t_date = number_format(floor((date("U")-$p_due_date)/86400),0);
+		
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = -(number_format(floor((date("U")-$p_due_date)/86400),0));
+		}
+		return excel_prepare_string( $t_date_to_display );
+	}
+	
+?>
Index: core/custom_function_api.php
===================================================================
--- core/custom_function_api.php	(revision 5190)
+++ core/custom_function_api.php	(working copy)
@@ -231,6 +231,12 @@
 	function custom_function_default_print_column_title( $p_column, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 		global $t_sort, $t_dir;
 
+		$t_view_due_date = config_get( 'due_date_view_threshold' );
+		
+		if ( current_user_get_access_level() < $t_view_due_date && 
+			( $p_column === 'due_date' || $p_column === 'overdue' || $p_column === 'due_days' ) )
+			return;
+		
 		$t_custom_field = column_get_custom_field_name( $p_column );
 		if ( $t_custom_field !== null ) {
 			if ( COLUMNS_TARGET_CSV_PAGE != $p_columns_target ) {
@@ -276,6 +282,13 @@
 	# $p_row: the row from the bug table that belongs to the issue that we should print the values for.
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function custom_function_default_print_column_value( $p_column, $p_issue_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+	
+		$t_view_due_date = config_get( 'due_date_view_threshold' );
+		
+		if ( current_user_get_access_level() < $t_view_due_date && 
+			( $p_column === 'due_date' || $p_column === 'overdue' || $p_column === 'due_days' ) )
+			return;	
+	
 		if ( COLUMNS_TARGET_CSV_PAGE == $p_columns_target ) {
 			$t_column_start = '';
 			$t_column_end = '';
Index: core/columns_api.php
===================================================================
--- core/columns_api.php	(revision 5190)
+++ core/columns_api.php	(working copy)
@@ -56,6 +56,9 @@
 			'summary',
 			'version',
 			'view_state',
+			'due_date',
+			'overdue',
+			'due_days'
 		);
 
 		# Add project custom fields to the array.  Only add the ones for which the current user has at least read access.
@@ -520,39 +523,21 @@
 	# --------------------
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function print_column_edit( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
-		global $t_icon_path, $t_update_bug_threshold;
-		$t_is_overdue = bug_is_overdue( $p_row[ 'id' ] );
-		$t_view_level = access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] );
-		
-		if ( $t_is_overdue && $t_view_level ) {
-			print "<td class=\"overdue\">";
-		} else {
+		if ( $p_columns_target != COLUMNS_TARGET_CSV_PAGE ) {
+			global $t_icon_path, $t_update_bug_threshold;
+
 			echo '<td>';
+			if ( !bug_is_readonly( $p_row['id'] )
+		  		&& access_has_bug_level( $t_update_bug_threshold, $p_row['id'] ) ) {
+				echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+				echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'update.png';
+				echo '" alt="' . lang_get( 'update_bug_button' ) . '"';
+				echo ' title="' . lang_get( 'update_bug_button' ) . '" /></a>';
+			} else {
+				echo '&nbsp;';
+			}
+			echo '</td>';
 		}
-		if ( !bug_is_readonly( $p_row['id'] )
-			&& access_has_bug_level( config_get( 'update_bug_threshold' ), $p_row['id'] ) ) {
-			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
-			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'update.png';
-			echo '" alt="' . lang_get( 'update_bug_button' ) . '"';
-			echo ' title="' . lang_get( 'update_bug_button' ) . '" /></a>';
-		} else {
-			echo '&nbsp;';
-		}
-		if ( $t_is_overdue && $t_view_level ) {
-			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
-			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdue.png';
-			echo '" alt="' . lang_get( 'overdue' ) . '"';
-			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
-		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && $t_view_level ) {
-			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
-			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
-			echo '" alt="' . lang_get( 'due_date' ) . '"';
-			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
-		} else {
-			echo '&nbsp;';
-		}
-		
-		echo '</td>';
 	}
 
 	# --------------------
@@ -775,6 +760,20 @@
 				, lang_get( 'private' )
 			);
 		}
+		$t_is_overdue = bug_is_overdue( $p_row[ 'id' ] );
+		$t_view_level = access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] );
+		
+		if ( $t_is_overdue && $t_view_level ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdue.png';
+			echo '" alt="' . lang_get( 'overdue' ) . '"';
+			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
+		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && $t_view_level ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
+			echo '" alt="' . lang_get( 'due_date' ) . '"';
+			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
+		} 
 		echo '</td>';
 	}
 
@@ -822,4 +821,44 @@
 
 		echo '</td>';
 	}
+	
+	# --------------------
+	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
+	function print_column_due_date( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_row['due_date'] ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $p_row['due_date'] );
+		}
+		echo '<td>', $t_date_to_display, '</td>';
+	}
+
+	# --------------------
+	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
+	function print_column_overdue( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+		$t_date_to_display = '';
+		$t_cell = '<td class="due2">';
+		if ( !date_is_null( $p_row['due_date'] ) ) {
+			if ( bug_is_overdue( $p_row['id'] ) ) {
+				$t_cell = '<td class="overdue2">';
+				$t_date_to_display = lang_get( 'yes' );
+			} else {
+				$t_date_to_display = lang_get( 'no' );
+			}
+		}
+		echo $t_cell, $t_date_to_display, '</td>';
+	}
+
+	# --------------------
+	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
+	function print_column_due_days( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+		$t_date_to_display = '';
+		
+		$t_date = number_format(floor((date("U")-$p_row['due_date'])/86400),0);
+		
+		if ( !date_is_null( $p_row['due_date'] ) ) {
+			$t_date_to_display = -(number_format(floor((date("U")-$p_row['due_date'])/86400),0));
+		}
+		echo '<td>', $t_date_to_display, '</td>';
+	}
+
 ?>
duedate_stage3_22_04_2008.diff (17,221 bytes)   
duedate_stage3_23_04_2008.diff (17,233 bytes)   
Index: bug_change_status_page.php
===================================================================
--- bug_change_status_page.php	(revision 5190)
+++ bug_change_status_page.php	(working copy)
@@ -53,6 +53,7 @@
 		access_denied();
 	}
 	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
+	
 	# get new issue handler if set, otherwise default to original handler
 	$f_handler_id = gpc_get_int( 'handler_id', bug_get_field( $f_bug_id, 'handler_id' ) );
 
@@ -162,7 +163,7 @@
 <?php } ?>
 
 <!-- Due date -->
-<?php if ( $t_can_update_due_date ) {
+<?php if ( $t_can_update_due_date && $f_new_status < $t_resolved ) {
 	$t_date_to_display = '';
 	if ( ! date_is_null( $t_bug->due_date ) ) {
 			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
@@ -341,7 +342,7 @@
 </div>
 
 <?php
-if ( $t_can_update_due_date ) {
+if ( $t_can_update_due_date && $f_new_status < $t_resolved ) {
 	date_finish_calendar( 'due_date', 'trigger');
 } ?>
 <br />
Index: lang/strings_english.txt
===================================================================
--- lang/strings_english.txt	(revision 5190)
+++ lang/strings_english.txt	(working copy)
@@ -1516,8 +1516,9 @@
 # due date
 $s_due_date = "Due Date";
 $s_overdue = "Overdue";
+$s_due_days = "Due days";
 
 # mind mapping
 $s_mindmap = 'Mindmap';
 $s_freemind_export = 'Freemind Export';
-?>
\ No newline at end of file
+?>
Index: lang/strings_polish.txt
===================================================================
--- lang/strings_polish.txt	(revision 5190)
+++ lang/strings_polish.txt	(working copy)
@@ -1338,5 +1338,5 @@
 
 $s_due_date = "Termin realizacji";
 $s_overdue = "Przeterminowane";
-
+$s_due_days = "Due days";
 ?>
Index: print_all_bug_page_word.php
===================================================================
--- print_all_bug_page_word.php	(revision 5190)
+++ print_all_bug_page_word.php	(working copy)
@@ -93,6 +93,9 @@
 		# prefix bug data with v_
 		# extract( $result[$j], EXTR_PREFIX_ALL, 'v' );
 		$t_id = $result[$j]['id'];
+		
+		$t_can_view_due_date = access_has_bug_level( config_get( 'due_date_view_threshold' ), $t_id );
+		$t_overdue = bug_is_overdue( $t_id );
 
 		# display the available and selected bugs
 		if ( in_array( $t_id, $f_bug_arr ) || !$f_show_flag ) {
@@ -185,7 +188,27 @@
 	<td class="print">
 		<?php echo $t_bug->platform ?>
 	</td>
+<?php if ( $t_can_view_due_date ) { ?>
+	<td class="print-category">
+		<?php echo lang_get( 'due_date' ) ?>:
+	</td>
+<?php
+		if ( $t_overdue ) { ?>
+		<td class="print-overdue">
+<?php
+		} else	{ ?>
+		<td class="print">
+<?php
+		}
+		if ( !date_is_null( $t_bug->due_date ) ) {
+				print_date( config_get( 'short_date_format' ), $t_bug->due_date ); 
+		print "</td>";
+		}
+	} else {
+?>
 	<td class="print" colspan="2">&nbsp;</td>
+<?php } 
+?>
 </tr>
 <tr class="print">
 	<td class="print-category">
Index: excel_xml_export.php
===================================================================
--- excel_xml_export.php	(revision 5190)
+++ excel_xml_export.php	(working copy)
@@ -95,7 +95,13 @@
 							echo excel_format_custom_field( $t_row['id'], $t_row['project_id'], $t_custom_field );
 						} else {
 							$t_function = 'excel_format_' . $t_column;
-							echo $t_function( $t_row[$t_column] );
+							if ( $t_column == 'overdue' ) {
+								echo $t_function( $t_row[ 'id' ], $t_row[ $t_column ] );
+							} else if ( $t_column == 'due_days' ) {
+								echo $t_function( $t_row[ 'due_date' ] );
+							} else {
+								echo $t_function( $t_row[ $t_column ] );
+							}
 						}
 					}
 				}
@@ -122,4 +128,4 @@
 	} while ( $t_more );
 
 	echo excel_get_footer();
-?>
\ No newline at end of file
+?>
Index: css/default.css
===================================================================
--- css/default.css	(revision 5190)
+++ css/default.css	(working copy)
@@ -53,6 +53,8 @@
 td.right			{ text-align: right; }
 td.category			{ background-color: #c8c8e8; color: #000000; font-weight: bold; vertical-align : top; }
 td.overdue			{ background-color: #ff0000; color: #000000; font-weight: bold; }
+td.overdue2			{ background-color: #ff0000; color: #000000; font-weight: bold; text-align: center}
+td.due2				{ text-align: center}
 
 td.col-1			{ background-color: #d8d8d8; color: #000000; }
 td.col-2			{ background-color: #e8e8e8; color: #000000; }
@@ -61,6 +63,7 @@
 td.small-caption	{ font-size: 8pt; }
 td.print			{ font-size: 8pt; text-align: left; padding: 2px; }
 td.print-category	{ font-size: 8pt; color: #000000; font-weight: bold; text-align: right; padding: 2px; }
+td.print-overdue	{ font-size: 8pt; color: #000000; font-weight: bold; padding: 2px; }
 td.print-bottom		{ border-bottom: 1px solid #000000; }
 td.print-spacer		{ background-color: #ffffff; color: #000000; font-size: 1pt; line-height: 0.1; padding: 0px;}
 
Index: config_defaults_inc.php
===================================================================
--- config_defaults_inc.php	(revision 5190)
+++ config_defaults_inc.php	(working copy)
@@ -528,7 +528,7 @@
 	# selection, edit, id, project_id, reporter_id, handler_id, priority, reproducibility, projection, eta,
 	# resolution, fixed_in_version, view_state, os, os_build, build (for product build), platform, version, date_submitted, attachment,
 	# category, sponsorship_total, severity, status, last_updated, summary, bugnotes_count, description,
-	# steps_to_reproduce, additional_information
+	# steps_to_reproduce, additional_information, due_date, overdue, due_days
 	$g_view_issues_page_columns = array ( 'selection', 'edit', 'priority', 'id', 'sponsorship_total', 'bugnotes_count', 'attachment', 'category', 'severity', 'status', 'last_updated', 'summary' );
 	
 	# The default columns to be included in the Print Issues Page.
Index: csv_export.php
===================================================================
--- csv_export.php	(revision 5190)
+++ csv_export.php	(working copy)
@@ -121,7 +121,13 @@
 				}
 
 				$t_function = 'csv_format_' . $t_column;
-				echo $t_function( $t_row[ $t_column ] );
+				if ( $t_column == 'overdue' ) {
+					echo $t_function( $t_row[ 'id' ], $t_row[ $t_column ] );
+				} else if ( $t_column == 'due_days' ) {
+					echo $t_function( $t_row[ 'due_date' ] );
+				} else {
+					echo $t_function( $t_row[ $t_column ] );
+				}
 			}
 		}
 
Index: core/bug_api.php
===================================================================
--- core/bug_api.php	(revision 5190)
+++ core/bug_api.php	(working copy)
@@ -350,6 +350,8 @@
 			$t_now = db_unixtimestamp();
 			if ( $t_now > $t_due_date ) {
 				if ( bug_is_resolved( $p_bug_id ) ) {
+					return false;
+				} else {
 					return true;
 				}
 			}
@@ -1238,11 +1240,12 @@
 		$c_field_name		= db_prepare_string( $p_field_name );
 		$c_status		=  $p_status; #generic, unknown type
 
+		$t_log_status = $c_status;
 		$h_status = bug_get_field( $p_bug_id, $p_field_name );
 		
 		if ( $p_field_name == 'due_date' ) {
 			if ( !date_is_null( $h_status )  ) {
-				$h_status = date( config_get( 'short_date_format' ), $h_status );
+				$h_status = date( config_get( 'Y-m-d' ), $h_status );
 			} else {
 				$h_status = '';
 			}
@@ -1251,9 +1254,11 @@
 				$t_tmp = strtotime( $p_status );
 			} 
 			if ( !date_is_null( $t_tmp ) ) {
-				$c_status = date( config_get( 'short_date_format' ), $t_tmp );
+				$c_status = date(  'Y-m-d 00:00:01', $t_tmp );
+				$t_log_status = date( config_get( 'short_date_format' ), $t_tmp );
 			} else {
 				$c_status = '';
+				$t_log_status = '';
 			}
 			$c_field_name = lang_get( 'due_date' );
 		}
@@ -1276,7 +1281,7 @@
 		# log changes except for duplicate_id which is obsolete and should be removed in
 		# Mantis 1.3.
 		if ( $p_field_name != 'duplicate_id' ) {
-			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $c_status );
+			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $t_log_status );
 		}
 
 		bug_clear_cache( $p_bug_id );
Index: core/csv_api.php
===================================================================
--- core/csv_api.php	(revision 5190)
+++ core/csv_api.php	(working copy)
@@ -249,4 +249,41 @@
 	function csv_format_selection( $p_duplicate_id ) {
 		return csv_escape_string( '' );
 	}
+	
+	# --------------------
+	# return due_date
+	function csv_format_due_date( $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $p_due_date );
+		}
+		return csv_escape_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return overdue
+	function csv_format_overdue( $p_bug_id, $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			if ( bug_is_overdue( $p_bug_id ) ) {
+				$t_date_to_display = lang_get( 'yes' );
+			} else {
+				$t_date_to_display = lang_get( 'no' );
+			}
+		}
+		return csv_escape_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return due days
+	function csv_format_due_days( $p_due_date ) {
+		$t_date_to_display = '';
+		
+		$t_date = number_format(floor((date("U")-$p_due_date)/86400),0);
+		
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = -(number_format(floor((date("U")-$p_due_date)/86400),0));
+		}
+		return csv_escape_string( $t_date_to_display );
+	}
 ?>
Index: core/excel_api.php
===================================================================
--- core/excel_api.php	(revision 5190)
+++ core/excel_api.php	(working copy)
@@ -423,4 +423,42 @@
 		// field is not linked to project
 		return excel_prepare_string( '' );
 	}
-?>
\ No newline at end of file
+	
+	# --------------------
+	# return due_date
+	function excel_format_due_date( $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $p_due_date );
+		}
+		return excel_prepare_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return overdue
+	function excel_format_overdue( $p_bug_id, $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			if ( bug_is_overdue( $p_bug_id ) ) {
+				$t_date_to_display = lang_get( 'yes' );
+			} else {
+				$t_date_to_display = lang_get( 'no' );
+			}
+		}
+		return excel_prepare_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return due days
+	function excel_format_due_days( $p_due_date ) {
+		$t_date_to_display = '';
+		
+		$t_date = number_format(floor((date("U")-$p_due_date)/86400),0);
+		
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = -(number_format(floor((date("U")-$p_due_date)/86400),0));
+		}
+		return excel_prepare_string( $t_date_to_display );
+	}
+	
+?>
Index: core/custom_function_api.php
===================================================================
--- core/custom_function_api.php	(revision 5190)
+++ core/custom_function_api.php	(working copy)
@@ -231,6 +231,12 @@
 	function custom_function_default_print_column_title( $p_column, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 		global $t_sort, $t_dir;
 
+		$t_view_due_date = config_get( 'due_date_view_threshold' );
+		
+		if ( current_user_get_access_level() < $t_view_due_date && 
+			( $p_column == 'due_date' || $p_column == 'overdue' || $p_column == 'due_days' ) )
+			return;
+		
 		$t_custom_field = column_get_custom_field_name( $p_column );
 		if ( $t_custom_field !== null ) {
 			if ( COLUMNS_TARGET_CSV_PAGE != $p_columns_target ) {
@@ -276,6 +282,13 @@
 	# $p_row: the row from the bug table that belongs to the issue that we should print the values for.
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function custom_function_default_print_column_value( $p_column, $p_issue_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+	
+		$t_view_due_date = config_get( 'due_date_view_threshold' );
+		
+		if ( current_user_get_access_level() < $t_view_due_date && 
+			( $p_column == 'due_date' || $p_column == 'overdue' || $p_column == 'due_days' ) )
+			return;	
+	
 		if ( COLUMNS_TARGET_CSV_PAGE == $p_columns_target ) {
 			$t_column_start = '';
 			$t_column_end = '';
Index: core/columns_api.php
===================================================================
--- core/columns_api.php	(revision 5190)
+++ core/columns_api.php	(working copy)
@@ -56,6 +56,9 @@
 			'summary',
 			'version',
 			'view_state',
+			'due_date',
+			'overdue',
+			'due_days'
 		);
 
 		# Add project custom fields to the array.  Only add the ones for which the current user has at least read access.
@@ -520,39 +523,21 @@
 	# --------------------
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function print_column_edit( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
-		global $t_icon_path, $t_update_bug_threshold;
-		$t_is_overdue = bug_is_overdue( $p_row[ 'id' ] );
-		$t_view_level = access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] );
-		
-		if ( $t_is_overdue && $t_view_level ) {
-			print "<td class=\"overdue\">";
-		} else {
+		if ( $p_columns_target != COLUMNS_TARGET_CSV_PAGE ) {
+			global $t_icon_path, $t_update_bug_threshold;
+
 			echo '<td>';
+			if ( !bug_is_readonly( $p_row['id'] )
+		  		&& access_has_bug_level( $t_update_bug_threshold, $p_row['id'] ) ) {
+				echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+				echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'update.png';
+				echo '" alt="' . lang_get( 'update_bug_button' ) . '"';
+				echo ' title="' . lang_get( 'update_bug_button' ) . '" /></a>';
+			} else {
+				echo '&nbsp;';
+			}
+			echo '</td>';
 		}
-		if ( !bug_is_readonly( $p_row['id'] )
-			&& access_has_bug_level( config_get( 'update_bug_threshold' ), $p_row['id'] ) ) {
-			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
-			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'update.png';
-			echo '" alt="' . lang_get( 'update_bug_button' ) . '"';
-			echo ' title="' . lang_get( 'update_bug_button' ) . '" /></a>';
-		} else {
-			echo '&nbsp;';
-		}
-		if ( $t_is_overdue && $t_view_level ) {
-			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
-			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdue.png';
-			echo '" alt="' . lang_get( 'overdue' ) . '"';
-			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
-		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && $t_view_level ) {
-			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
-			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
-			echo '" alt="' . lang_get( 'due_date' ) . '"';
-			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
-		} else {
-			echo '&nbsp;';
-		}
-		
-		echo '</td>';
 	}
 
 	# --------------------
@@ -775,6 +760,20 @@
 				, lang_get( 'private' )
 			);
 		}
+		$t_is_overdue = bug_is_overdue( $p_row[ 'id' ] );
+		$t_view_level = access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] );
+		
+		if ( $t_is_overdue && $t_view_level ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdue.png';
+			echo '" alt="' . lang_get( 'overdue' ) . '"';
+			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
+		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && $t_view_level ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
+			echo '" alt="' . lang_get( 'due_date' ) . '"';
+			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
+		} 
 		echo '</td>';
 	}
 
@@ -822,4 +821,44 @@
 
 		echo '</td>';
 	}
+	
+	# --------------------
+	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
+	function print_column_due_date( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_row['due_date'] ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $p_row['due_date'] );
+		}
+		echo '<td>', $t_date_to_display, '</td>';
+	}
+
+	# --------------------
+	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
+	function print_column_overdue( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+		$t_date_to_display = '';
+		$t_cell = '<td class="due2">';
+		if ( !date_is_null( $p_row['due_date'] ) ) {
+			if ( bug_is_overdue( $p_row['id'] ) ) {
+				$t_cell = '<td class="overdue2">';
+				$t_date_to_display = lang_get( 'yes' );
+			} else {
+				$t_date_to_display = lang_get( 'no' );
+			}
+		}
+		echo $t_cell, $t_date_to_display, '</td>';
+	}
+
+	# --------------------
+	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
+	function print_column_due_days( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+		$t_date_to_display = '';
+		
+		$t_date = number_format(floor((date("U")-$p_row['due_date'])/86400),0);
+		
+		if ( !date_is_null( $p_row['due_date'] ) ) {
+			$t_date_to_display = -(number_format(floor((date("U")-$p_row['due_date'])/86400),0));
+		}
+		echo '<td>', $t_date_to_display, '</td>';
+	}
+
 ?>
duedate_stage3_23_04_2008.diff (17,233 bytes)   
duedate_stage3_final1.diff (17,615 bytes)   
Index: bug_change_status_page.php
===================================================================
--- bug_change_status_page.php	(revision 5200)
+++ bug_change_status_page.php	(working copy)
@@ -53,6 +53,7 @@
 		access_denied();
 	}
 	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
+	
 	# get new issue handler if set, otherwise default to original handler
 	$f_handler_id = gpc_get_int( 'handler_id', bug_get_field( $f_bug_id, 'handler_id' ) );
 
@@ -162,7 +163,7 @@
 <?php } ?>
 
 <!-- Due date -->
-<?php if ( $t_can_update_due_date ) {
+<?php if ( $t_can_update_due_date && $f_new_status < $t_resolved ) {
 	$t_date_to_display = '';
 	if ( ! date_is_null( $t_bug->due_date ) ) {
 			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
@@ -341,7 +342,7 @@
 </div>
 
 <?php
-if ( $t_can_update_due_date ) {
+if ( $t_can_update_due_date && $f_new_status < $t_resolved ) {
 	date_finish_calendar( 'due_date', 'trigger');
 } ?>
 <br />
Index: lang/strings_english.txt
===================================================================
--- lang/strings_english.txt	(revision 5200)
+++ lang/strings_english.txt	(working copy)
@@ -1516,8 +1516,9 @@
 # due date
 $s_due_date = "Due Date";
 $s_overdue = "Overdue";
+$s_due_days = "Due days";
 
 # mind mapping
 $s_mindmap = 'Mindmap';
 $s_freemind_export = 'Freemind Export';
-?>
\ No newline at end of file
+?>
Index: lang/strings_polish.txt
===================================================================
--- lang/strings_polish.txt	(revision 5200)
+++ lang/strings_polish.txt	(working copy)
@@ -1338,5 +1338,5 @@
 
 $s_due_date = "Termin realizacji";
 $s_overdue = "Przeterminowane";
-
+$s_due_days = "Due days";
 ?>
Index: print_all_bug_page_word.php
===================================================================
--- print_all_bug_page_word.php	(revision 5200)
+++ print_all_bug_page_word.php	(working copy)
@@ -93,6 +93,9 @@
 		# prefix bug data with v_
 		# extract( $result[$j], EXTR_PREFIX_ALL, 'v' );
 		$t_id = $result[$j]['id'];
+		
+		$t_can_view_due_date = access_has_bug_level( config_get( 'due_date_view_threshold' ), $t_id );
+		$t_overdue = bug_is_overdue( $t_id );
 
 		# display the available and selected bugs
 		if ( in_array( $t_id, $f_bug_arr ) || !$f_show_flag ) {
@@ -185,7 +188,27 @@
 	<td class="print">
 		<?php echo $t_bug->platform ?>
 	</td>
+<?php if ( $t_can_view_due_date ) { ?>
+	<td class="print-category">
+		<?php echo lang_get( 'due_date' ) ?>:
+	</td>
+<?php
+		if ( $t_overdue ) { ?>
+		<td class="print-overdue">
+<?php
+		} else	{ ?>
+		<td class="print">
+<?php
+		}
+		if ( !date_is_null( $t_bug->due_date ) ) {
+				print_date( config_get( 'short_date_format' ), $t_bug->due_date ); 
+		print "</td>";
+		}
+	} else {
+?>
 	<td class="print" colspan="2">&nbsp;</td>
+<?php } 
+?>
 </tr>
 <tr class="print">
 	<td class="print-category">
Index: excel_xml_export.php
===================================================================
--- excel_xml_export.php	(revision 5200)
+++ excel_xml_export.php	(working copy)
@@ -95,7 +95,13 @@
 							echo excel_format_custom_field( $t_row['id'], $t_row['project_id'], $t_custom_field );
 						} else {
 							$t_function = 'excel_format_' . $t_column;
-							echo $t_function( $t_row[$t_column] );
+							if ( $t_column == 'overdue' ) {
+								echo $t_function( $t_row[ 'id' ], $t_row[ $t_column ] );
+							} else if ( $t_column == 'due_days' ) {
+								echo $t_function( $t_row[ 'due_date' ] );
+							} else {
+								echo $t_function( $t_row[ $t_column ] );
+							}
 						}
 					}
 				}
@@ -122,4 +128,4 @@
 	} while ( $t_more );
 
 	echo excel_get_footer();
-?>
\ No newline at end of file
+?>
Index: css/default.css
===================================================================
--- css/default.css	(revision 5200)
+++ css/default.css	(working copy)
@@ -53,6 +53,8 @@
 td.right			{ text-align: right; }
 td.category			{ background-color: #c8c8e8; color: #000000; font-weight: bold; vertical-align : top; }
 td.overdue			{ background-color: #ff0000; color: #000000; font-weight: bold; }
+td.overdue2			{ background-color: #ff0000; color: #000000; font-weight: bold; text-align: center}
+td.due2				{ text-align: center}
 
 td.col-1			{ background-color: #d8d8d8; color: #000000; }
 td.col-2			{ background-color: #e8e8e8; color: #000000; }
@@ -61,6 +63,7 @@
 td.small-caption	{ font-size: 8pt; }
 td.print			{ font-size: 8pt; text-align: left; padding: 2px; }
 td.print-category	{ font-size: 8pt; color: #000000; font-weight: bold; text-align: right; padding: 2px; }
+td.print-overdue	{ font-size: 8pt; color: #000000; font-weight: bold; padding: 2px; }
 td.print-bottom		{ border-bottom: 1px solid #000000; }
 td.print-spacer		{ background-color: #ffffff; color: #000000; font-size: 1pt; line-height: 0.1; padding: 0px;}
 
Index: config_defaults_inc.php
===================================================================
--- config_defaults_inc.php	(revision 5200)
+++ config_defaults_inc.php	(working copy)
@@ -528,7 +528,7 @@
 	# selection, edit, id, project_id, reporter_id, handler_id, priority, reproducibility, projection, eta,
 	# resolution, fixed_in_version, view_state, os, os_build, build (for product build), platform, version, date_submitted, attachment,
 	# category, sponsorship_total, severity, status, last_updated, summary, bugnotes_count, description,
-	# steps_to_reproduce, additional_information
+	# steps_to_reproduce, additional_information, due_date, overdue, due_days
 	$g_view_issues_page_columns = array ( 'selection', 'edit', 'priority', 'id', 'sponsorship_total', 'bugnotes_count', 'attachment', 'category', 'severity', 'status', 'last_updated', 'summary' );
 	
 	# The default columns to be included in the Print Issues Page.
Index: csv_export.php
===================================================================
--- csv_export.php	(revision 5200)
+++ csv_export.php	(working copy)
@@ -121,7 +121,13 @@
 				}
 
 				$t_function = 'csv_format_' . $t_column;
-				echo $t_function( $t_row[ $t_column ] );
+				if ( $t_column == 'overdue' ) {
+					echo $t_function( $t_row[ 'id' ], $t_row[ $t_column ] );
+				} else if ( $t_column == 'due_days' ) {
+					echo $t_function( $t_row[ 'due_date' ] );
+				} else {
+					echo $t_function( $t_row[ $t_column ] );
+				}
 			}
 		}
 
Index: core/bug_api.php
===================================================================
--- core/bug_api.php	(revision 5200)
+++ core/bug_api.php	(working copy)
@@ -350,6 +350,8 @@
 			$t_now = db_unixtimestamp();
 			if ( $t_now > $t_due_date ) {
 				if ( bug_is_resolved( $p_bug_id ) ) {
+					return false;
+				} else {
 					return true;
 				}
 			}
@@ -1238,11 +1240,12 @@
 		$c_field_name		= db_prepare_string( $p_field_name );
 		$c_status		=  $p_status; #generic, unknown type
 
+		$t_log_status = $c_status;
 		$h_status = bug_get_field( $p_bug_id, $p_field_name );
 		
 		if ( $p_field_name == 'due_date' ) {
 			if ( !date_is_null( $h_status )  ) {
-				$h_status = date( config_get( 'short_date_format' ), $h_status );
+				$h_status = date( config_get( 'Y-m-d' ), $h_status );
 			} else {
 				$h_status = '';
 			}
@@ -1251,9 +1254,11 @@
 				$t_tmp = strtotime( $p_status );
 			} 
 			if ( !date_is_null( $t_tmp ) ) {
-				$c_status = date( config_get( 'short_date_format' ), $t_tmp );
+				$c_status = date(  'Y-m-d 00:00:01', $t_tmp );
+				$t_log_status = date( config_get( 'short_date_format' ), $t_tmp );
 			} else {
 				$c_status = '';
+				$t_log_status = '';
 			}
 			$c_field_name = lang_get( 'due_date' );
 		}
@@ -1276,7 +1281,7 @@
 		# log changes except for duplicate_id which is obsolete and should be removed in
 		# Mantis 1.3.
 		if ( $p_field_name != 'duplicate_id' ) {
-			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $c_status );
+			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $t_log_status );
 		}
 
 		bug_clear_cache( $p_bug_id );
Index: core/date_api.php
===================================================================
--- core/date_api.php	(revision 5200)
+++ core/date_api.php	(working copy)
@@ -25,7 +25,7 @@
 	# --------------------
 	# checks if date is null
 	function date_is_null( $p_date ) {
-		return $p_date == date_get_null();
+		return $p_date <= date_get_null();
 	}
 
 	# --------------------
Index: core/csv_api.php
===================================================================
--- core/csv_api.php	(revision 5200)
+++ core/csv_api.php	(working copy)
@@ -249,4 +249,41 @@
 	function csv_format_selection( $p_duplicate_id ) {
 		return csv_escape_string( '' );
 	}
+	
+	# --------------------
+	# return due_date
+	function csv_format_due_date( $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $p_due_date );
+		}
+		return csv_escape_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return overdue
+	function csv_format_overdue( $p_bug_id, $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			if ( bug_is_overdue( $p_bug_id ) ) {
+				$t_date_to_display = lang_get( 'yes' );
+			} else {
+				$t_date_to_display = lang_get( 'no' );
+			}
+		}
+		return csv_escape_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return due days
+	function csv_format_due_days( $p_due_date ) {
+		$t_date_to_display = '';
+		
+		$t_date = number_format(floor((date("U")-$p_due_date)/86400),0);
+		
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = -(number_format(floor((date("U")-$p_due_date)/86400),0));
+		}
+		return csv_escape_string( $t_date_to_display );
+	}
 ?>
Index: core/excel_api.php
===================================================================
--- core/excel_api.php	(revision 5200)
+++ core/excel_api.php	(working copy)
@@ -423,4 +423,42 @@
 		// field is not linked to project
 		return excel_prepare_string( '' );
 	}
-?>
\ No newline at end of file
+	
+	# --------------------
+	# return due_date
+	function excel_format_due_date( $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $p_due_date );
+		}
+		return excel_prepare_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return overdue
+	function excel_format_overdue( $p_bug_id, $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			if ( bug_is_overdue( $p_bug_id ) ) {
+				$t_date_to_display = lang_get( 'yes' );
+			} else {
+				$t_date_to_display = lang_get( 'no' );
+			}
+		}
+		return excel_prepare_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return due days
+	function excel_format_due_days( $p_due_date ) {
+		$t_date_to_display = '';
+		
+		$t_date = number_format(floor((date("U")-$p_due_date)/86400),0);
+		
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = -(number_format(floor((date("U")-$p_due_date)/86400),0));
+		}
+		return excel_prepare_string( $t_date_to_display );
+	}
+	
+?>
Index: core/custom_function_api.php
===================================================================
--- core/custom_function_api.php	(revision 5200)
+++ core/custom_function_api.php	(working copy)
@@ -236,6 +236,12 @@
 	function custom_function_default_print_column_title( $p_column, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 		global $t_sort, $t_dir;
 
+		$t_view_due_date = config_get( 'due_date_view_threshold' );
+		
+		if ( current_user_get_access_level() < $t_view_due_date && 
+			( $p_column == 'due_date' || $p_column == 'overdue' || $p_column == 'due_days' ) )
+			return;
+		
 		$t_custom_field = column_get_custom_field_name( $p_column );
 		if ( $t_custom_field !== null ) {
 			if ( COLUMNS_TARGET_CSV_PAGE != $p_columns_target ) {
@@ -281,6 +287,13 @@
 	# $p_row: the row from the bug table that belongs to the issue that we should print the values for.
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function custom_function_default_print_column_value( $p_column, $p_issue_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+	
+		$t_view_due_date = config_get( 'due_date_view_threshold' );
+		
+		if ( current_user_get_access_level() < $t_view_due_date && 
+			( $p_column == 'due_date' || $p_column == 'overdue' || $p_column == 'due_days' ) )
+			return;	
+	
 		if ( COLUMNS_TARGET_CSV_PAGE == $p_columns_target ) {
 			$t_column_start = '';
 			$t_column_end = '';
Index: core/columns_api.php
===================================================================
--- core/columns_api.php	(revision 5200)
+++ core/columns_api.php	(working copy)
@@ -56,6 +56,9 @@
 			'summary',
 			'version',
 			'view_state',
+			'due_date',
+			'overdue',
+			'due_days'
 		);
 
 		# Add project custom fields to the array.  Only add the ones for which the current user has at least read access.
@@ -520,39 +523,21 @@
 	# --------------------
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function print_column_edit( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
-		global $t_icon_path, $t_update_bug_threshold;
-		$t_is_overdue = bug_is_overdue( $p_row[ 'id' ] );
-		$t_view_level = access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] );
-		
-		if ( $t_is_overdue && $t_view_level ) {
-			print "<td class=\"overdue\">";
-		} else {
+		if ( $p_columns_target != COLUMNS_TARGET_CSV_PAGE ) {
+			global $t_icon_path, $t_update_bug_threshold;
+
 			echo '<td>';
+			if ( !bug_is_readonly( $p_row['id'] )
+		  		&& access_has_bug_level( $t_update_bug_threshold, $p_row['id'] ) ) {
+				echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+				echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'update.png';
+				echo '" alt="' . lang_get( 'update_bug_button' ) . '"';
+				echo ' title="' . lang_get( 'update_bug_button' ) . '" /></a>';
+			} else {
+				echo '&nbsp;';
+			}
+			echo '</td>';
 		}
-		if ( !bug_is_readonly( $p_row['id'] )
-			&& access_has_bug_level( config_get( 'update_bug_threshold' ), $p_row['id'] ) ) {
-			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
-			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'update.png';
-			echo '" alt="' . lang_get( 'update_bug_button' ) . '"';
-			echo ' title="' . lang_get( 'update_bug_button' ) . '" /></a>';
-		} else {
-			echo '&nbsp;';
-		}
-		if ( $t_is_overdue && $t_view_level ) {
-			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
-			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdue.png';
-			echo '" alt="' . lang_get( 'overdue' ) . '"';
-			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
-		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && $t_view_level ) {
-			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
-			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
-			echo '" alt="' . lang_get( 'due_date' ) . '"';
-			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
-		} else {
-			echo '&nbsp;';
-		}
-		
-		echo '</td>';
 	}
 
 	# --------------------
@@ -775,6 +760,20 @@
 				, lang_get( 'private' )
 			);
 		}
+		$t_is_overdue = bug_is_overdue( $p_row[ 'id' ] );
+		$t_view_level = access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] );
+		
+		if ( $t_is_overdue && $t_view_level ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdue.png';
+			echo '" alt="' . lang_get( 'overdue' ) . '"';
+			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
+		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && $t_view_level ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
+			echo '" alt="' . lang_get( 'due_date' ) . '"';
+			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
+		} 
 		echo '</td>';
 	}
 
@@ -822,4 +821,44 @@
 
 		echo '</td>';
 	}
+	
+	# --------------------
+	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
+	function print_column_due_date( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_row['due_date'] ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $p_row['due_date'] );
+		}
+		echo '<td>', $t_date_to_display, '</td>';
+	}
+
+	# --------------------
+	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
+	function print_column_overdue( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+		$t_date_to_display = '';
+		$t_cell = '<td class="due2">';
+		if ( !date_is_null( $p_row['due_date'] ) ) {
+			if ( bug_is_overdue( $p_row['id'] ) ) {
+				$t_cell = '<td class="overdue2">';
+				$t_date_to_display = lang_get( 'yes' );
+			} else {
+				$t_date_to_display = lang_get( 'no' );
+			}
+		}
+		echo $t_cell, $t_date_to_display, '</td>';
+	}
+
+	# --------------------
+	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
+	function print_column_due_days( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+		$t_date_to_display = '';
+		
+		$t_date = number_format(floor((date("U")-$p_row['due_date'])/86400),0);
+		
+		if ( !date_is_null( $p_row['due_date'] ) ) {
+			$t_date_to_display = -(number_format(floor((date("U")-$p_row['due_date'])/86400),0));
+		}
+		echo '<td>', $t_date_to_display, '</td>';
+	}
+
 ?>
duedate_stage3_final1.diff (17,615 bytes)   
duedate_stage3_final2.diff (19,165 bytes)   
Index: bug_change_status_page.php
===================================================================
--- bug_change_status_page.php	(revision 5213)
+++ bug_change_status_page.php	(working copy)
@@ -53,6 +53,7 @@
 		access_denied();
 	}
 	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
+	
 	# get new issue handler if set, otherwise default to original handler
 	$f_handler_id = gpc_get_int( 'handler_id', bug_get_field( $f_bug_id, 'handler_id' ) );
 
@@ -162,7 +163,7 @@
 <?php } ?>
 
 <!-- Due date -->
-<?php if ( $t_can_update_due_date ) {
+<?php if ( $t_can_update_due_date && $f_new_status < $t_resolved ) {
 	$t_date_to_display = '';
 	if ( ! date_is_null( $t_bug->due_date ) ) {
 			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
@@ -341,7 +342,7 @@
 </div>
 
 <?php
-if ( $t_can_update_due_date ) {
+if ( $t_can_update_due_date && $f_new_status < $t_resolved ) {
 	date_finish_calendar( 'due_date', 'trigger');
 } ?>
 <br />
Index: lang/strings_polish_8859-2.txt
===================================================================
--- lang/strings_polish_8859-2.txt	(revision 5213)
+++ lang/strings_polish_8859-2.txt	(working copy)
@@ -1336,7 +1336,12 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
-$s_due_date = "Termin realizacji";
-$s_overdue = "Przeterminowane";
+$s_due_date = 'Termin realizacji';
+$s_overdue = 'Przeterminowane';
+$s_due_days = 'Due days';
+$s_overdue_csv_yes = 'Tak';
+$s_overdue_csv_no = 'Nie';
+$s_overdue_excel_yes = 'Tak';
+$s_overdue_excel_no = 'Nie';
 
 ?>
Index: lang/strings_english.txt
===================================================================
--- lang/strings_english.txt	(revision 5213)
+++ lang/strings_english.txt	(working copy)
@@ -1514,10 +1514,15 @@
 $s_copy_columns_to = 'Copy Columns To';
 
 # due date
-$s_due_date = "Due Date";
-$s_overdue = "Overdue";
+$s_due_date = 'Due Date';
+$s_overdue = 'Overdue';
+$s_due_days = 'Due days';
+$s_overdue_csv_yes = 'Yes';
+$s_overdue_csv_no = 'No';
+$s_overdue_excel_yes = 'Yes';
+$s_overdue_excel_no = 'No';
 
 # mind mapping
 $s_mindmap = 'Mindmap';
 $s_freemind_export = 'Freemind Export';
-?>
\ No newline at end of file
+?>
Index: lang/strings_polish.txt
===================================================================
--- lang/strings_polish.txt	(revision 5213)
+++ lang/strings_polish.txt	(working copy)
@@ -1336,7 +1336,11 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
-$s_due_date = "Termin realizacji";
-$s_overdue = "Przeterminowane";
-
+$s_due_date = 'Termin realizacji';
+$s_overdue = 'Przeterminowane';
+$s_due_days = 'Due days';
+$s_overdue_csv_yes = 'Tak';
+$s_overdue_csv_no = 'Nie';
+$s_overdue_excel_yes = 'Tak';
+$s_overdue_excel_no = 'Nie';
 ?>
Index: print_all_bug_page_word.php
===================================================================
--- print_all_bug_page_word.php	(revision 5213)
+++ print_all_bug_page_word.php	(working copy)
@@ -93,6 +93,9 @@
 		# prefix bug data with v_
 		# extract( $result[$j], EXTR_PREFIX_ALL, 'v' );
 		$t_id = $result[$j]['id'];
+		
+		$t_can_view_due_date = access_has_bug_level( config_get( 'due_date_view_threshold' ), $t_id );
+		$t_overdue = bug_is_overdue( $t_id );
 
 		# display the available and selected bugs
 		if ( in_array( $t_id, $f_bug_arr ) || !$f_show_flag ) {
@@ -185,7 +188,27 @@
 	<td class="print">
 		<?php echo $t_bug->platform ?>
 	</td>
+<?php if ( $t_can_view_due_date ) { ?>
+	<td class="print-category">
+		<?php echo lang_get( 'due_date' ) ?>:
+	</td>
+<?php
+		if ( $t_overdue ) { ?>
+		<td class="print-overdue">
+<?php
+		} else	{ ?>
+		<td class="print">
+<?php
+		}
+		if ( !date_is_null( $t_bug->due_date ) ) {
+				print_date( config_get( 'short_date_format' ), $t_bug->due_date ); 
+		print "</td>";
+		}
+	} else {
+?>
 	<td class="print" colspan="2">&nbsp;</td>
+<?php } 
+?>
 </tr>
 <tr class="print">
 	<td class="print-category">
Index: excel_xml_export.php
===================================================================
--- excel_xml_export.php	(revision 5213)
+++ excel_xml_export.php	(working copy)
@@ -95,7 +95,13 @@
 							echo excel_format_custom_field( $t_row['id'], $t_row['project_id'], $t_custom_field );
 						} else {
 							$t_function = 'excel_format_' . $t_column;
-							echo $t_function( $t_row[$t_column] );
+							if ( $t_column == 'overdue' ) {
+								echo $t_function( $t_row[ 'id' ], $t_row[ $t_column ] );
+							} else if ( $t_column == 'due_days' ) {
+								echo $t_function( $t_row[ 'due_date' ] );
+							} else {
+								echo $t_function( $t_row[ $t_column ] );
+							}
 						}
 					}
 				}
@@ -122,4 +128,4 @@
 	} while ( $t_more );
 
 	echo excel_get_footer();
-?>
\ No newline at end of file
+?>
Index: css/default.css
===================================================================
--- css/default.css	(revision 5213)
+++ css/default.css	(working copy)
@@ -53,6 +53,8 @@
 td.right			{ text-align: right; }
 td.category			{ background-color: #c8c8e8; color: #000000; font-weight: bold; vertical-align : top; }
 td.overdue			{ background-color: #ff0000; color: #000000; font-weight: bold; }
+td.overdue2			{ background-color: #ff0000; color: #000000; font-weight: bold; text-align: center}
+td.due2				{ text-align: center}
 
 td.col-1			{ background-color: #d8d8d8; color: #000000; }
 td.col-2			{ background-color: #e8e8e8; color: #000000; }
@@ -61,6 +63,7 @@
 td.small-caption	{ font-size: 8pt; }
 td.print			{ font-size: 8pt; text-align: left; padding: 2px; }
 td.print-category	{ font-size: 8pt; color: #000000; font-weight: bold; text-align: right; padding: 2px; }
+td.print-overdue	{ font-size: 8pt; color: #000000; font-weight: bold; padding: 2px; }
 td.print-bottom		{ border-bottom: 1px solid #000000; }
 td.print-spacer		{ background-color: #ffffff; color: #000000; font-size: 1pt; line-height: 0.1; padding: 0px;}
 
Index: config_defaults_inc.php
===================================================================
--- config_defaults_inc.php	(revision 5213)
+++ config_defaults_inc.php	(working copy)
@@ -528,7 +528,7 @@
 	# selection, edit, id, project_id, reporter_id, handler_id, priority, reproducibility, projection, eta,
 	# resolution, fixed_in_version, view_state, os, os_build, build (for product build), platform, version, date_submitted, attachment,
 	# category, sponsorship_total, severity, status, last_updated, summary, bugnotes_count, description,
-	# steps_to_reproduce, additional_information
+	# steps_to_reproduce, additional_information, due_date, overdue, due_days
 	$g_view_issues_page_columns = array ( 'selection', 'edit', 'priority', 'id', 'sponsorship_total', 'bugnotes_count', 'attachment', 'category', 'severity', 'status', 'last_updated', 'summary' );
 	
 	# The default columns to be included in the Print Issues Page.
Index: csv_export.php
===================================================================
--- csv_export.php	(revision 5213)
+++ csv_export.php	(working copy)
@@ -121,7 +121,13 @@
 				}
 
 				$t_function = 'csv_format_' . $t_column;
-				echo $t_function( $t_row[ $t_column ] );
+				if ( $t_column == 'overdue' ) {
+					echo $t_function( $t_row[ 'id' ], $t_row[ $t_column ] );
+				} else if ( $t_column == 'due_days' ) {
+					echo $t_function( $t_row[ 'due_date' ] );
+				} else {
+					echo $t_function( $t_row[ $t_column ] );
+				}
 			}
 		}
 
Index: core/bug_api.php
===================================================================
--- core/bug_api.php	(revision 5213)
+++ core/bug_api.php	(working copy)
@@ -350,6 +350,8 @@
 			$t_now = db_unixtimestamp();
 			if ( $t_now > $t_due_date ) {
 				if ( bug_is_resolved( $p_bug_id ) ) {
+					return false;
+				} else {
 					return true;
 				}
 			}
@@ -1238,11 +1240,12 @@
 		$c_field_name		= db_prepare_string( $p_field_name );
 		$c_status		=  $p_status; #generic, unknown type
 
+		$t_log_status = $c_status;
 		$h_status = bug_get_field( $p_bug_id, $p_field_name );
 		
 		if ( $p_field_name == 'due_date' ) {
 			if ( !date_is_null( $h_status )  ) {
-				$h_status = date( config_get( 'short_date_format' ), $h_status );
+				$h_status = date( config_get( 'Y-m-d' ), $h_status );
 			} else {
 				$h_status = '';
 			}
@@ -1251,9 +1254,11 @@
 				$t_tmp = strtotime( $p_status );
 			} 
 			if ( !date_is_null( $t_tmp ) ) {
-				$c_status = date( config_get( 'short_date_format' ), $t_tmp );
+				$c_status = date(  'Y-m-d 00:00:01', $t_tmp );
+				$t_log_status = date( config_get( 'short_date_format' ), $t_tmp );
 			} else {
 				$c_status = '';
+				$t_log_status = '';
 			}
 			$c_field_name = lang_get( 'due_date' );
 		}
@@ -1276,7 +1281,7 @@
 		# log changes except for duplicate_id which is obsolete and should be removed in
 		# Mantis 1.3.
 		if ( $p_field_name != 'duplicate_id' ) {
-			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $c_status );
+			history_log_event_direct( $p_bug_id, $p_field_name, $h_status, $t_log_status );
 		}
 
 		bug_clear_cache( $p_bug_id );
Index: core/date_api.php
===================================================================
--- core/date_api.php	(revision 5213)
+++ core/date_api.php	(working copy)
@@ -25,7 +25,7 @@
 	# --------------------
 	# checks if date is null
 	function date_is_null( $p_date ) {
-		return $p_date == date_get_null();
+		return $p_date <= date_get_null();
 	}
 
 	# --------------------
Index: core/csv_api.php
===================================================================
--- core/csv_api.php	(revision 5213)
+++ core/csv_api.php	(working copy)
@@ -249,4 +249,41 @@
 	function csv_format_selection( $p_duplicate_id ) {
 		return csv_escape_string( '' );
 	}
+	
+	# --------------------
+	# return due_date
+	function csv_format_due_date( $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $p_due_date );
+		}
+		return csv_escape_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return overdue
+	function csv_format_overdue( $p_bug_id, $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			if ( bug_is_overdue( $p_bug_id ) ) {
+				$t_date_to_display = lang_get( 'overdue_csv_yes' );
+			} else {
+				$t_date_to_display = lang_get( 'overdue_csv_no' );
+			}
+		}
+		return csv_escape_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return due days
+	function csv_format_due_days( $p_due_date ) {
+		$t_date_to_display = '';
+		
+		$t_date = number_format(floor((date("U")-$p_due_date)/86400),0);
+		
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = -(number_format(floor((date("U")-$p_due_date)/86400),0));
+		}
+		return csv_escape_string( $t_date_to_display );
+	}
 ?>
Index: core/excel_api.php
===================================================================
--- core/excel_api.php	(revision 5213)
+++ core/excel_api.php	(working copy)
@@ -423,4 +423,42 @@
 		// field is not linked to project
 		return excel_prepare_string( '' );
 	}
-?>
\ No newline at end of file
+	
+	# --------------------
+	# return due_date
+	function excel_format_due_date( $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $p_due_date );
+		}
+		return excel_prepare_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return overdue
+	function excel_format_overdue( $p_bug_id, $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			if ( bug_is_overdue( $p_bug_id ) ) {
+				$t_date_to_display = lang_get( 'overdue_excel_yes' );
+			} else {
+				$t_date_to_display = lang_get( 'overdue_excel_no' );
+			}
+		}
+		return excel_prepare_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return due days
+	function excel_format_due_days( $p_due_date ) {
+		$t_date_to_display = '';
+		
+		$t_date = number_format(floor((date("U")-$p_due_date)/86400),0);
+		
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = -(number_format(floor((date("U")-$p_due_date)/86400),0));
+		}
+		return excel_prepare_string( $t_date_to_display );
+	}
+	
+?>
Index: core/custom_function_api.php
===================================================================
--- core/custom_function_api.php	(revision 5213)
+++ core/custom_function_api.php	(working copy)
@@ -24,6 +24,7 @@
 	$t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
 
 	require_once( $t_core_dir . 'prepare_api.php' );
+	require_once( $t_core_dir . 'access_api.php' );
 
 	### Custom Function API ###
 
@@ -235,7 +236,14 @@
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function custom_function_default_print_column_title( $p_column, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 		global $t_sort, $t_dir;
-
+		
+		$t_current_user_level = current_user_get_access_level();
+		$t_view_due_date = access_compare_level($t_current_user_level, config_get( 'due_date_view_threshold' ));
+		
+		if ( current_user_get_access_level() < $t_view_due_date && 
+			( $p_column == 'due_date' || $p_column == 'overdue' || $p_column == 'due_days' ) )
+			return;
+		
 		$t_custom_field = column_get_custom_field_name( $p_column );
 		if ( $t_custom_field !== null ) {
 			if ( COLUMNS_TARGET_CSV_PAGE != $p_columns_target ) {
@@ -281,6 +289,14 @@
 	# $p_row: the row from the bug table that belongs to the issue that we should print the values for.
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function custom_function_default_print_column_value( $p_column, $p_issue_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+	
+		$t_current_user_level = current_user_get_access_level();
+		$t_view_due_date = access_compare_level($t_current_user_level, config_get( 'due_date_view_threshold' ));
+		
+		if ( current_user_get_access_level() < $t_view_due_date && 
+			( $p_column == 'due_date' || $p_column == 'overdue' || $p_column == 'due_days' ) )
+			return;	
+	
 		if ( COLUMNS_TARGET_CSV_PAGE == $p_columns_target ) {
 			$t_column_start = '';
 			$t_column_end = '';
Index: core/columns_api.php
===================================================================
--- core/columns_api.php	(revision 5213)
+++ core/columns_api.php	(working copy)
@@ -56,6 +56,9 @@
 			'summary',
 			'version',
 			'view_state',
+			'due_date',
+			'overdue',
+			'due_days'
 		);
 
 		# Add project custom fields to the array.  Only add the ones for which the current user has at least read access.
@@ -520,39 +523,21 @@
 	# --------------------
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function print_column_edit( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
-		global $t_icon_path, $t_update_bug_threshold;
-		$t_is_overdue = bug_is_overdue( $p_row[ 'id' ] );
-		$t_view_level = access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] );
-		
-		if ( $t_is_overdue && $t_view_level ) {
-			print "<td class=\"overdue\">";
-		} else {
+		if ( $p_columns_target != COLUMNS_TARGET_CSV_PAGE ) {
+			global $t_icon_path, $t_update_bug_threshold;
+
 			echo '<td>';
+			if ( !bug_is_readonly( $p_row['id'] )
+		  		&& access_has_bug_level( $t_update_bug_threshold, $p_row['id'] ) ) {
+				echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+				echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'update.png';
+				echo '" alt="' . lang_get( 'update_bug_button' ) . '"';
+				echo ' title="' . lang_get( 'update_bug_button' ) . '" /></a>';
+			} else {
+				echo '&nbsp;';
+			}
+			echo '</td>';
 		}
-		if ( !bug_is_readonly( $p_row['id'] )
-			&& access_has_bug_level( config_get( 'update_bug_threshold' ), $p_row['id'] ) ) {
-			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
-			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'update.png';
-			echo '" alt="' . lang_get( 'update_bug_button' ) . '"';
-			echo ' title="' . lang_get( 'update_bug_button' ) . '" /></a>';
-		} else {
-			echo '&nbsp;';
-		}
-		if ( $t_is_overdue && $t_view_level ) {
-			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
-			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdue.png';
-			echo '" alt="' . lang_get( 'overdue' ) . '"';
-			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
-		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && $t_view_level ) {
-			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
-			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
-			echo '" alt="' . lang_get( 'due_date' ) . '"';
-			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
-		} else {
-			echo '&nbsp;';
-		}
-		
-		echo '</td>';
 	}
 
 	# --------------------
@@ -775,6 +760,20 @@
 				, lang_get( 'private' )
 			);
 		}
+		$t_is_overdue = bug_is_overdue( $p_row[ 'id' ] );
+		$t_view_level = access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] );
+		
+		if ( $t_is_overdue && $t_view_level ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdue.png';
+			echo '" alt="' . lang_get( 'overdue' ) . '"';
+			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
+		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && $t_view_level ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
+			echo '" alt="' . lang_get( 'due_date' ) . '"';
+			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
+		} 
 		echo '</td>';
 	}
 
@@ -822,4 +821,44 @@
 
 		echo '</td>';
 	}
+	
+	# --------------------
+	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
+	function print_column_due_date( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_row['due_date'] ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $p_row['due_date'] );
+		}
+		echo '<td>', $t_date_to_display, '</td>';
+	}
+
+	# --------------------
+	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
+	function print_column_overdue( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+		$t_date_to_display = '';
+		$t_cell = '<td class="due2">';
+		if ( !date_is_null( $p_row['due_date'] ) ) {
+			if ( bug_is_overdue( $p_row['id'] ) ) {
+				$t_cell = '<td class="overdue2">';
+				$t_date_to_display = lang_get( 'yes' );
+			} else {
+				$t_date_to_display = lang_get( 'no' );
+			}
+		}
+		echo $t_cell, $t_date_to_display, '</td>';
+	}
+
+	# --------------------
+	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
+	function print_column_due_days( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+		$t_date_to_display = '';
+		
+		$t_date = number_format(floor((date("U")-$p_row['due_date'])/86400),0);
+		
+		if ( !date_is_null( $p_row['due_date'] ) ) {
+			$t_date_to_display = -(number_format(floor((date("U")-$p_row['due_date'])/86400),0));
+		}
+		echo '<td>', $t_date_to_display, '</td>';
+	}
+
 ?>
duedate_stage3_final2.diff (19,165 bytes)   
duedate_stage3_final3.diff (17,080 bytes)   
Index: bug_change_status_page.php
===================================================================
--- bug_change_status_page.php	(revision 5248)
+++ bug_change_status_page.php	(working copy)
@@ -53,6 +53,7 @@
 		access_denied();
 	}
 	$t_can_update_due_date = access_has_bug_level( config_get( 'due_date_update_threshold' ), $f_bug_id );
+	
 	# get new issue handler if set, otherwise default to original handler
 	$f_handler_id = gpc_get_int( 'handler_id', bug_get_field( $f_bug_id, 'handler_id' ) );
 
@@ -162,7 +163,7 @@
 <?php } ?>
 
 <!-- Due date -->
-<?php if ( $t_can_update_due_date ) {
+<?php if ( $t_can_update_due_date && $f_new_status < $t_resolved ) {
 	$t_date_to_display = '';
 	if ( ! date_is_null( $t_bug->due_date ) ) {
 			$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
@@ -341,7 +342,7 @@
 </div>
 
 <?php
-if ( $t_can_update_due_date ) {
+if ( $t_can_update_due_date && $f_new_status < $t_resolved ) {
 	date_finish_calendar( 'due_date', 'trigger');
 } ?>
 <br />
Index: lang/strings_polish_8859-2.txt
===================================================================
--- lang/strings_polish_8859-2.txt	(revision 5248)
+++ lang/strings_polish_8859-2.txt	(working copy)
@@ -1336,7 +1336,12 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
-$s_due_date = "Termin realizacji";
-$s_overdue = "Przeterminowane";
+$s_due_date = 'Termin realizacji';
+$s_overdue = 'Przeterminowane';
+$s_due_days = 'Due days';
+$s_overdue_csv_yes = 'Tak';
+$s_overdue_csv_no = 'Nie';
+$s_overdue_excel_yes = 'Tak';
+$s_overdue_excel_no = 'Nie';
 
 ?>
Index: lang/strings_english.txt
===================================================================
--- lang/strings_english.txt	(revision 5248)
+++ lang/strings_english.txt	(working copy)
@@ -1515,8 +1515,13 @@
 $s_copy_columns_to = 'Copy Columns To';
 
 # due date
-$s_due_date = "Due Date";
-$s_overdue = "Overdue";
+$s_due_date = 'Due Date';
+$s_overdue = 'Overdue';
+$s_due_days = 'Due days';
+$s_overdue_csv_yes = 'Yes';
+$s_overdue_csv_no = 'No';
+$s_overdue_excel_yes = 'Yes';
+$s_overdue_excel_no = 'No';
 
 # mind mapping
 $s_mindmap = 'Mindmap';
Index: lang/strings_polish.txt
===================================================================
--- lang/strings_polish.txt	(revision 5248)
+++ lang/strings_polish.txt	(working copy)
@@ -1336,7 +1336,11 @@
 # wiki related strings
 $s_wiki = 'Wiki';
 
-$s_due_date = "Termin realizacji";
-$s_overdue = "Przeterminowane";
-
+$s_due_date = 'Termin realizacji';
+$s_overdue = 'Przeterminowane';
+$s_due_days = 'Due days';
+$s_overdue_csv_yes = 'Tak';
+$s_overdue_csv_no = 'Nie';
+$s_overdue_excel_yes = 'Tak';
+$s_overdue_excel_no = 'Nie';
 ?>
Index: print_all_bug_page_word.php
===================================================================
--- print_all_bug_page_word.php	(revision 5248)
+++ print_all_bug_page_word.php	(working copy)
@@ -93,6 +93,9 @@
 		# prefix bug data with v_
 		# extract( $result[$j], EXTR_PREFIX_ALL, 'v' );
 		$t_id = $result[$j]['id'];
+		
+		$t_can_view_due_date = access_has_bug_level( config_get( 'due_date_view_threshold' ), $t_id );
+		$t_overdue = bug_is_overdue( $t_id );
 
 		# display the available and selected bugs
 		if ( in_array( $t_id, $f_bug_arr ) || !$f_show_flag ) {
@@ -185,7 +188,27 @@
 	<td class="print">
 		<?php echo $t_bug->platform ?>
 	</td>
+<?php if ( $t_can_view_due_date ) { ?>
+	<td class="print-category">
+		<?php echo lang_get( 'due_date' ) ?>:
+	</td>
+<?php
+		if ( $t_overdue ) { ?>
+		<td class="print-overdue">
+<?php
+		} else	{ ?>
+		<td class="print">
+<?php
+		}
+		if ( !date_is_null( $t_bug->due_date ) ) {
+				print_date( config_get( 'short_date_format' ), $t_bug->due_date ); 
+		print "</td>";
+		}
+	} else {
+?>
 	<td class="print" colspan="2">&nbsp;</td>
+<?php } 
+?>
 </tr>
 <tr class="print">
 	<td class="print-category">
Index: excel_xml_export.php
===================================================================
--- excel_xml_export.php	(revision 5248)
+++ excel_xml_export.php	(working copy)
@@ -95,7 +95,13 @@
 							echo excel_format_custom_field( $t_row['id'], $t_row['project_id'], $t_custom_field );
 						} else {
 							$t_function = 'excel_format_' . $t_column;
-							echo $t_function( $t_row[$t_column] );
+							if ( $t_column == 'overdue' ) {
+								echo $t_function( $t_row[ 'id' ], $t_row[ $t_column ] );
+							} else if ( $t_column == 'due_days' ) {
+								echo $t_function( $t_row[ 'due_date' ] );
+							} else {
+								echo $t_function( $t_row[ $t_column ] );
+							}
 						}
 					}
 				}
@@ -122,4 +128,4 @@
 	} while ( $t_more );
 
 	echo excel_get_footer();
-?>
\ No newline at end of file
+?>
Index: css/default.css
===================================================================
--- css/default.css	(revision 5248)
+++ css/default.css	(working copy)
@@ -53,6 +53,8 @@
 td.right			{ text-align: right; }
 td.category			{ background-color: #c8c8e8; color: #000000; font-weight: bold; vertical-align : top; }
 td.overdue			{ background-color: #ff0000; color: #000000; font-weight: bold; }
+td.overdue2			{ background-color: #ff0000; color: #000000; font-weight: bold; text-align: center}
+td.due2				{ text-align: center}
 
 td.col-1			{ background-color: #d8d8d8; color: #000000; }
 td.col-2			{ background-color: #e8e8e8; color: #000000; }
@@ -61,6 +63,7 @@
 td.small-caption	{ font-size: 8pt; }
 td.print			{ font-size: 8pt; text-align: left; padding: 2px; }
 td.print-category	{ font-size: 8pt; color: #000000; font-weight: bold; text-align: right; padding: 2px; }
+td.print-overdue	{ font-size: 8pt; color: #000000; font-weight: bold; padding: 2px; }
 td.print-bottom		{ border-bottom: 1px solid #000000; }
 td.print-spacer		{ background-color: #ffffff; color: #000000; font-size: 1pt; line-height: 0.1; padding: 0px;}
 
Index: config_defaults_inc.php
===================================================================
--- config_defaults_inc.php	(revision 5248)
+++ config_defaults_inc.php	(working copy)
@@ -531,7 +531,7 @@
 	# selection, edit, id, project_id, reporter_id, handler_id, priority, reproducibility, projection, eta,
 	# resolution, fixed_in_version, view_state, os, os_build, build (for product build), platform, version, date_submitted, attachment,
 	# category, sponsorship_total, severity, status, last_updated, summary, bugnotes_count, description,
-	# steps_to_reproduce, additional_information
+	# steps_to_reproduce, additional_information, due_date, overdue, due_days
 	$g_view_issues_page_columns = array ( 'selection', 'edit', 'priority', 'id', 'sponsorship_total', 'bugnotes_count', 'attachment', 'category', 'severity', 'status', 'last_updated', 'summary' );
 	
 	# The default columns to be included in the Print Issues Page.
Index: csv_export.php
===================================================================
--- csv_export.php	(revision 5248)
+++ csv_export.php	(working copy)
@@ -121,7 +121,13 @@
 				}
 
 				$t_function = 'csv_format_' . $t_column;
-				echo $t_function( $t_row[ $t_column ] );
+				if ( $t_column == 'overdue' ) {
+					echo $t_function( $t_row[ 'id' ], $t_row[ $t_column ] );
+				} else if ( $t_column == 'due_days' ) {
+					echo $t_function( $t_row[ 'due_date' ] );
+				} else {
+					echo $t_function( $t_row[ $t_column ] );
+				}
 			}
 		}
 
Index: core/csv_api.php
===================================================================
--- core/csv_api.php	(revision 5248)
+++ core/csv_api.php	(working copy)
@@ -249,4 +249,41 @@
 	function csv_format_selection( $p_duplicate_id ) {
 		return csv_escape_string( '' );
 	}
+	
+	# --------------------
+	# return due_date
+	function csv_format_due_date( $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $p_due_date );
+		}
+		return csv_escape_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return overdue
+	function csv_format_overdue( $p_bug_id, $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			if ( bug_is_overdue( $p_bug_id ) ) {
+				$t_date_to_display = lang_get( 'overdue_csv_yes' );
+			} else {
+				$t_date_to_display = lang_get( 'overdue_csv_no' );
+			}
+		}
+		return csv_escape_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return due days
+	function csv_format_due_days( $p_due_date ) {
+		$t_date_to_display = '';
+		
+		$t_date = number_format(floor((date("U")-$p_due_date)/86400),0);
+		
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = -(number_format(floor((date("U")-$p_due_date)/86400),0));
+		}
+		return csv_escape_string( $t_date_to_display );
+	}
 ?>
Index: core/excel_api.php
===================================================================
--- core/excel_api.php	(revision 5248)
+++ core/excel_api.php	(working copy)
@@ -423,4 +423,42 @@
 		// field is not linked to project
 		return excel_prepare_string( '' );
 	}
-?>
\ No newline at end of file
+	
+	# --------------------
+	# return due_date
+	function excel_format_due_date( $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $p_due_date );
+		}
+		return excel_prepare_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return overdue
+	function excel_format_overdue( $p_bug_id, $p_due_date ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_due_date ) ) {
+			if ( bug_is_overdue( $p_bug_id ) ) {
+				$t_date_to_display = lang_get( 'overdue_excel_yes' );
+			} else {
+				$t_date_to_display = lang_get( 'overdue_excel_no' );
+			}
+		}
+		return excel_prepare_string( $t_date_to_display );
+	}
+
+	# --------------------
+	# return due days
+	function excel_format_due_days( $p_due_date ) {
+		$t_date_to_display = '';
+		
+		$t_date = number_format(floor((date("U")-$p_due_date)/86400),0);
+		
+		if ( !date_is_null( $p_due_date ) ) {
+			$t_date_to_display = -(number_format(floor((date("U")-$p_due_date)/86400),0));
+		}
+		return excel_prepare_string( $t_date_to_display );
+	}
+	
+?>
Index: core/custom_function_api.php
===================================================================
--- core/custom_function_api.php	(revision 5248)
+++ core/custom_function_api.php	(working copy)
@@ -25,6 +25,7 @@
 
 	require_once( $t_core_dir . 'prepare_api.php' );
 	require_once( $t_core_dir . 'columns_api.php' );
+	require_once( $t_core_dir . 'access_api.php' );
 
 	### Custom Function API ###
 
@@ -240,7 +241,14 @@
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function custom_function_default_print_column_title( $p_column, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
 		global $t_sort, $t_dir;
-
+		
+		$t_current_user_level = current_user_get_access_level();
+		$t_view_due_date = access_compare_level($t_current_user_level, config_get( 'due_date_view_threshold' ));
+		
+		if ( current_user_get_access_level() < $t_view_due_date && 
+			( $p_column == 'due_date' || $p_column == 'overdue' || $p_column == 'due_days' ) )
+			return;
+		
 		$t_custom_field = column_get_custom_field_name( $p_column );
 		if ( $t_custom_field !== null ) {
 			if ( COLUMNS_TARGET_CSV_PAGE != $p_columns_target ) {
@@ -286,6 +294,14 @@
 	# $p_row: the row from the bug table that belongs to the issue that we should print the values for.
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function custom_function_default_print_column_value( $p_column, $p_issue_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+	
+		$t_current_user_level = current_user_get_access_level();
+		$t_view_due_date = access_compare_level($t_current_user_level, config_get( 'due_date_view_threshold' ));
+		
+		if ( current_user_get_access_level() < $t_view_due_date && 
+			( $p_column == 'due_date' || $p_column == 'overdue' || $p_column == 'due_days' ) )
+			return;	
+	
 		if ( COLUMNS_TARGET_CSV_PAGE == $p_columns_target ) {
 			$t_column_start = '';
 			$t_column_end = '';
Index: core/columns_api.php
===================================================================
--- core/columns_api.php	(revision 5248)
+++ core/columns_api.php	(working copy)
@@ -56,6 +56,9 @@
 			'summary',
 			'version',
 			'view_state',
+			'due_date',
+			'overdue',
+			'due_days'
 		);
 
 		# Add project custom fields to the array.  Only add the ones for which the current user has at least read access.
@@ -527,39 +530,21 @@
 	# --------------------
 	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
 	function print_column_edit( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
-		global $t_icon_path, $t_update_bug_threshold;
-		$t_is_overdue = bug_is_overdue( $p_row[ 'id' ] );
-		$t_view_level = access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] );
-		
-		if ( $t_is_overdue && $t_view_level ) {
-			print "<td class=\"overdue\">";
-		} else {
+		if ( $p_columns_target != COLUMNS_TARGET_CSV_PAGE ) {
+			global $t_icon_path, $t_update_bug_threshold;
+
 			echo '<td>';
+			if ( !bug_is_readonly( $p_row['id'] )
+		  		&& access_has_bug_level( $t_update_bug_threshold, $p_row['id'] ) ) {
+				echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+				echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'update.png';
+				echo '" alt="' . lang_get( 'update_bug_button' ) . '"';
+				echo ' title="' . lang_get( 'update_bug_button' ) . '" /></a>';
+			} else {
+				echo '&nbsp;';
+			}
+			echo '</td>';
 		}
-		if ( !bug_is_readonly( $p_row['id'] )
-			&& access_has_bug_level( config_get( 'update_bug_threshold' ), $p_row['id'] ) ) {
-			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
-			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'update.png';
-			echo '" alt="' . lang_get( 'update_bug_button' ) . '"';
-			echo ' title="' . lang_get( 'update_bug_button' ) . '" /></a>';
-		} else {
-			echo '&nbsp;';
-		}
-		if ( $t_is_overdue && $t_view_level ) {
-			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
-			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdue.png';
-			echo '" alt="' . lang_get( 'overdue' ) . '"';
-			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
-		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && $t_view_level ) {
-			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
-			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
-			echo '" alt="' . lang_get( 'due_date' ) . '"';
-			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
-		} else {
-			echo '&nbsp;';
-		}
-		
-		echo '</td>';
 	}
 
 	# --------------------
@@ -782,6 +767,20 @@
 				, lang_get( 'private' )
 			);
 		}
+		$t_is_overdue = bug_is_overdue( $p_row[ 'id' ] );
+		$t_view_level = access_has_bug_level( config_get( 'due_date_view_threshold' ), $p_row['id'] );
+		
+		if ( $t_is_overdue && $t_view_level ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'overdue.png';
+			echo '" alt="' . lang_get( 'overdue' ) . '"';
+			echo ' title="' . lang_get( 'overdue' ) . '" /></a>';
+		} else if ( ! date_is_null( $p_row[ 'due_date' ] ) && $t_view_level ) {
+			echo '<a href="' . string_get_bug_update_url( $p_row['id'] ) . '">';
+			echo '<img border="0" width="16" height="16" src="' . $t_icon_path . 'clock.png';
+			echo '" alt="' . lang_get( 'due_date' ) . '"';
+			echo ' title="' . lang_get( 'due_date' ) . '" /></a>';
+		} 
 		echo '</td>';
 	}
 
@@ -829,4 +828,44 @@
 
 		echo '</td>';
 	}
+	
+	# --------------------
+	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
+	function print_column_due_date( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+		$t_date_to_display = '';
+		if ( !date_is_null( $p_row['due_date'] ) ) {
+			$t_date_to_display = date( config_get( 'short_date_format' ), $p_row['due_date'] );
+		}
+		echo '<td>', $t_date_to_display, '</td>';
+	}
+
+	# --------------------
+	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
+	function print_column_overdue( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+		$t_date_to_display = '';
+		$t_cell = '<td class="due2">';
+		if ( !date_is_null( $p_row['due_date'] ) ) {
+			if ( bug_is_overdue( $p_row['id'] ) ) {
+				$t_cell = '<td class="overdue2">';
+				$t_date_to_display = lang_get( 'yes' );
+			} else {
+				$t_date_to_display = lang_get( 'no' );
+			}
+		}
+		echo $t_cell, $t_date_to_display, '</td>';
+	}
+
+	# --------------------
+	# $p_columns_target: see COLUMNS_TARGET_* in constant_inc.php
+	function print_column_due_days( $p_row, $p_columns_target = COLUMNS_TARGET_VIEW_PAGE ) {
+		$t_date_to_display = '';
+		
+		$t_date = number_format(floor((date("U")-$p_row['due_date'])/86400),0);
+		
+		if ( !date_is_null( $p_row['due_date'] ) ) {
+			$t_date_to_display = -(number_format(floor((date("U")-$p_row['due_date'])/86400),0));
+		}
+		echo '<td>', $t_date_to_display, '</td>';
+	}
+
 ?>
duedate_stage3_final3.diff (17,080 bytes)   

Relationships

related to 0009272 new due_date conversion problem when using custom date format 
parent of 0009088 closedgrangeway After upgrade all issues are assigned 1970-01-01 and some are considered overdue 
parent of 0009346 closedvboctor Due Date is shown in history even if user doesn't have access to view due dates 
parent of 0009155 closeddregad Cell coloring for due date indicates "overdue" when not overdue yet. 
parent of 0009291 confirmed Bogus history entries are created for Due Date 
has duplicate 0007019 closedvboctor There should be a field "Due Date" (also as sort criterion) 
has duplicate 0009151 closedgrangeway Due_Date column not availabe on "Manage Columns" pages. 
related to 0009057 closedvboctor Request feature 
related to 0007829 new remember / timestamp function 
Not all the children of this issue are yet resolved or closed.

Activities

vboctor

vboctor

2008-03-08 01:12

manager   ~0017287

I haven't applied the patch yet (got some error and rebuilding my git repository), but following are some comments:

  1. deadline -> due_date
  2. css overdued -> overdue?
  3. Default $g_due_date_set_threshold = DEVELOPER;
  4. bug_is_overdued -> overdue
  5. bug_is_overdued -> cache the whole row, then get the due date from it.
  6. bug_is_overdued -> shouldn't you check if isset() on due_date before calculating the db_unixtimestamp?
  7. When checking if the due date is set, should be use is_blank() rather than isset()?
  8. bug_check_workflow -> lang_get( 'deadline' ) - use one terminology everywhere.
vboctor

vboctor

2008-03-08 02:00

manager   ~0017288

Here are some more comments after doing some further testing on the patch:

  1. The installation doesn't add the due_date - cause is that the name of the upgrade array is mis-spelled in schema.php.

  2. System Warning on Issue Advanced Update page.

  3. Due date should be displayed without the time portion, it should be just a date. Currently it uses the following format by default: "2008-03-09 00:00"

  4. It is not possible to add "due_date" field to My Account -> Manage Columns -> View issues (or other formats).

  5. I don't think the due date should belong to the simple report/update/view pages.

  6. When including due date on the report page, it doesn't get saved correctly.

  7. The overdue css style seem to center the data. I don't think this is a good idea. The style can highlight the text or change the color, but shouldn't change the alignment.

  8. On the View Issues page, the overdue icon has the title as "Update Issue". I believe the title should be the due date. I wonder if we should have an icon next to any issue that has a due date, where we use one icon for overdue and one for items that are not overdue.

  9. On the View Issues page, move the overdue icon to be after the summary, similar to the lock icon that appears after private issues.

  10. In the schema you use a T to represent the due date, I wonder if there is a date type. I am assuming we are not supporting a due time, but rather a due date. Not a big deal though, if it makes our life simpler, then we can stick with the current type.

smig1o

smig1o

2008-03-08 08:08

reporter   ~0017296

Wheee... a feedback :)
Sorry for mess with due_date <-> deadline. I've just ported this from my todo list patch.
Of course I'll follow your suggestions about naming, css etc and prepare upgrade ASAP.
@ date formating.. I use mantis standard functions. I'll se what I can do about that.
@ icons. I use icons from free set, but its licence demands to say about it (the set) on page where it is used. thats why I screamed about changing the icon. On the other hand we can set needed information & link and uset the icons :)
I was thinking of adding icon to each issue with due date set. Overdued with red dot by clock and not overdued with green one.
I had a problem with checking due date cos it can be null and if its then bug_get_field returns error which forced me to load due date by my own (SQL).

Value of default should be discussed as well.

Besides. bug_is_overdued isnt checking bug status. I've realized that after I'd submitted the patch.

Ok. I'll work on it to make it perfect ;).
If only you could send me feedback more often.. ;)

smig1o

smig1o

2008-03-27 06:00

reporter   ~0017472

Last edited: 2008-03-27 06:04

@ 1.1 fixed. Anjuta find'n'replace sux.. :)
@ 1.2 fixed
@ 1.3 set to Array (ADMINISTRATOR, MANAGER) now
@ 1.4 fixed to overdue
@ 1.5 fixed
@ 1.6 function rewritten
@ 1.7 rewriten in several places..
@ 1.8 sure. checked and fixed

@ 2.1 I wasnt able to find that mis-spell.. sorry
@ 2.2 Warning caused by bug_get_field function. Fixed now (no I didnt touch bug_get_field function..)
@ 2.3 Now I use short_date_format to display due date
@ 2.4 That will be fixed in stage 3 AFAIR
@ 2.5 Removed from simple pages
@ 2.6 Checked and fixed
@ 2.7 Now I do not change the allignment
@ 2.8 Icons by issues with due date set is just an idea. But it can be moved/removed...
@ 2.9 Im not sure if its good place for that. IMHO due date is important information and should be displayed in front. Of Course it can be easely changed.
@ 2.10 I left T type for due date. Whats more.. I use 1970-01-01 00:00:01 as a null date.

Stage 1:

  • db schema modification
  • view/report/update forms modifications
  • nothing else (so icons on View Issues are something extra that will be fixed in stage 3)

Take a closer look at bug_api changes (bug_create and bug_update functions). I use there >strtotime< function to convert date between user format (short_date _format) and database format ( Y-m-d). If you know better way to do that.. let me know.

Patch posted

Oh.. almost forgot.
Patch made against rev 5086.

smig1o

smig1o

2008-03-30 02:51

reporter   ~0017490

Ok I think due_date stag1 is ready for use right now...
I think...

vboctor

vboctor

2008-03-30 03:12

manager   ~0017494

Thanks smig1o, I'll check it out when I get a chance.

vboctor

vboctor

2008-03-30 03:34

manager   ~0017497

I'm getting errors while applying the patch using git:

[vboctor@localhost mantisbt]$ git apply diffs
diffs:26: trailing whitespace.
<?php if ( $t_can_set_due_date ) {
diffs:30: trailing whitespace.
echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar.js\"></script>\n";
diffs:31: trailing whitespace.
echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/lang/calendar-en.js\"></script>\n";
diffs:32: trailing whitespace.
echo "<script type=\"text/javascript\" src=\"javascript/jscalendar/calendar-setup.js\"></script>\n";
diffs:59: trailing whitespace.
if ( $t_can_set_due_date ) {
error: patch failed: admin/schema.php:399
error: admin/schema.php: patch does not apply
error: patch failed: config_defaults_inc.php:1989
error: config_defaults_inc.php: patch does not apply
error: patch failed: lang/strings_english.txt:1501
error: lang/strings_english.txt: patch does not apply

smig1o

smig1o

2008-03-30 03:45

reporter   ~0017498

I see.. patch was made against r 5086 which is a bit old..
duedate_final1 is madea against lastest..

sorry I forogt about source update..

vboctor

vboctor

2008-03-31 02:00

manager   ~0017504

Thanks smig1o for your effort. The patch looks good. Following are some comments:

  1. The way access level is checked. Why don't you use access_has_bug_level() and similar methods?
  2. I am wondering if we are better off marking due date as a nullable field? Maybe this is something we can discuss on IRC or through here. If we decided to keep the implementation as is (i.e. not nullable), then we should define the value for "null" as a constant in constants_inc.php and use the define instead of the hard coded value.
  3. As per our standard, If body must have {} even if it has one line. For example, bug_update.php
  4. bug_update_advanced_page.php has some added dead code (commented out).
  5. Should the due date show up in the bug update simple page? I think it is not part of the bug report simple page. I don't mind having a configuration option that controls showing / accepting due date on simple pages (report, update, view).
  6. In config_defaults_inc.php, set $g_due_date_set_threshold to DEVELOPER. The array format should be used when cherry picked roles are used, but if a role and higher is to be used, then we just specify the role.
  7. In bug_is_overdue(), use $t_bug_row rather than $t_bug_all. Also fix curly brackets for IF statements.
  8. In bug_check_workflow(), the variable name $t_tmp is not descriptive.
  9. I believe that we should consider having a configuration option for viewing the due dates. Such configuration option should hide due dates as well as the overdue indicators when the logged in user doesn't have access.
  10. After applying the patch, I get blank install / login screens.
vboctor

vboctor

2008-03-31 02:01

manager   ~0017505

Once more comment, please attach the patches without zipping them. This allows us to preview them in the browser. We typically use zip files when attaching multiple files as one bundle.

smig1o

smig1o

2008-03-31 10:17

reporter   ~0017509

@ 1 fixed
@ 2 2 new functions in date_api: date_is_null and date_get_null. due_date is not null field.
@ 3 I hope I fixed that too
@ 4 I didnt find any dead code in there...
@ 5 due date is shown only on >advanced< versions of page
@ 6 fixed
@ 7 fixed var name and brackets
@ 8 did I do anything to bug_check_workflow() function?? I dont think so..
@ 9 added g_due_date_see_threshold. used in bug_advanced_view_page and in columns_api
@ 10 No idea why.. try now
I found a big problem with schema.php. Adding field with >AddColumnSQL< comman produce messed SQL commands. Seems you must apply DB changes by yourself untill this will be fixed.
I found a bug in version_api bug. Fixed that too (must be double checked!) Its, again, problem with postgres and fact that false != 0 for postgres.

smig1o

smig1o

2008-04-04 04:53

reporter   ~0017548

Some minor changes...

vboctor

vboctor

2008-04-05 03:08

manager   ~0017554

I couldn't apply the patch, I got conflicts in schema.php. You will probably need to update, apply comments below, update again :), and then create the patch.

I've pasted duedate_stage1_final3.diff on pastebin to easily comment on it using line numbers:
http://mantis.pastebin.com/f43ece012

L27: due_date_set_threshold -> due_date_update_threshold.
L56. 59: Use echo rather than print.
L121: due_date_set_threshold -> due_date_update_threshold (update config option and temporary variable).
L137-161: Can't we encapsulate all of this into an API that can be called to print a date field with a calendar given some parameters?
L258: $cal_icon -> $t_cal_icon. Replace all usage of such variable.
L367: Update this comment. This is the threshold required for a user to be able to set or update the due date field.
L370: Update name as indicated above. Add documentation. Default should be VIEWER OR DEVELOPER. I think that we may want to be on the conservative side and go with DEVELOPER.
L415: Use bug_isresolved().
L509: Use curly brackets for the if/else blocks.
L518, 520, 521: Don't assign values to $p
variables. The value for parameters must never change. If necessary then create a corresponding $t_ variable.
L572: It seems that the image is still called overdued.
L641: We shouldn't pass the obsolete flag in if it wasn't added to the query. You can create a parameters array and add to it the values whenever you insert corresponding db_param() in the query.

smig1o

smig1o

2008-04-10 08:10

reporter   ~0017583

Updated all except L641.

L641 is not part of due_date patch. It fixes problem with bool field in version_api. I've removed it from fianl4.

I hop now you'll be able to apply the patch w/o problems.
Patch should be valid till 17.04. ;)

smig1o

smig1o

2008-04-11 04:04

reporter   ~0017587

At the end of schema.php
-$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "

  • due_date T NOTNULL DEFAULT '1970-01-01 00:00:01' " ) );

+$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'mantis_bug_table' ), "

  • due_date T NOTNULL DEFAULT '1970-01-01' " ) );

That will fix schema update problems

vboctor

vboctor

2008-04-12 01:05

manager   ~0017589

OK, I just tried now, failed to apply again. I don't know why the patches are very sensitive to changes. It would be great if you upload a new patch with the time fix as well. Sorry.

smig1o

smig1o

2008-04-12 05:15

reporter   ~0017590

I hope youll find a time today to try this one...

vboctor

vboctor

2008-04-12 16:17

manager   ~0017591

I have the same problem merging schema.php. Also you shouldn't be adding schema steps except at the end of the file. So your new due_date field should be after the version obsolete field.

Please also add documentation to the new date_xxx() functions in date_api.php.

Here is the error that I am getting:

[vboctor@localhost mantisbt]$ git apply /home/vboctor/Desktop/duedate_stage1_final5.diff
/home/vboctor/Desktop/duedate_stage1_final5.diff:40: trailing whitespace.
<?php if ( $t_can_update_due_date ) {
/home/vboctor/Desktop/duedate_stage1_final5.diff:44: trailing whitespace.
$t_date_to_display = date( config_get( 'short_date_format' ), $t_bug->due_date );
/home/vboctor/Desktop/duedate_stage1_final5.diff:68: trailing whitespace.
if ( $t_can_update_due_date ) {
/home/vboctor/Desktop/duedate_stage1_final5.diff:103: trailing whitespace.

/home/vboctor/Desktop/duedate_stage1_final5.diff:113: trailing whitespace.

error: patch failed: admin/schema.php:402

smig1o

smig1o

2008-04-13 05:03

reporter   ~0017593

Victor I dont know why schema.php fails. But its the first file to be patched. So try to eatcher use pure patch command or remove schema.php section from the file and try again.
I have no idea why this file fails..
good luck

smig1o

smig1o

2008-04-15 16:30

reporter   ~0017606

victor, daryn helped me create working patch. Nuclear_eclyps has tested it and its ok, so, please check it asap...

vboctor

vboctor

2008-04-16 02:30

manager   ~0017608

The patch duedate_stage1_final8.diff was checked in after two fixes:

  1. Fixed a notice in bug_api.php.
  2. Fixed a bug in bug_set_field() where it was adding 00:00:01 to the new value in bug history.

The following is yet to be done:

  1. The clock / overdue icon should not be in the edit column. It should should either move it after the summary or consider other options.

  2. The code that decides whether to display the icons or not in print_column_edit_value() calls APIs several times rather than caching the value and re-using it.

This marks the completion of stage 1. Stage 2 is the filtering, but we've agreed to move directly to stage 3 which is support for due date in View Issues Page, Print Issues page, csv, and Excel.

svn:5167
http://mantisbt.svn.sourceforge.net/mantisbt/?rev=5167&view=rev

smig1o

smig1o

2008-04-18 15:24

reporter   ~0017623

Stage 3 is about support View Issues Page, Print Issues, Print Issue and Excel/CVS export.

Print Issue will contain Due date info filled with date, bold for overdued issue.

For other situations Im going to create 3 columns based on due date:

  • due date ( date itself or blank )
  • is issue overdue (Yes / No / Blank)
  • days to due date ( number of days till due date. Negative if that date passed)
    The clock icon will be moved to summary field.

All suggestions are welcome.

smig1o

smig1o

2008-04-19 10:44

reporter   ~0017627

Patch fix the problem from bug 9088 and some minor problems in other files.

smig1o

smig1o

2008-04-22 08:37

reporter   ~0017658

Stage3 patch posted. It adds support for manage 3 columns: due_date, overdue and due_days. Export to CSV, Word, Excel added as well.
There are also several minor fixes in bug_api file.
Patch made agains r5190

smig1o

smig1o

2008-04-24 08:27

reporter   ~0017679

I hope thats the last >stage3_final< patch.
Its made against rev 5200.

vboctor

vboctor

2008-04-25 23:22

manager   ~0017703

I'll try to check the stage 3 patch in details. However, following are some quick issues that I noticed:

  1. The patch doesn't include the updates for the Docbook.
  2. I'm wondering if the export format should include localized "yes"/"no" vs. x/[blank] or 1/0. We might also decide to have csv not use localized strings, where others do.
  3. When you are comparing against due date view threshold, you can't use smaller than operator. Since a threshold can be a cut off (in this case smaller than operator would work), or it can be an array of access levels. Hence, the right way to do it is to use access_has_bug_access_level() or something similar.
smig1o

smig1o

2008-04-26 11:03

reporter   ~0017704

@1 No it doesnt. Seems I must closer look at documentaton then, but I dont think docbook part will be stage3 element. I'll prepare it separately.
@2 I can prepare strings "yes"/"no" for each export format so user will decide what he wants to see. The only problem is with x/[blank] since blank means "due date not set" not "not overdue".
@3 I keep forgetting that threshold can be an array... I'll fix it asap.

Since this patch fixes some bugs in bug_is_overdue and bug_set_field functions I'd like them to be applied asap. I'll try to prepare patch today.

Thanks for feedback

smig1o

smig1o

2008-05-06 15:19

reporter   ~0017785

Lastest patch made against rev. 5248

vboctor

vboctor

2008-06-27 19:54

manager   ~0018212

smig1o, can you checkout 0009272. Let me know once you have a patch that has all the fixes so far.

One more thing, can you please make the due date feature disabled by default. This can be done by setting the thresholds to NOBODY.

smig1o

smig1o

2008-07-03 02:35

reporter   ~0018286

I'll fix that and 9272 as soon as ill find some free time. Right now I've got deadlined job to finish. After deadline, Ill create patch and update stage3 patch too

Niko

Niko

2008-08-13 05:55

reporter   ~0019141

Hi,

i am very interested in this topic, but i need some help to open those patches.
I have no idea, how you find the newest one... because none of those is working fine. I use TortoiseSVN to patch, but i cant find the current version of mantis nor patches.

by the way, great work! One week ago i also started to develop something equal...but now i think i will continue your idea, but first i have to find the knowledge behind this stuff ^^

smig1o

smig1o

2008-08-14 03:06

reporter   ~0019153

Hi there
First of all remember that due date feature is prepared for 1.2.x version.
I'm trying to prepare patch for lastes svn version but, since it been changed quite often its becoming out of date quite soon after I put it in here.
here http://www.mantisbt.org/wiki/doku.php/?do=search&id=due+date you'll find details about implementid that feature. So far stage 1 was applied and in bug 9272 you'll find patch with some fixes.
I have posted here stage 3 patch but now its out of date and cant be applied. AFAIK it's been partially applied but right now I have no idea what should be done to finish this feature.

smig1o

smig1o

2010-04-22 11:38

reporter   ~0025200

This issue should be closed since Mantis 1.2 has due date now.

atrol

atrol

2012-08-08 15:30

developer   ~0032515

Closed akkording to smig1o's feedback 0008942:0025200