--- ../mantis-1.0.6/lang/strings_english.txt	2006-10-23 16:14:44.000000000 +0900
+++ lang/strings_english.txt	2007-03-30 14:46:32.000000000 +0900
@@ -138,6 +138,7 @@
 $s_graph_imp_severity_title = 'Synthesis graphs by severity';
 $s_graph_imp_category_title = 'Synthesis graphs by category';
 $s_graph_imp_resolution_title = 'Synthesis graphs by resolution';
+$s_graph_imp_date_title = 'Sythesis graph by date';
 $s_by_status_pct = 'by status percentage';
 $s_by_priority_pct = 'by priority percentage';
 $s_by_severity_pct = 'by severity percentage';
@@ -146,12 +147,17 @@
 $s_by_severity_mix = 'by severity and status';
 $s_by_priority_mix = 'by priority and status';
 $s_by_resolution_mix = 'by resolution and status';
+$s_with_priority = 'with priority';
+$s_daily = 'Daily';
+$s_weekly = 'Weekly';
+$s_monthly = 'Monthly';
 $s_synthesis_link = 'Synthesis';
 $s_status_link = 'Per state';
 $s_priority_link = 'Per priority';
 $s_severity_link = 'Per severity';
 $s_category_link = 'Per category';
 $s_resolution_link = 'Per resolution';
+$s_date_link = 'Per date';
 $s_legend_still_open = 'Still Open';
 $s_legend_resolved = 'Resolved';
 $s_legend_assigned = 'Assigned';
--- ../mantis-1.0.6/lang/strings_japanese_utf8.txt	2006-10-23 16:14:44.000000000 +0900
+++ lang/strings_japanese_utf8.txt	2007-03-30 16:17:36.000000000 +0900
@@ -140,6 +140,7 @@
 $s_graph_imp_severity_title = '重要度によるグラフ';
 $s_graph_imp_category_title = 'カテゴリによるグラフ';
 $s_graph_imp_resolution_title = '分析状況によるグラフ';
+$s_graph_imp_date_title = '時系列によるグラフ';
 $s_by_status_pct = 'ステータスパーセンテージ';
 $s_by_priority_pct = '優先パーセンテージ';
 $s_by_severity_pct = '重要度パーセンテージ';
@@ -148,12 +149,17 @@
 $s_by_severity_mix = '重要度とステータス';
 $s_by_priority_mix = '優先度とステータス';
 $s_by_resolution_mix = '解決とステータス';
+$s_with_priority = '+ 優先度別';
+$s_daily = '日別';
+$s_weekly = '週別';
+$s_monthly = '月別';
 $s_synthesis_link = '総合';
 $s_status_link = 'ステータス別';
 $s_priority_link = '優先度別';
 $s_severity_link = '重要度別';
 $s_category_link = 'カテゴリ別';
 $s_resolution_link = '分析状況別';
+$s_date_link = '時系列別';
 $s_legend_still_open = '未解決';
 $s_legend_resolved = '解決済';
 $s_legend_assigned = '割当済';
--- ../mantis-1.0.6/core/html_api.php	2006-09-09 14:47:14.000000000 +0900
+++ core/html_api.php	2007-03-29 18:35:17.000000000 +0900
@@ -600,7 +600,8 @@
 			PRINT '<a href="summary_graph_imp_priority.php"><img src="' . $t_icon_path.'synthgraph.gif" border="0" align="center" />' . lang_get( 'priority_link' ) . '</a> | ';
 			PRINT '<a href="summary_graph_imp_severity.php"><img src="' . $t_icon_path.'synthgraph.gif" border="0" align="center" />' . lang_get( 'severity_link' ) . '</a> | ';
 			PRINT '<a href="summary_graph_imp_category.php"><img src="' . $t_icon_path.'synthgraph.gif" border="0" align="center" />' . lang_get( 'category_link' ) . '</a> | ';
-			PRINT '<a href="summary_graph_imp_resolution.php"><img src="' . $t_icon_path.'synthgraph.gif" border="0" align="center" />' . lang_get( 'resolution_link' ) . '</a>';
+			PRINT '<a href="summary_graph_imp_resolution.php"><img src="' . $t_icon_path.'synthgraph.gif" border="0" align="center" />' . lang_get( 'resolution_link' ) . '</a> | ';
+			PRINT '<a href="summary_graph_imp_date.php"><img src="' . $t_icon_path.'synthgraph.gif" border="0" align="center" />' . lang_get( 'date_link' ) . '</a>';
 		}
 	}
 
--- /dev/null	2007-04-10 15:51:58.000000000 +0900
+++ ./summary_graph_bydate.php	2007-04-10 14:19:37.000000000 +0900
@@ -0,0 +1,410 @@
+<?php
+
+define( 'INTERVAL_DAILY',  '1' );
+define( 'INTERVAL_WEEKLY', '7' );
+define( 'INTERVAL_MONTH',  '-1' );
+define( 'LENGTH_INFINITY', '-1' );
+
+$g_f = null;
+
+function debug_r($obj) {
+    global $g_f;
+    fwrite($g_f, print_r($obj, true));
+}
+
+function db_query_with_date( $p_query ) {
+    $t_result   = array();
+    $t_dbresult = db_query( $p_query );
+
+    while ( $t_row = db_fetch_array( $t_dbresult ) ) {
+        preg_match( '/^(\d+-\d+-\d+)/', $t_row[0], $t_match );
+        $t_date = $t_match[1];
+
+        if ( !array_key_exists( $t_date, $t_result ) ) {
+            $t_result[$t_date] = array();
+        }
+
+        array_shift( $t_row );
+        $t_result[$t_date][] = $t_row;
+    }
+
+    ksort( $t_result );
+
+    return $t_result;
+}
+
+function db_get_start_day() {
+    $t_project_id = helper_get_current_project();
+    $t_query      = "SELECT date_submitted FROM mantis_bug_table
+                     WHERE project_id = '$t_project_id'
+                     ORDER BY date_submitted LIMIT 1";
+    $t_day        = db_result( db_query( $t_query ), 0, 0 );
+
+    preg_match( '/^(\d+)-(\d+)-(\d+)/', $t_day, $t_matches );
+
+    return array( 'Y' => $t_matches[1],
+                  'm' => $t_matches[2],
+                  'd' => $t_matches[3] );
+}
+
+function add_date( $p_d, $p_n ) {
+    preg_match( '/^(\d+)-(\d+)-(\d+)/', $p_d, $t_m );
+
+    $t_t = $p_n == INTERVAL_MONTH ?
+        mktime( 0, 0, 0, $t_m[2] + 1, 1, $t_m[1] ) :
+        mktime( 0, 0, 0, $t_m[2], $t_m[3] + $p_n, $t_m[1] );
+
+    return date( 'Y-m-d', $t_t );
+}
+
+function check_range( $p_range, $p_date ) {
+    preg_match ( '/^(\d+-\d+-\d+) - (\d+-\d+-\d+)$/', $p_range, $t_matches );
+//    $t_v = $t_matches[1] <= $p_date && $p_date < $t_matches[2];
+//    debug_r("$p_range, $p_date => " . ($t_v ? "true" : "false") . "\n");
+//    return $t_v;
+    return $t_matches[1] <= $p_date && $p_date < $t_matches[2];
+}
+
+function get_custom_field_name( $t_fieldid ) {
+    $t_query  = "SELECT name FROM mantis_custom_field_table
+                 WHERE id='$t_fieldid'";
+    $t_result = db_query( $t_query );
+    return db_result( $t_result, 0, 0 );
+}
+
+function group_result_by_date( $p_data, $p_begin, $p_end, $p_interval ) {
+    $t_result = array();
+    $t_tmp    = array();
+
+    $t_labels = array();
+    while ( $p_begin < $p_end ) {
+        $t_end = add_date( $p_begin, $p_interval );
+
+        switch ( $p_interval ) {
+        case INTERVAL_DAILY:
+           $t_labels[] = array( 'label' => $p_begin,
+                                'cond'  => "$p_begin - $t_end" );
+           break;
+
+        case INTERVAL_MONTH:
+           preg_match( '/^(\d+-\d+)/', $p_begin, $t_matches );
+           $t_labels[] = array( 'label' => $t_matches[1],
+                                'cond'  => "$p_begin - $t_end" );
+           break;
+
+        default:
+           $t_labels[] = array( 'label' => "$p_begin - $t_end",
+                                'cond'  => "$p_begin - $t_end" );
+           break;
+        }
+
+        $p_begin = $t_end;
+    }
+
+    $t_current = array_shift( $t_labels );
+
+    foreach ( $p_data as $t_date => $t_value ) {
+        while ( $t_labels && !check_range( $t_current['cond'], $t_date ) ) {
+            $t_result[$t_current['label']] = $t_tmp;
+            $t_tmp                         = array();
+            $t_current                     = array_shift( $t_labels );
+        }
+
+        $t_tmp = array_merge( $t_tmp, $t_value );
+    }
+
+    $t_result[$t_current['label']] = $t_tmp;
+
+    foreach ( $t_labels as $t_label ) {
+        $t_result[$t_label['label']] = array();
+    }
+
+    return $t_result;
+}
+
+function graph_accbarplot( $p_metrics, $p_title, $p_legends,
+                           $p_width, $p_height ) {
+    $t_graph_font = graph_get_font();
+
+    $graph = new Graph( $p_width, $p_height );
+    $graph->img->SetMargin( 45, 100, 35, 100 );
+    $graph->img->SetAntiAliasing();
+    $graph->SetScale('textlin');
+    $graph->SetMarginColor('white');
+    $graph->SetFrame(false);
+    $graph->title->SetFont( $t_graph_font, FS_BOLD );
+    $graph->title->Set($p_title);
+    if ( FF_FONT2 <= $t_graph_font ) {
+        $graph->xaxis->SetLabelAngle(60);
+    } else {
+        $graph->xaxis->SetLabelAngle(90);
+	}
+	$graph->xaxis->SetFont( $t_graph_font );
+    $graph->xaxis->SetTickLabels( array_keys( $p_metrics ) );
+	$graph->legend->Pos(0.05, 0.08);
+	$graph->legend->SetFont( $t_graph_font );
+	$graph->yaxis->scale->ticks->SetDirection(-1);
+	$graph->yaxis->SetFont( $t_graph_font );
+	$graph->yscale->SetGrace(10);
+
+    $t_plots = array();
+
+    foreach ( $p_legends as $t_label => $t_legend_attr ) {
+        $t_values = array();
+
+        foreach ( $p_metrics as $t_stat ) {
+            $t_values[] = $t_stat[$t_label];
+        }
+
+        $t_plot = new BarPlot( $t_values );
+        $t_plot->SetFillColor( $t_legend_attr['color'] );
+        $t_plot->SetLegend( $t_legend_attr['legend'] );
+        $t_plots[] = $t_plot;
+    }
+
+    $t_acc = new AccBarPlot( $t_plots );
+    $graph->Add( $t_acc );
+
+    if ( ON == config_get( 'show_queries_count' ) ) {
+        $graph->subtitle->Set( db_count_queries() . ' queries (' . db_count_unique_queries() . ' unique) (' . db_time_queries() . 'sec)' );
+        $graph->subtitle->SetFont( $t_graph_font, FS_NORMAL, 8 );
+    }
+
+    $graph->Stroke();
+}
+
+function generate_graph_total( $p_data, $p_title, $p_width, $p_height ) {
+    $t_metrics = array();
+
+    foreach ( $p_data as $t_label => $t_data ) {
+        $t_metrics[$t_label] = count( $t_data );
+    }
+
+    graph_bar( $t_metrics, $p_title, $p_width, $p_height );
+}
+
+function generate_graph_priority( $p_data, $p_title, $p_width, $p_height ) {
+    $t_priority_enum_strings = explode( ',',
+                                        lang_get( 'priority_enum_string' ) );
+    $t_priority_strings      = array();
+
+    foreach ( $t_priority_enum_strings as $t_string ) {
+        $t_enum = explode( ':', $t_string );
+        $t_priority_strings[$t_enum[0]] = $t_enum[1];
+    }
+
+    $t_legends = array();
+    $t_legends['immediate'] = array( 'color'  => 'goldenrod2',
+                                     'legend' => $t_priority_strings[60] );
+    $t_legends['urgent']    = array( 'color'  => 'lemonchiffon1',
+                                     'legend' => $t_priority_strings[50] );
+    $t_legends['high']      = array( 'color'  => 'cadetblue3',
+                                     'legend' => $t_priority_strings[40] );
+    $t_legends['normal']    = array( 'color'  => 'chartreuse3',
+                                     'legend' => $t_priority_strings[30] );
+    $t_legends['low']       = array( 'color'  => 'cyan4',
+                                     'legend' => $t_priority_strings[20] );
+    $t_legends['none']      = array( 'color'  => 'cyan3',
+                                     'legend' => $t_priority_strings[10] );
+
+    $t_metrics = array();
+
+    foreach ( $p_data as $t_label => $t_value ) {
+        $t_tmp = array( 'none' => 0, 'low'  => 0,   'normal' => 0,
+                        'high' => 0, 'urgent' => 0, 'immediate' => 0 );
+
+        foreach ( $t_value as $t_pri ) {
+            switch ( $t_pri['priority'] ) {
+            case 10: $t_tmp['none']++;      break;
+            case 20: $t_tmp['low']++;       break;
+            case 30: $t_tmp['normal']++;    break;
+            case 40: $t_tmp['high']++;      break;
+            case 50: $t_tmp['urgent']++;    break;
+            case 60: $t_tmp['immediate']++; break;
+            }
+        }
+
+        $t_metrics[$t_label] = $t_tmp;
+    }
+
+    graph_accbarplot( $t_metrics, $p_title, $t_legends, $p_width, $p_height );
+}
+
+function generate_graph_custom( $p_data, $p_title, $p_width, $p_height ) {
+    $t_colors  = array( 'goldenrod2', 'lemonchiffon1', 'cadetblue3',
+                        'chartreuse3', 'cyan4', 'cyan3', 'darkorchid',
+                        'hotpink', 'gold1', 'greenyellow' );
+    $i         = 0;
+    $t_legends = array();
+    $t_metrics = array();
+
+    foreach ( $p_data as $t_label => $t_values ) {
+        foreach ( $t_values as $t_value ) {
+            $t_value = $t_value[0];
+
+            if ( !array_key_exists( $t_value, $t_legends ) ) {
+                $t_legends[$t_value] =
+                    array ( 'legend' => $t_value,
+                            'color'  => $t_colors[$i % count($t_colors)] );
+                $i++;
+            }
+        }
+    }
+
+    foreach ( $p_data as $t_label => $t_values ) {
+        $t_tmp = array();
+
+        foreach ( $t_legends as $t_legend ) {
+            $t_tmp[$t_legend['legend']] = 0;
+        }
+
+        foreach ( $t_values as $t_value ) {
+            $t_tmp[$t_value[0]]++;
+        }
+
+        $t_metrics[$t_label] = $t_tmp;
+    }
+
+    graph_accbarplot( $t_metrics, $p_title, $t_legends, $p_width, $p_height );
+}
+
+function generate_graph( $p_mode, $p_range, $p_width, $p_height ) {
+    $t_title = $t_interval = $t_length = $t_query = $t_fieldid =
+        $t_begin = $t_end = null;
+
+    switch ( $p_range ) {
+    case 'daily':
+       $t_title    = lang_get( 'daily' );
+       $t_interval = INTERVAL_DAILY;
+       $t_length   = 30;
+       $t_past  = ($t_interval * $t_length) - 1;
+       $t_begin = date( 'Y-m-d', strtotime( "-$t_past day" ) );
+       $t_end   = date( 'Y-m-d', strtotime( '+1 day' ) );
+       break;
+
+    case 'weekly':
+       $t_title    = lang_get( 'weekly' );
+       $t_interval = INTERVAL_WEEKLY;
+       $t_length   = 12;
+       $t_past     = $t_length * 7;
+       $t_dow      = date( 'w' );
+       $t_begin    = date( 'Y-m-d',
+                           mktime( 0, 0, 0,
+                                   date( 'm' ),
+                                   date( 'd' ) + 7 - $t_dow - $t_past,
+                                   date( 'Y' ) ) );
+       $t_end      = date( 'Y-m-d',
+                           mktime( 0, 0, 0,
+                                   date( 'm' ),
+                                   date( 'd' ) + 7 - $t_dow,
+                                   date( 'Y' ) ) );
+//       $t_begin    = date( 'Y-m-d', strtotime( "+1 Sunday -$t_past day" ) );
+//       $t_end      = date( 'Y-m-d', strtotime( '+1 Sunday' ) );
+       break;
+
+    case 'monthly':
+       $t_title    = lang_get( 'monthly' );
+       $t_interval = INTERVAL_MONTH;
+       $t_length   = LENGTH_INFINITY;
+
+       if ( $t_length != LENGTH_INFINITY ) {
+           $t_begin = date( 'Y-m-d',
+                            mktime( 0, 0, 0,
+                                    date( 'm' ) - $t_length + 1,
+                                    1, date( 'Y' ) ) );
+       } else {
+           $t_start = db_get_start_day();
+           $t_begin = date( 'Y-m-d',
+                            mktime( 0, 0, 0,
+                                    $t_start['m'], 1, $t_start['Y'] ) );
+       }
+
+       $t_end   = date( 'Y-m-d',
+                        mktime( 0, 0, 0,
+                                date( 'm' ) + 1, 1, date( 'Y' ) ) );
+       break;
+    }
+
+    $t_project_id = helper_get_current_project();
+
+    switch ( $p_mode ) {
+    case 'total':
+       $t_query = "SELECT date_submitted
+                   FROM mantis_bug_table
+                   WHERE project_id = '$t_project_id' AND
+                         date_submitted >= '$t_begin' AND
+                         date_submitted <  '$t_end'";
+       break;
+
+    case 'priority':
+       $t_query = "SELECT date_submitted, priority
+                   FROM mantis_bug_table
+                   WHERE project_id = '$t_project_id' AND
+                         date_submitted >= '$t_begin' AND
+                         date_submitted <  '$t_end'";
+       break;
+
+    default:
+       if ( preg_match( '/^custom(\d+)$/', $p_mode, $t_matches ) ) {
+           $t_fieldid = $t_matches[1];
+
+           $t_query = "SELECT b.date_submitted, s.value
+                       FROM mantis_bug_table AS b,
+                            mantis_custom_field_string_table AS s
+                       WHERE b.id = s.bug_id AND
+                             b.project_id = '$t_project_id' AND
+                             s.field_id = '$t_fieldid' AND
+                             b.date_submitted >= '$t_begin' AND
+                             b.date_submitted <  '$t_end'";
+       }
+       break;
+    }
+
+    $t_data = db_query_with_date( $t_query );
+    $t_data = group_result_by_date( $t_data, $t_begin, $t_end, $t_interval );
+
+    switch ( $p_mode ) {
+    case 'total':
+       generate_graph_total( $t_data, $t_title, $p_width, $p_height );
+       break;
+
+    case 'priority':
+       $t_title .= ' ' . lang_get( 'with_priority' );
+       generate_graph_priority( $t_data, $t_title, $p_width, $p_height );
+       break;
+
+    default:
+       if ( $t_fieldid !== null ) {
+           $tltitle .= ' (' . get_custom_field_name( $t_fieldid ) . ')';
+           generate_graph_custom( $t_data, $t_title, $p_width, $p_height );
+       }
+    }
+}
+
+?>
+<?php
+require_once( 'core.php' );
+
+$t_core_path = config_get( 'core_path' );
+
+require_once( $t_core_path . 'graph_api.php' );
+
+$f_width  = gpc_get_int( 'width', 300 );
+$f_range  = gpc_get_string( 'range' );
+$f_mode   = gpc_get_string( 'mode' );
+$t_ar     = config_get( 'graph_bar_aspect' );
+$t_height = $f_width * $t_ar;
+
+/*
+global $g_f;
+$g_f = fopen('./log', 'w');
+debug_r("\n" . '===' . date('r') . "=== {\n");
+*/
+
+generate_graph( $f_mode, $f_range, $f_width, $t_height );
+
+/*
+debug_r('} ===' . date('r') . "===\n");
+fclose($g_f);
+*/
+?>
--- /dev/null	2007-04-10 15:51:58.000000000 +0900
+++ ./summary_graph_imp_date.php	2007-04-02 15:51:38.000000000 +0900
@@ -0,0 +1,72 @@
+<?PHP
+require_once( 'core.php' );
+
+access_ensure_project_level( config_get( 'view_summary_threshold' ) );
+
+html_page_top1();
+html_page_top2();
+
+print_summary_menu( 'summary_page.php' );
+echo '<br />';
+
+print_menu_graph();
+
+$t_width = config_get( 'graph_window_width' );
+$t_graph_width = (int) ( ( $t_width - 50 ) * 0.6 );
+?>
+
+<br />
+<table class="width100" cellspacing="1">
+<tr>
+    <td class="form-title">
+        <?php lang_get( 'graph_imp_date_title' ); ?>
+    </td>
+</tr>
+<tr valign="top">
+    <td>
+        <center><img src="summary_graph_bydate.php?width=<?php echo $t_graph_width?>&mode=total&range=daily" border="0" /></center>
+    </td>
+</tr>
+<tr valign="top">
+    <td>
+        <center><img src="summary_graph_bydate.php?width=<?php echo $t_graph_width?>&mode=total&range=weekly" border="0" /></center>
+    </td>
+</tr>
+<tr valign="top">
+    <td>
+        <center><img src="summary_graph_bydate.php?width=<?php echo $t_graph_width?>&mode=total&range=monthly" border="0" /></center>
+    </td>
+</tr>
+<tr valign="top">
+    <td>
+        <center><img src="summary_graph_bydate.php?width=<?php echo $t_graph_width?>&mode=priority&range=daily" border="0" /></center>
+    </td>
+</tr>
+<tr valign="top">
+    <td>
+        <center><img src="summary_graph_bydate.php?width=<?php echo $t_graph_width?>&mode=priority&range=weekly" border="0" /></center>
+    </td>
+</tr>
+<tr valign="top">
+    <td>
+        <center><img src="summary_graph_bydate.php?width=<?php echo $t_graph_width?>&mode=priority&range=monthly" border="0" /></center>
+    </td>
+</tr>
+<tr valign="top">
+    <td>
+        <center><img src="summary_graph_bydate.php?width=<?php echo $t_graph_width?>&mode=custom1&range=daily" border="0" /></center>
+    </td>
+</tr>
+<tr valign="top">
+    <td>
+        <center><img src="summary_graph_bydate.php?width=<?php echo $t_graph_width?>&mode=custom1&range=weekly" border="0" /></center>
+    </td>
+</tr>
+<tr valign="top">
+    <td>
+        <center><img src="summary_graph_bydate.php?width=<?php echo $t_graph_width?>&mode=custom1&range=monthly" border="0" /></center>
+    </td>
+</tr>
+</table>
+
+<?php html_page_bottom1(__FILE__) ?>
