Skip to content

Commit

Permalink
use bound queries, and fixes xhtml output
Browse files Browse the repository at this point in the history
also fixes 0010675: Made enhancement to the billing page
  • Loading branch information
mantis committed Jan 22, 2012
1 parent 93ffd22 commit 2a5c447
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
32 changes: 25 additions & 7 deletions billing_inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
$t_bugnote_stats_to_y = gpc_get_int('end_year', $t_bugnote_stats_to_def_y);

$f_get_bugnote_stats_button = gpc_get_string('get_bugnote_stats_button', '');

$f_reporter_id = gpc_get_int( 'reporter_id', ALL_USERS );
$f_bugnote_cost = gpc_get_int( 'bugnote_cost', '' );
$f_project_id = helper_get_current_project();

Expand All @@ -91,18 +93,17 @@
?>
<form method="post" action="">
<?php # CSRF protection not required here - form does not result in modifications ?>
<input type="hidden" name="id" value="<?php echo isset( $f_bug_id ) ? $f_bug_id : 0 ?>" />
<table class="width100" cellspacing="0">
<table class="width50" cellspacing="0">
<tr>
<td class="form-title" colspan="4">
<td class="form-title" colspan="2">
<?php
collapse_icon( 'bugnotestats' );
?>
<?php echo lang_get( 'time_tracking' ) ?>
</td>
</tr>
<tr class="row-2">
<td class="category" width="25%">
<td class="category" colspan="2">
<?php
$t_filter = array();
$t_filter[FILTER_PROPERTY_FILTER_BY_DATE] = 'on';
Expand All @@ -116,8 +117,20 @@
?>
</td>
</tr>

<tr class="row-2">
<td>
<?php echo lang_get( 'username' ) ?>:
<select name="reporter_id">
<option value="0" selected="selected"></option>
<?php print_reporter_option_list( $f_reporter_id, $f_project_id ) ?>
</select>
</td>
</tr>


<?php if ( $t_cost_col ) { ?>
<tr class="row-1">
<tr class="row-2">
<td>
<?php echo lang_get( 'time_tracking_cost_label' ) ?>
<input type="text" name="bugnote_cost" value="<?php echo $f_bugnote_cost ?>" />
Expand All @@ -126,6 +139,7 @@
<?php } ?>
<tr>
<td class="center" colspan="2">
<input type="hidden" name="id" value="<?php echo isset( $f_bug_id ) ? $f_bug_id : 0 ?>" />
<input type="submit" class="button" name="get_bugnote_stats_button" value="<?php echo lang_get( 'time_tracking_get_info_button' ) ?>" />
</td>
</tr>
Expand All @@ -136,7 +150,7 @@
if ( !is_blank( $f_get_bugnote_stats_button ) ) {
$t_from = "$t_bugnote_stats_from_y-$t_bugnote_stats_from_m-$t_bugnote_stats_from_d";
$t_to = "$t_bugnote_stats_to_y-$t_bugnote_stats_to_m-$t_bugnote_stats_to_d";
$t_bugnote_stats = bugnote_stats_get_project_array( $f_project_id, $t_from, $t_to, $f_bugnote_cost );
$t_bugnote_stats = bugnote_stats_get_project_array( $f_project_id, $t_from, $t_to, $f_bugnote_cost, $f_reporter_id );

if ( is_blank( $f_bugnote_cost ) || ( (double)$f_bugnote_cost == 0 ) ) {
$t_cost_col = false;
Expand Down Expand Up @@ -166,7 +180,11 @@

foreach ( $t_bugnote_stats as $t_item ) {
$t_sum_in_minutes += $t_item['sum_time_tracking'];
$t_user_summary[$t_item['username']] += $t_item['sum_time_tracking'];
if( isset( $t_user_summary[$t_item['username']] ) ) {
$t_user_summary[$t_item['username']] += $t_item['sum_time_tracking'];
} else {
$t_user_summary[$t_item['username']] = $t_item['sum_time_tracking'];
}

$t_item['sum_time_tracking'] = db_minutes_to_hhmm( $t_item['sum_time_tracking'] );
if ( $t_item['bug_id'] != $t_prev_id) {
Expand Down
31 changes: 21 additions & 10 deletions core/bugnote_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,47 +589,58 @@ function bugnote_stats_get_events_array( $p_bug_id, $p_from, $p_to ) {
* @param string $p_from Starting date (yyyy-mm-dd) inclusive, if blank, then ignored.
* @param string $p_to Ending date (yyyy-mm-dd) inclusive, if blank, then ignored.
* @param int $p_cost cost
* @param int $p_user_id Optional user id of user who added the bugnote
* @return array array of bugnote stats
* @access public
*/
function bugnote_stats_get_project_array( $p_project_id, $p_from, $p_to, $p_cost ) {
$c_project_id = (int)$p_project_id;
function bugnote_stats_get_project_array( $p_project_id, $p_from, $p_to, $p_cost, $p_user_id = ALL_USERS ) {
$t_params = array();

$c_to = strtotime( $p_to ) + SECONDS_PER_DAY - 1;
$c_from = strtotime( $p_from );

if ( $c_to === false || $c_from === false ) {
throw new MantisBT\Exception\Generic( array( $p_form, $p_to ) );
throw new MantisBT\Exception\Generic( array( $p_from, $p_to ) );
}

if( ALL_PROJECTS != $p_project_id ) {
$t_project_where = " AND b.project_id=%d AND bn.bug_id = b.id";
$t_params[] = $p_project_id;
} else {
$t_project_where = '';
}

if( !is_blank( $c_from ) ) {
$t_from_where = " AND bn.date_submitted >= $c_from";
$t_from_where = " AND bn.date_submitted>=%d";
$t_params[] = $c_from;
} else {
$t_from_where = '';
}

if( !is_blank( $c_to ) ) {
$t_to_where = " AND bn.date_submitted <= $c_to";
$t_to_where = " AND bn.date_submitted<=%d";
$t_params[] = $c_to;
} else {
$t_to_where = '';
}

if( ALL_PROJECTS != $c_project_id ) {
$t_project_where = " AND b.project_id = '$c_project_id' AND bn.bug_id = b.id ";
if( ALL_USERS != $p_user_id ) {
$t_reporter_where = " AND bn.reporter_id=%d";
$t_params[] = $p_user_id;
} else {
$t_project_where = '';
$t_reporter_where = '';
}

$t_results = array();

$t_query = "SELECT username, summary, bn.bug_id, SUM(time_tracking) AS sum_time_tracking
FROM {user} u, {bugnote} bn, {bug} b
WHERE u.id = bn.reporter_id AND bn.time_tracking != 0 AND bn.bug_id = b.id
$t_project_where $t_from_where $t_to_where
$t_project_where $t_from_where $t_to_where $t_reporter_where
GROUP BY bn.bug_id, u.id, u.username, b.summary
ORDER BY bn.bug_id";

$t_result = db_query( $t_query, array() );
$t_result = db_query( $t_query, $t_params );

$t_cost_min = $p_cost / 60.0;

Expand Down

0 comments on commit 2a5c447

Please sign in to comment.