Skip to content

Commit

Permalink
Fix Undefined variable notice: query_pull_timerecords
Browse files Browse the repository at this point in the history
When the view_bug_time() function was called by a user without access
to timetracking information, the variable $query_pull_timerecords was
not initialized, resulting in a SYSTEM_NOTICE warning and subsequent
error #1065: Query was empty for the query: .

Now the function exits when the user does not have access.
  • Loading branch information
dregad committed Jan 9, 2012
1 parent 9a577a1 commit 0b2c545
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions TimeTracking/TimeTracking.php
Expand Up @@ -25,7 +25,7 @@ function register() {
$this->description = 'Time tracking plugin that supports entering date worked, time and notes. Also includes limited permissions per user.';
$this->page = 'config_page';

$this->version = '1.0.4';
$this->version = '1.0.5';
$this->requires = array(
'MantisCore' => '1.2.0'
);
Expand Down Expand Up @@ -71,6 +71,9 @@ function view_bug_time( $p_event, $p_bug_id ) {
$query_pull_timerecords = "SELECT * FROM $table WHERE bug_id = $p_bug_id ORDER BY timestamp DESC";
} else if( access_has_bug_level( plugin_config_get( 'admin_own_threshold' ), $p_bug_id ) ) {
$query_pull_timerecords = "SELECT * FROM $table WHERE bug_id = $p_bug_id and user = $t_user_id ORDER BY timestamp DESC";
} else {
// User has no access
return;
}

$result_pull_timerecords = db_query( $query_pull_timerecords );
Expand All @@ -81,23 +84,20 @@ function view_bug_time( $p_event, $p_bug_id ) {
$result_pull_hours = db_query( $query_pull_hours );
$row_pull_hours = db_fetch_array( $result_pull_hours );

if( (access_has_bug_level( plugin_config_get( 'admin_own_threshold' ), $p_bug_id ) )
|| (access_has_bug_level( plugin_config_get( 'view_others_threshold' ), $p_bug_id ) ) ) {

?>


<a name="timerecord" id="timerecord" /><br />

<?php
collapse_open( 'timerecord' );
collapse_open( 'timerecord' );
?>
<table class="width100" cellspacing="1">
<tr>
<td colspan="6" class="form-title">
<?php
collapse_icon( 'timerecord' );
echo plugin_lang_get( 'title' );
collapse_icon( 'timerecord' );
echo plugin_lang_get( 'title' );
?>
</td>
</tr>
Expand All @@ -112,8 +112,8 @@ function view_bug_time( $p_event, $p_bug_id ) {


<?php
if ( access_has_bug_level( plugin_config_get( 'admin_own_threshold' ), $p_bug_id ) ) {
$current_date = explode("-", date("Y-m-d"));
if ( access_has_bug_level( plugin_config_get( 'admin_own_threshold' ), $p_bug_id ) ) {
$current_date = explode("-", date("Y-m-d"));
?>


Expand All @@ -139,10 +139,10 @@ function view_bug_time( $p_event, $p_bug_id ) {
</form>

<?php
} # END Access Control
} # END Access Control

for ( $i=0; $i < $num_timerecords; $i++ ) {
$row = db_fetch_array( $result_pull_timerecords );
for ( $i=0; $i < $num_timerecords; $i++ ) {
$row = db_fetch_array( $result_pull_timerecords );
?>


Expand All @@ -154,29 +154,29 @@ function view_bug_time( $p_event, $p_bug_id ) {
<td><div align="center"><?php echo date( config_get("complete_date_format"), strtotime($row["timestamp"])); ?> </div></td>

<?php
$user = auth_get_current_user_id();
if( ($user == $row["user"] && access_has_bug_level( plugin_config_get( 'admin_own_threshold' ), $p_bug_id) )
|| access_has_bug_level( plugin_config_get( 'admin_threshold' ), $p_bug_id) ) {
$user = auth_get_current_user_id();
if( ($user == $row["user"] && access_has_bug_level( plugin_config_get( 'admin_own_threshold' ), $p_bug_id) )
|| access_has_bug_level( plugin_config_get( 'admin_threshold' ), $p_bug_id) ) {
?>


<td><a href="<?php echo plugin_page('delete_record') ?>&bug_id=<?php echo $p_bug_id; ?>&delete_id=<?php echo $row["id"]; ?><?php echo form_security_param( 'plugin_TimeTracking_delete_record' ) ?>"><?php echo plugin_lang_get( 'delete' ) ?>
</a></td>

<?php
}
else {
}
else {
?>
<td>&nbsp;</td>

<?php
}
}
?>
</tr>


<?php
} # End for loop
} # End for loop
?>


Expand All @@ -191,7 +191,7 @@ function view_bug_time( $p_event, $p_bug_id ) {
</table>

<?php
collapse_closed( 'timerecord' );
collapse_closed( 'timerecord' );
?>

<table class="width100" cellspacing="1">
Expand All @@ -204,9 +204,8 @@ function view_bug_time( $p_event, $p_bug_id ) {
</table>

<?php
collapse_end( 'timerecord' );
collapse_end( 'timerecord' );

} # Add access
} # function end

function schema() {
Expand Down

0 comments on commit 0b2c545

Please sign in to comment.