16
16
17
17
Notes: Based on the Time Tracking plugin by Elmar:
18
18
2005 by Elmar Schumacher - GAMBIT Consulting GmbH
19
- http://www.mantisbt.org/forums/viewtopic.php?f=4&t=589
19
+ http://www.mantisbt.org/forums/viewtopic.php?f=4&t=589
20
20
*/
21
21
class TimeTrackingPlugin extends MantisPlugin {
22
22
23
- function register () {
24
- $ this ->name = 'Time Tracking ' ;
25
- $ this ->description = 'Time tracking plugin that supports entering date worked, time and notes. Also includes limited permissions per user. ' ;
26
- $ this ->page = 'config_page ' ;
27
-
28
- $ this ->version = '1.0.4 ' ;
29
- $ this ->requires = array (
30
- 'MantisCore ' => '1.2.0 '
31
- );
32
-
33
- $ this ->author = 'Michael Baker ' ;
34
- $ this ->
contact =
'[email protected] ' ;
35
- $ this ->url = '' ;
36
- }
37
-
38
- function hooks () {
39
- return array (
40
- 'EVENT_VIEW_BUG_EXTRA ' => 'view_bug_time ' ,
41
- ' EVENT_MENU_ISSUE ' => 'timerecord_menu ' ,
42
- ' EVENT_MENU_MAIN ' => 'showreport_menu ' ,
43
- );
44
- }
45
-
46
- function config () {
47
- return array (
48
- 'admin_own_threshold ' => DEVELOPER ,
49
- 'view_others_threshold ' => MANAGER ,
50
- ' admin_threshold ' => ADMINISTRATOR
51
- );
52
- }
53
-
54
- function init () {
55
- $ t_path = config_get_global ('plugin_path ' ). plugin_get_current () . DIRECTORY_SEPARATOR . 'core ' . DIRECTORY_SEPARATOR ;
56
- set_include_path (get_include_path () . PATH_SEPARATOR . $ t_path );
57
- }
23
+ function register () {
24
+ $ this ->name = 'Time Tracking ' ;
25
+ $ this ->description = 'Time tracking plugin that supports entering date worked, time and notes. Also includes limited permissions per user. ' ;
26
+ $ this ->page = 'config_page ' ;
27
+
28
+ $ this ->version = '1.0.4 ' ;
29
+ $ this ->requires = array (
30
+ 'MantisCore ' => '1.2.0 '
31
+ );
32
+
33
+ $ this ->author = 'Michael Baker ' ;
34
+ $ this ->
contact =
'[email protected] ' ;
35
+ $ this ->url = '' ;
36
+ }
37
+
38
+ function hooks () {
39
+ return array (
40
+ 'EVENT_VIEW_BUG_EXTRA ' => 'view_bug_time ' ,
41
+ ' EVENT_MENU_ISSUE ' => 'timerecord_menu ' ,
42
+ ' EVENT_MENU_MAIN ' => 'showreport_menu ' ,
43
+ );
44
+ }
45
+
46
+ function config () {
47
+ return array (
48
+ 'admin_own_threshold ' => DEVELOPER ,
49
+ 'view_others_threshold ' => MANAGER ,
50
+ ' admin_threshold ' => ADMINISTRATOR
51
+ );
52
+ }
53
+
54
+ function init () {
55
+ $ t_path = config_get_global ('plugin_path ' ). plugin_get_current () . DIRECTORY_SEPARATOR . 'core ' . DIRECTORY_SEPARATOR ;
56
+ set_include_path (get_include_path () . PATH_SEPARATOR . $ t_path );
57
+ }
58
58
59
59
60
60
/**
61
61
* Show TimeTracking information when viewing bugs.
62
62
* @param string Event name
63
63
* @param int Bug ID
64
64
*/
65
- function view_bug_time ( $ p_event , $ p_bug_id ) {
66
- $ table = plugin_table ('data ' );
67
- $ t_user_id = auth_get_current_user_id ();
68
-
69
- # Pull all Time-Record entries for the current Bug
70
- if (access_has_bug_level ( plugin_config_get ( 'view_others_threshold ' ), $ p_bug_id ) ) {
71
- $ query_pull_timerecords = "SELECT * FROM $ table WHERE bug_id = $ p_bug_id ORDER BY timestamp DESC " ;
72
-
73
- } else if (access_has_bug_level ( plugin_config_get ( 'admin_own_threshold ' ), $ p_bug_id ) ) {
74
- $ query_pull_timerecords = "SELECT * FROM $ table WHERE bug_id = $ p_bug_id and user = $ t_user_id ORDER BY timestamp DESC " ;
75
- }
76
- $ result_pull_timerecords = db_query ($ query_pull_timerecords );
77
- $ num_timerecords = db_num_rows ( $ result_pull_timerecords );
78
-
79
- # Get Sum for this bug
80
- $ query_pull_hours = "SELECT SUM(hours) as hours FROM $ table WHERE bug_id = $ p_bug_id " ;
81
- $ result_pull_hours = db_query ( $ query_pull_hours );
82
- $ row_pull_hours = db_fetch_array ( $ result_pull_hours );
83
-
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 ) ) ) {
65
+ function view_bug_time ( $ p_event , $ p_bug_id ) {
66
+ $ table = plugin_table ('data ' );
67
+ $ t_user_id = auth_get_current_user_id ();
68
+
69
+ # Pull all Time-Record entries for the current Bug
70
+ if ( access_has_bug_level ( plugin_config_get ( 'view_others_threshold ' ), $ p_bug_id ) ) {
71
+ $ query_pull_timerecords = "SELECT * FROM $ table WHERE bug_id = $ p_bug_id ORDER BY timestamp DESC " ;
72
+ } else if ( access_has_bug_level ( plugin_config_get ( 'admin_own_threshold ' ), $ p_bug_id ) ) {
73
+ $ query_pull_timerecords = "SELECT * FROM $ table WHERE bug_id = $ p_bug_id and user = $ t_user_id ORDER BY timestamp DESC " ;
74
+ }
75
+
76
+ $ result_pull_timerecords = db_query ( $ query_pull_timerecords );
77
+ $ num_timerecords = db_num_rows ( $ result_pull_timerecords );
78
+
79
+ # Get Sum for this bug
80
+ $ query_pull_hours = "SELECT SUM(hours) as hours FROM $ table WHERE bug_id = $ p_bug_id " ;
81
+ $ result_pull_hours = db_query ( $ query_pull_hours );
82
+ $ row_pull_hours = db_fetch_array ( $ result_pull_hours );
83
+
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
+
86
87
?>
87
88
88
89
89
90
<a name="timerecord" id="timerecord" /><br />
90
91
91
92
<?php
92
- collapse_open ( 'timerecord ' );
93
+ collapse_open ( 'timerecord ' );
93
94
?>
94
95
<table class="width100" cellspacing="1">
95
96
<tr>
96
97
<td colspan="6" class="form-title">
97
98
<?php
98
- collapse_icon ( 'timerecord ' ); ?>
99
- <?php echo plugin_lang_get ( 'title ' ); ?>
99
+ collapse_icon ( 'timerecord ' );
100
+ echo plugin_lang_get ( 'title ' );
101
+ ?>
100
102
</td>
101
103
</tr>
102
104
<tr class="row-category">
@@ -109,17 +111,17 @@ function view_bug_time( $p_event, $p_bug_id ) {
109
111
</tr>
110
112
111
113
112
- <?php
113
- if ( access_has_bug_level ( plugin_config_get ( 'admin_own_threshold ' ), $ p_bug_id ) ) {
114
- $ current_date = explode ("- " , date ("Y-m-d " ));
114
+ <?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
117
?>
116
118
117
119
118
120
<form name="time_tracking" method="post" action="<?php echo plugin_page ('add_record ' ) ?> " >
119
121
<?php echo form_security_field ( 'plugin_TimeTracking_add_record ' ) ?>
120
122
121
123
<input type="hidden" name="bug_id" value="<?php echo $ p_bug_id ; ?> ">
122
-
124
+
123
125
<tr <?php echo helper_alternate_class () ?> >
124
126
<td><?php echo user_get_name ( auth_get_current_user_id () ) ?> </td>
125
127
<td nowrap>
@@ -137,10 +139,10 @@ function view_bug_time( $p_event, $p_bug_id ) {
137
139
</form>
138
140
139
141
<?php
140
- } # END Access Control
142
+ } # END Access Control
141
143
142
- for ( $ i =0 ; $ i < $ num_timerecords ; $ i ++ ) {
143
- $ row = db_fetch_array ( $ result_pull_timerecords );
144
+ for ( $ i =0 ; $ i < $ num_timerecords ; $ i ++ ) {
145
+ $ row = db_fetch_array ( $ result_pull_timerecords );
144
146
?>
145
147
146
148
@@ -151,30 +153,30 @@ function view_bug_time( $p_event, $p_bug_id ) {
151
153
<td><div align="center"><?php echo string_display_links ($ row ["info " ]); ?> </div></td>
152
154
<td><div align="center"><?php echo date ( config_get ("complete_date_format " ), strtotime ($ row ["timestamp " ])); ?> </div></td>
153
155
154
- <?php
155
- $ user = auth_get_current_user_id ();
156
- if ( ($ user == $ row ["user " ] && access_has_bug_level ( plugin_config_get ( 'admin_own_threshold ' ), $ p_bug_id ) )
157
- || access_has_bug_level ( plugin_config_get ( 'admin_threshold ' ), $ p_bug_id ) ) {
156
+ <?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 ) ) {
158
160
?>
159
161
160
162
161
163
<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 ' ) ?>
162
164
</a></td>
163
165
164
- <?php
165
- }
166
- else {
166
+ <?php
167
+ }
168
+ else {
167
169
?>
168
170
<td> </td>
169
171
170
172
<?php
171
- }
173
+ }
172
174
?>
173
175
</tr>
174
176
175
177
176
178
<?php
177
- } # End for loop
179
+ } # End for loop
178
180
?>
179
181
180
182
@@ -189,7 +191,7 @@ function view_bug_time( $p_event, $p_bug_id ) {
189
191
</table>
190
192
191
193
<?php
192
- collapse_closed ( 'timerecord ' );
194
+ collapse_closed ( 'timerecord ' );
193
195
?>
194
196
195
197
<table class="width100" cellspacing="1">
@@ -202,48 +204,49 @@ function view_bug_time( $p_event, $p_bug_id ) {
202
204
</table>
203
205
204
206
<?php
205
- collapse_end ( 'timerecord ' );
206
-
207
- } # Add access
208
- } # function end
209
-
210
- function schema () {
211
- return array (
212
- array ( 'CreateTableSQL ' , array ( plugin_table ( 'data ' ), "
213
- id I NOTNULL UNSIGNED AUTOINCREMENT PRIMARY,
214
- bug_id I DEFAULT NULL UNSIGNED,
215
- user I DEFAULT NULL UNSIGNED,
216
- expenditure_date T DEFAULT NULL,
217
- hours F(15,3) DEFAULT NULL,
218
- timestamp T DEFAULT NULL,
219
- info C(255) DEFAULT NULL
220
- " ) ),
221
- );
222
- }
223
-
224
- function timerecord_menu () {
225
- $ bugid = gpc_get_int ( 'id ' );
226
- if ( access_has_bug_level ( plugin_config_get ( 'admin_own_threshold ' ), $ bugid )
227
- || access_has_bug_level ( plugin_config_get ( 'view_others_threshold ' ), $ bugid ) ){
228
- $ import_page ='view.php? ' ;
229
- $ import_page .='id= ' ;
230
- $ import_page .= $ bugid ;
231
- $ import_page .= '#timerecord ' ;
232
-
233
- return array ( plugin_lang_get ( 'timerecord_menu ' ) => $ import_page );
207
+ collapse_end ( 'timerecord ' );
208
+
209
+ } # Add access
210
+ } # function end
211
+
212
+ function schema () {
213
+ return array (
214
+ array ( 'CreateTableSQL ' , array ( plugin_table ( 'data ' ), "
215
+ id I NOTNULL UNSIGNED AUTOINCREMENT PRIMARY,
216
+ bug_id I DEFAULT NULL UNSIGNED,
217
+ user I DEFAULT NULL UNSIGNED,
218
+ expenditure_date T DEFAULT NULL,
219
+ hours F(15,3) DEFAULT NULL,
220
+ timestamp T DEFAULT NULL,
221
+ info C(255) DEFAULT NULL
222
+ " )
223
+ ),
224
+ );
225
+ }
226
+
227
+ function timerecord_menu () {
228
+ $ bugid = gpc_get_int ( 'id ' );
229
+ if ( access_has_bug_level ( plugin_config_get ( 'admin_own_threshold ' ), $ bugid )
230
+ || access_has_bug_level ( plugin_config_get ( 'view_others_threshold ' ), $ bugid ) ) {
231
+ $ import_page = 'view.php? ' ;
232
+ $ import_page .= 'id= ' ;
233
+ $ import_page .= $ bugid ;
234
+ $ import_page .= '#timerecord ' ;
235
+
236
+ return array ( plugin_lang_get ( 'timerecord_menu ' ) => $ import_page );
234
237
}
235
238
else {
236
239
return array ();
237
240
}
238
241
}
239
242
240
- function showreport_menu () {
241
- if ( access_has_global_level ( plugin_config_get ( 'admin_own_threshold ' ) ) ){
242
- return array ( '<a href=" ' . plugin_page ( 'show_report ' ) . '"> ' . plugin_lang_get ( 'title ' ) . '</a> ' , );
243
+ function showreport_menu () {
244
+ if ( access_has_global_level ( plugin_config_get ( 'admin_own_threshold ' ) ) ){
245
+ return array ( '<a href=" ' . plugin_page ( 'show_report ' ) . '"> ' . plugin_lang_get ( 'title ' ) . '</a> ' , );
243
246
}
244
247
else {
245
248
return array ('' );
246
- }
249
+ }
247
250
}
248
251
249
252
0 commit comments