Skip to content

Commit 0b2c545

Browse files
committed
Fix Undefined variable notice: query_pull_timerecords
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.
1 parent 9a577a1 commit 0b2c545

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

TimeTracking/TimeTracking.php

+21-22
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function register() {
2525
$this->description = 'Time tracking plugin that supports entering date worked, time and notes. Also includes limited permissions per user.';
2626
$this->page = 'config_page';
2727

28-
$this->version = '1.0.4';
28+
$this->version = '1.0.5';
2929
$this->requires = array(
3030
'MantisCore' => '1.2.0'
3131
);
@@ -71,6 +71,9 @@ function view_bug_time( $p_event, $p_bug_id ) {
7171
$query_pull_timerecords = "SELECT * FROM $table WHERE bug_id = $p_bug_id ORDER BY timestamp DESC";
7272
} else if( access_has_bug_level( plugin_config_get( 'admin_own_threshold' ), $p_bug_id ) ) {
7373
$query_pull_timerecords = "SELECT * FROM $table WHERE bug_id = $p_bug_id and user = $t_user_id ORDER BY timestamp DESC";
74+
} else {
75+
// User has no access
76+
return;
7477
}
7578

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

84-
if( (access_has_bug_level( plugin_config_get( 'admin_own_threshold' ), $p_bug_id ) )
85-
|| (access_has_bug_level( plugin_config_get( 'view_others_threshold' ), $p_bug_id ) ) ) {
86-
8787
?>
8888

8989

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

9292
<?php
93-
collapse_open( 'timerecord' );
93+
collapse_open( 'timerecord' );
9494
?>
9595
<table class="width100" cellspacing="1">
9696
<tr>
9797
<td colspan="6" class="form-title">
9898
<?php
99-
collapse_icon( 'timerecord' );
100-
echo plugin_lang_get( 'title' );
99+
collapse_icon( 'timerecord' );
100+
echo plugin_lang_get( 'title' );
101101
?>
102102
</td>
103103
</tr>
@@ -112,8 +112,8 @@ function view_bug_time( $p_event, $p_bug_id ) {
112112

113113

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

119119

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

141141
<?php
142-
} # END Access Control
142+
} # END Access Control
143143

144-
for ( $i=0; $i < $num_timerecords; $i++ ) {
145-
$row = db_fetch_array( $result_pull_timerecords );
144+
for ( $i=0; $i < $num_timerecords; $i++ ) {
145+
$row = db_fetch_array( $result_pull_timerecords );
146146
?>
147147

148148

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

156156
<?php
157-
$user = auth_get_current_user_id();
158-
if( ($user == $row["user"] && access_has_bug_level( plugin_config_get( 'admin_own_threshold' ), $p_bug_id) )
159-
|| access_has_bug_level( plugin_config_get( 'admin_threshold' ), $p_bug_id) ) {
157+
$user = auth_get_current_user_id();
158+
if( ($user == $row["user"] && access_has_bug_level( plugin_config_get( 'admin_own_threshold' ), $p_bug_id) )
159+
|| access_has_bug_level( plugin_config_get( 'admin_threshold' ), $p_bug_id) ) {
160160
?>
161161

162162

163163
<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' ) ?>
164164
</a></td>
165165

166166
<?php
167-
}
168-
else {
167+
}
168+
else {
169169
?>
170170
<td>&nbsp;</td>
171171

172172
<?php
173-
}
173+
}
174174
?>
175175
</tr>
176176

177177

178178
<?php
179-
} # End for loop
179+
} # End for loop
180180
?>
181181

182182

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

193193
<?php
194-
collapse_closed( 'timerecord' );
194+
collapse_closed( 'timerecord' );
195195
?>
196196

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

206206
<?php
207-
collapse_end( 'timerecord' );
207+
collapse_end( 'timerecord' );
208208

209-
} # Add access
210209
} # function end
211210

212211
function schema() {

0 commit comments

Comments
 (0)