Skip to content

Commit 64ea99d

Browse files
1. Permissions make more sense now
2. Project grouping for the report page
1 parent 13580ca commit 64ea99d

11 files changed

+74
-41
lines changed

TimeTracking/TimeTracking.php

+19-11
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.3';
28+
$this->version = '1.0.4';
2929
$this->requires = array(
3030
'MantisCore' => '1.2.0'
3131
);
@@ -45,9 +45,8 @@ function hooks() {
4545

4646
function config() {
4747
return array(
48-
'view_threshold' => DEVELOPER,
49-
'delete_threshold' => DEVELOPER,
50-
'add_threshold' => DEVELOPER,
48+
'admin_own_threshold' => DEVELOPER,
49+
'view_others_threshold' => MANAGER,
5150
'admin_threshold' => ADMINISTRATOR
5251
);
5352
}
@@ -65,18 +64,25 @@ function init() {
6564
*/
6665
function view_bug_time( $p_event, $p_bug_id ) {
6766
$table = plugin_table('data');
67+
$t_user_id = auth_get_current_user_id();
6868

6969
# Pull all Time-Record entries for the current Bug
70+
if (access_has_bug_level( plugin_config_get( 'view_others_threshold' ), $p_bug_id ) ) {
7071
$query_pull_timerecords = "SELECT * FROM $table WHERE bug_id = $p_bug_id ORDER BY timestamp DESC";
71-
$result_pull_timerecords = db_query($query_pull_timerecords);
72-
$num_timerecords = db_num_rows( $result_pull_timerecords );
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 );
7378

7479
# Get Sum for this bug
7580
$query_pull_hours = "SELECT SUM(hours) as hours FROM $table WHERE bug_id = $p_bug_id";
7681
$result_pull_hours = db_query( $query_pull_hours );
7782
$row_pull_hours = db_fetch_array( $result_pull_hours );
7883

79-
if (access_has_bug_level( plugin_config_get( 'view_threshold' ), $p_bug_id )) {
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 ) ) ) {
8086
?>
8187

8288

@@ -104,7 +110,7 @@ function view_bug_time( $p_event, $p_bug_id ) {
104110

105111

106112
<?php
107-
if ( access_has_bug_level( plugin_config_get( 'add_threshold' ), $p_bug_id ) ) {
113+
if ( access_has_bug_level( plugin_config_get( 'admin_own_threshold' ), $p_bug_id ) ) {
108114
$current_date = explode("-", date("Y-m-d"));
109115
?>
110116

@@ -147,7 +153,8 @@ function view_bug_time( $p_event, $p_bug_id ) {
147153

148154
<?php
149155
$user = auth_get_current_user_id();
150-
if ($user == $row["user"] && access_has_bug_level( plugin_config_get( 'delete_threshold' ), $p_bug_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) ) {
151158
?>
152159

153160

@@ -216,7 +223,8 @@ function schema() {
216223

217224
function timerecord_menu() {
218225
$bugid = gpc_get_int( 'id' );
219-
if ( access_has_bug_level( plugin_config_get( 'view_threshold' ), $bugid ) ){
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 ) ){
220228
$import_page ='view.php?';
221229
$import_page .='id=';
222230
$import_page .= $bugid ;
@@ -230,7 +238,7 @@ function timerecord_menu() {
230238
}
231239

232240
function showreport_menu() {
233-
if ( access_has_global_level( plugin_config_get( 'view_threshold' ) ) ){
241+
if ( access_has_global_level( plugin_config_get( 'admin_own_threshold' ) ) ){
234242
return array( '<a href="' . plugin_page( 'show_report' ) . '">' . plugin_lang_get( 'title' ) . '</a>', );
235243
}
236244
else {

TimeTracking/core/timetracking_api.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ function plugin_TimeTracking_stats_get_project_array( $p_project_id, $p_from, $p
1818
$t_timereport_table = plugin_table('data', 'TimeTracking');
1919
$t_bug_table = db_get_table( 'mantis_bug_table' );
2020
$t_user_table = db_get_table( 'mantis_user_table' );
21+
$t_project_table = db_get_table( 'mantis_project_table' );
22+
2123
if( !is_blank( $c_from ) ) {
2224
$t_from_where = " AND expenditure_date >= $c_from";
2325
} else {
@@ -33,19 +35,20 @@ function plugin_TimeTracking_stats_get_project_array( $p_project_id, $p_from, $p
3335
} else {
3436
$t_project_where = '';
3537
}
36-
if ( access_has_global_level( plugin_config_get( 'add_threshold' ) ) ){
38+
if ( !access_has_global_level( plugin_config_get( 'view_others_threshold' ) ) ){
3739
$t_user_id = auth_get_current_user_id();
3840
$t_user_where = " AND user = '$t_user_id' ";
3941
} else {
4042
$t_user_where = '';
4143
}
4244

4345
$t_results = array();
44-
$query = "SELECT u.username, bug_id, expenditure_date, hours, timestamp, info
45-
FROM $t_timereport_table tr, $t_bug_table b, $t_user_table u
46-
WHERE tr.bug_id=b.id and tr.user=u.id
46+
$query = "SELECT u.username, p.name as project_name, bug_id, expenditure_date, hours, timestamp, info
47+
FROM $t_timereport_table tr, $t_bug_table b, $t_user_table u, $t_project_table p
48+
WHERE tr.bug_id=b.id and tr.user=u.id AND p.id = b.project_id
4749
$t_project_where $t_from_where $t_to_where $t_user_where
4850
ORDER BY user, expenditure_date, bug_id";
51+
4952
$result = db_query( $query );
5053
while( $row = db_fetch_array( $result ) ) {
5154
$t_results[] = $row;

TimeTracking/lang/strings_english.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
$s_plugin_TimeTracking_subtitle = 'Are you a Developer and have worked on this case? Document your work here.';
44
$s_plugin_TimeTracking_user = 'User';
55

6-
$s_plugin_TimeTracking_view_threshold = 'View Threshold';
7-
$s_plugin_TimeTracking_add_threshold = 'Add Threshold';
8-
$s_plugin_TimeTracking_delete_threshold = 'Delete Threshold';
6+
$s_plugin_TimeTracking_admin_own_threshold = 'Admin Own Threshold';
7+
$s_plugin_TimeTracking_view_others_threshold = 'View Others Threshold';
98
$s_plugin_TimeTracking_admin_threshold = 'Admin Threshold';
109

1110
$s_plugin_TimeTracking_expenditure_date = 'Expenditure Date';

TimeTracking/lang/strings_french.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
$s_plugin_TimeTracking_subtitle = 'Are you a Developer and have worked on this case? Document your work here.';
44
$s_plugin_TimeTracking_user = 'User';
55

6-
$s_plugin_TimeTracking_view_threshold = 'View Threshold';
7-
$s_plugin_TimeTracking_add_threshold = 'Add Threshold';
8-
$s_plugin_TimeTracking_delete_threshold = 'Delete Threshold';
6+
$s_plugin_TimeTracking_admin_own_threshold = 'Admin Own Threshold';
7+
$s_plugin_TimeTracking_view_others_threshold = 'View Others Threshold';
98
$s_plugin_TimeTracking_admin_threshold = 'Admin Threshold';
109

1110
$s_plugin_TimeTracking_expenditure_date = 'Expenditure Date';

TimeTracking/lang/strings_german.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
$s_plugin_TimeTracking_subtitle = 'Sie sind Entwickler und haben abrechenbaren Aufwand zu diesem Problem? Erfassen sie Ihn hier.';
44
$s_plugin_TimeTracking_user = 'User';
55

6-
$s_plugin_TimeTracking_view_threshold = 'View Threshold';
7-
$s_plugin_TimeTracking_add_threshold = 'Add Threshold';
8-
$s_plugin_TimeTracking_delete_threshold = 'Delete Threshold';
6+
$s_plugin_TimeTracking_admin_own_threshold = 'Admin Own Threshold';
7+
$s_plugin_TimeTracking_view_others_threshold = 'View Others Threshold';
98
$s_plugin_TimeTracking_admin_threshold = 'Admin Threshold';
109

1110
$s_plugin_TimeTracking_expenditure_date = 'Aufwandsdatum';

TimeTracking/lang/strings_spanish.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
$s_plugin_TimeTracking_subtitle = 'Si has dedicado tiempo a esta incidencia, indicarlo aqui';
44
$s_plugin_TimeTracking_user = 'Usuario';
55

6-
$s_plugin_TimeTracking_view_threshold = 'View Threshold';
7-
$s_plugin_TimeTracking_add_threshold = 'Add Threshold';
8-
$s_plugin_TimeTracking_delete_threshold = 'Delete Threshold';
6+
$s_plugin_TimeTracking_admin_own_threshold = 'Admin Own Threshold';
7+
$s_plugin_TimeTracking_view_others_threshold = 'View Others Threshold';
98
$s_plugin_TimeTracking_admin_threshold = 'Admin Threshold';
109

1110
$s_plugin_TimeTracking_expenditure_date = 'Fecha efectiva';

TimeTracking/pages/add_record.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
$f_month = gpc_get_int( 'month' );
2929
$f_day = gpc_get_int( 'day' );
3030

31-
access_ensure_bug_level( plugin_config_get( 'add_threshold' ), $f_bug_id );
31+
access_ensure_bug_level( plugin_config_get( 'admin_own_threshold' ), $f_bug_id );
3232

3333
# Current UserID
3434
$user = auth_get_current_user_id();

TimeTracking/pages/config_page.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,12 @@
3333
<td class="form-title" colspan="2"><?php echo plugin_lang_get( 'title' ), ': ', plugin_lang_get( 'configuration' ) ?></td>
3434
</tr>
3535
<tr <?php echo helper_alternate_class() ?>>
36-
<td class="category"><?php echo plugin_lang_get( 'view_threshold' ) ?></td>
37-
<td><select name="view_threshold"><?php print_enum_string_option_list( 'access_levels', plugin_config_get( 'view_threshold' ) ) ?></select></td>
36+
<td class="category"><?php echo plugin_lang_get( 'admin_own_threshold' ) ?></td>
37+
<td><select name="admin_own_threshold"><?php print_enum_string_option_list( 'access_levels', plugin_config_get( 'admin_own_threshold' ) ) ?></select></td>
3838
</tr>
3939
<tr <?php echo helper_alternate_class() ?>>
40-
<td class="category"><?php echo plugin_lang_get( 'add_threshold' ) ?></td>
41-
<td><select name="add_threshold"><?php print_enum_string_option_list( 'access_levels', plugin_config_get( 'add_threshold' ) ) ?></select></td>
42-
</tr>
43-
<tr <?php echo helper_alternate_class() ?>>
44-
<td class="category"><?php echo plugin_lang_get( 'delete_threshold' ) ?></td>
45-
<td><select name="delete_threshold"><?php print_enum_string_option_list( 'access_levels', plugin_config_get( 'delete_threshold' ) ) ?></select></td>
40+
<td class="category"><?php echo plugin_lang_get( 'view_others_threshold' ) ?></td>
41+
<td><select name="view_others_threshold"><?php print_enum_string_option_list( 'access_levels', plugin_config_get( 'view_others_threshold' ) ) ?></select></td>
4642
</tr>
4743
<tr <?php echo helper_alternate_class() ?>>
4844
<td class="category"><?php echo plugin_lang_get( 'admin_threshold' ) ?></td>

TimeTracking/pages/config_update.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ function maybe_set_option( $name, $value ) {
3131
}
3232
}
3333

34-
maybe_set_option( 'view_threshold', gpc_get_int( 'view_threshold' ) );
35-
maybe_set_option( 'add_threshold', gpc_get_int( 'add_threshold' ) );
36-
maybe_set_option( 'delete_threshold', gpc_get_int( 'delete_threshold' ) );
34+
maybe_set_option( 'admin_own_threshold', gpc_get_int( 'admin_own_threshold' ) );
35+
maybe_set_option( 'view_others_threshold', gpc_get_int( 'view_others_threshold' ) );
3736
maybe_set_option( 'admin_threshold', gpc_get_int( 'admin_threshold' ) );
3837

3938

TimeTracking/pages/delete_record.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@
2424
$f_bug_id = gpc_get_int( 'bug_id' );
2525
$f_delete_id = gpc_get_int( 'delete_id' );
2626

27-
access_ensure_bug_level( plugin_config_get( 'delete_threshold' ), $f_bug_id );
28-
2927
$table = plugin_table('data', 'TimeTracking');
3028
$query_pull_timerecords = "SELECT * FROM $table WHERE id = $f_delete_id ORDER BY timestamp DESC";
3129
$result_pull_timerecords = db_query($query_pull_timerecords);
3230
$row = db_fetch_array( $result_pull_timerecords );
31+
32+
$t_user_id = auth_get_current_user_id();
33+
if ( $row[user] == $t_user_id) {
34+
access_ensure_bug_level( plugin_config_get( 'admin_own_threshold' ), $f_bug_id );
35+
} else {
36+
access_ensure_bug_level( plugin_config_get( 'admin_threshold' ), $f_bug_id );
37+
}
3338
$query_delete = "DELETE FROM $table WHERE id = $f_delete_id";
3439
db_query($query_delete);
3540

TimeTracking/pages/show_report.php

+26
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,18 @@
105105
<?php
106106
$t_sum_in_hours = 0;
107107
$t_user_summary = array();
108+
$t_project_summary = array();
108109
$t_bug_summary = array();
109110
# Initialize the user summary array
110111
foreach ( $t_plugin_TimeTracking_stats as $t_item ) {
111112
$t_user_summary[$t_item['username']] = 0;
113+
$t_project_summary[$t_item['project_name']] = 0;
112114
$t_bug_summary[$t_item['bug_id']] = 0;
113115
}
114116
foreach ( $t_plugin_TimeTracking_stats as $t_key => $t_item ) {
115117
$t_sum_in_hours += $t_item['hours'];
116118
$t_user_summary[$t_item['username']] += $t_item['hours'];
119+
$t_project_summary[$t_item['project_name']] += $t_item['hours'];
117120
$t_bug_summary[$t_item['bug_id']] += $t_item['hours'];
118121
?>
119122
<tr <?php echo helper_alternate_class() ?>>
@@ -169,6 +172,29 @@
169172
<?php } ?>
170173
</table>
171174

175+
<BR>
176+
<table border="1" class="width100" cellspacing="0">
177+
<tr class="row-category-history">
178+
<td class="small-caption">
179+
<?php echo lang_get( 'project_name' ) ?>
180+
</td>
181+
<td class="small-caption">
182+
<?php echo plugin_lang_get( 'hours' ) ?>
183+
</td>
184+
</tr>
185+
186+
<?php foreach ( $t_project_summary as $t_project_key => $t_project_value ) { ?>
187+
<tr <?php echo helper_alternate_class() ?>>
188+
<td class="small-caption">
189+
<?php echo lang_get( 'total_time' ); ?>(<?php echo $t_project_key; ?>)
190+
</td>
191+
<td class="small-caption">
192+
<?php echo number_format($t_project_value, 2, '.', ','); ?> (<?php echo db_minutes_to_hhmm( $t_project_value * 60); ?>)
193+
</td>
194+
</tr>
195+
<?php } ?>
196+
</table>
197+
172198
<BR>
173199
<table border="1" class="width100" cellspacing="0">
174200
<tr class="row-category-history">

0 commit comments

Comments
 (0)