From: Nik Okuntseff Date: Fri, 19 Apr 2019 15:36:25 +0000 (+0000) Subject: Separated users section on reports in 2 for active and inactive users. X-Git-Tag: timetracker_1.19-1~70 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=223ec69341da525ce2fce640ad5e62b00ec27360;p=timetracker.git Separated users section on reports in 2 for active and inactive users. --- diff --git a/WEB-INF/lib/ttFavReportHelper.class.php b/WEB-INF/lib/ttFavReportHelper.class.php index 8b9f4052..a3e130c3 100644 --- a/WEB-INF/lib/ttFavReportHelper.class.php +++ b/WEB-INF/lib/ttFavReportHelper.class.php @@ -72,6 +72,7 @@ class ttFavReportHelper { } return false; } + // getReport - returns a report identified by its id. // TODO: get rid of this function by encapsulating all cron related tasks in its own class. // Because cron works for all orgs and we want this class to always work in context of @@ -225,10 +226,16 @@ class ttFavReportHelper { if (!$bean->getAttribute('chtotalsonly')) $bean->setAttribute('chtotalsonly', 0); - $users_in_bean = $bean->getAttribute('users'); - if ($users_in_bean && is_array($users_in_bean)) { - $users = join(',', $users_in_bean); + $active_users_in_bean = $bean->getAttribute('users_active'); + if ($active_users_in_bean && is_array($active_users_in_bean)) { + $users = join(',', $active_users_in_bean); + } + $inactive_users_in_bean = $bean->getAttribute('users_inactive'); + if ($inactive_users_in_bean && is_array($inactive_users_in_bean)) { + if ($users) $users .= ','; + $users .= join(',', $inactive_users_in_bean); } + if ($bean->getAttribute('start_date')) { $dt = new DateAndTime($user->getDateFormat(), $bean->getAttribute('start_date')); $from = $dt->toString(DB_DATEFORMAT); @@ -322,7 +329,8 @@ class ttFavReportHelper { $bean->setAttribute('invoice', $val['invoice']); $bean->setAttribute('paid_status', $val['paid_status']); $bean->setAttribute('timesheet', $val['timesheet']); - $bean->setAttribute('users', explode(',', $val['users'])); + $bean->setAttribute('users_active', explode(',', $val['users'])); + $bean->setAttribute('users_inactive', explode(',', $val['users'])); $bean->setAttribute('period', $val['period']); if ($val['period_start']) { $dt = new DateAndTime(DB_DATEFORMAT, $val['period_start']); diff --git a/WEB-INF/lib/ttGroupHelper.class.php b/WEB-INF/lib/ttGroupHelper.class.php index 4bc71648..167c620c 100644 --- a/WEB-INF/lib/ttGroupHelper.class.php +++ b/WEB-INF/lib/ttGroupHelper.class.php @@ -637,19 +637,22 @@ class ttGroupHelper { } // The getUsersForClient obtains all active and inactive users in a group that are relevant to a client. - static function getUsersForClient() { + static function getUsersForClient($options) { global $user; $mdb2 = getConnection(); $group_id = $user->getGroup(); $org_id = $user->org_id; + if (isset($options['status'])) + $where_part = 'where u.status = '.(int)$options['status']; + else + $where_part = 'where u.status is not null'; + $sql = "select u.id, u.name from tt_user_project_binds upb". " inner join tt_client_project_binds cpb on (upb.project_id = cpb.project_id and cpb.client_id = $user->client_id)". " inner join tt_users u on (u.id = upb.user_id and u.group_id = $group_id and u.org_id = $org_id)". - " where (u.status = 1 or u.status = 0)". - " group by u.id". - " order by upper(u.name)"; + " $where_part group by u.id order by upper(u.name)"; $res = $mdb2->query($sql); $user_list = array(); if (is_a($res, 'PEAR_Error')) diff --git a/WEB-INF/lib/ttReportHelper.class.php b/WEB-INF/lib/ttReportHelper.class.php index 088280ca..9c6dfb0f 100644 --- a/WEB-INF/lib/ttReportHelper.class.php +++ b/WEB-INF/lib/ttReportHelper.class.php @@ -1155,7 +1155,18 @@ class ttReportHelper { if ($user->isPluginEnabled('ap') && $user->isClient() && !$user->can('view_client_unapproved')) $options['approved'] = 1; // Restrict clients to approved records only. $options['timesheet'] = $bean->getAttribute('timesheet'); - if (is_array($bean->getAttribute('users'))) $options['users'] = join(',', $bean->getAttribute('users')); + + $active_users_in_bean = $bean->getAttribute('users_active'); + if ($active_users_in_bean && is_array($active_users_in_bean)) { + $users = join(',', $active_users_in_bean); + } + $inactive_users_in_bean = $bean->getAttribute('users_inactive'); + if ($inactive_users_in_bean && is_array($inactive_users_in_bean)) { + if ($users) $users .= ','; + $users .= join(',', $inactive_users_in_bean); + } + if ($users) $options['users'] = $users; + $options['period'] = $bean->getAttribute('period'); $options['period_start'] = $bean->getAttribute('start_date'); $options['period_end'] = $bean->getAttribute('end_date'); @@ -1187,13 +1198,19 @@ class ttReportHelper { global $user; // Check users. - $users_in_bean = $bean->getAttribute('users'); - if (is_array($users_in_bean)) { + $active_users_in_bean = $bean->getAttribute('users_active'); + $inactive_users_in_bean = $bean->getAttribute('users_inactive'); + if (is_array($active_users_in_bean) || is_array($inactive_users_in_bean)) { $users_in_group = ttGroupHelper::getUsers(); foreach ($users_in_group as $user_in_group) { $valid_ids[] = $user_in_group['id']; } - foreach ($users_in_bean as $user_in_bean) { + foreach ($active_users_in_bean as $user_in_bean) { + if (!in_array($user_in_bean, $valid_ids)) { + return false; + } + } + foreach ($inactive_users_in_bean as $user_in_bean) { if (!in_array($user_in_bean, $valid_ids)) { return false; } diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index 33a32dc2..2d45101c 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -424,7 +424,7 @@ class ttUser { $left_joins = null; if (isset($options['max_rank']) || $skipClients || isset($options['include_role'])) - $left_joins .= ' left join tt_roles r on (u.role_id = r.id)'; + $left_joins .= ' left join tt_roles r on (u.role_id = r.id)'; $where_part = " where u.org_id = $org_id and u.group_id = $group_id"; if (isset($options['status'])) diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 99115a67..eea5a85d 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.19.0.4959 | Copyright © Anuko | +  Anuko Time Tracker 1.19.1.4960 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/reports.tpl b/WEB-INF/templates/reports.tpl index 3f1dea04..c79425e6 100644 --- a/WEB-INF/templates/reports.tpl +++ b/WEB-INF/templates/reports.tpl @@ -300,12 +300,20 @@ function handleCheckboxes() {
-{if $show_users} +{if $show_active_users} - {$i18n.label.users} + {$i18n.form.users.active_users} - {$forms.reportForm.users.control} + {$forms.reportForm.users_active.control} + +{/if} +{if $show_inactive_users} + + {$i18n.form.users.inactive_users} + + + {$forms.reportForm.users_inactive.control} {/if} diff --git a/reports.php b/reports.php index c191de9a..fe545b21 100644 --- a/reports.php +++ b/reports.php @@ -216,17 +216,25 @@ if ($showUsers) { if ($user->can('view_reports') || $user->can('view_all_reports')) { $rank = $user->getMaxRankForGroup($user->getGroup()); if ($user->can('view_all_reports')) $max_rank = MAX_RANK; - if ($user->can('view_own_reports')) - $options = array('max_rank'=>$max_rank,'include_self'=>true); - else - $options = array('max_rank'=>$max_rank); - $users = $user->getUsers($options); // Active and inactive users. + if ($user->can('view_own_reports')) { + $options_active = array('max_rank'=>$max_rank,'include_self'=>true,'status'=>ACTIVE); + $options_inactive = array('max_rank'=>$max_rank,'include_self'=>true,'status'=>INACTIVE); + } else { + $options_active = array('max_rank'=>$max_rank,'status'=>ACTIVE); + $options_inactive = array('max_rank'=>$max_rank,'status'=>INACTIVE); + } + $active_users = $user->getUsers($options_active); + $inactive_users = $user->getUsers($options_inactive); + } + elseif ($user->isClient()) { + $options_active = array('status'=>ACTIVE); + $options_inactive = array('status'=>INACTIVE); + $active_users = ttGroupHelper::getUsersForClient($options_active); + $inactive_users = ttGroupHelper::getUsersForClient($options_inactive); } - elseif ($user->isClient()) - $users = ttGroupHelper::getUsersForClient(); // Active and inactive users for clients. - foreach ($users as $single_user) { - $user_list[$single_user['id']] = $single_user['name']; + foreach ($active_users as $single_user) { + $user_list_active[$single_user['id']] = $single_user['name']; $projects = ttProjectHelper::getAssignedProjects($single_user['id']); if ($projects) { foreach ($projects as $single_project) { @@ -234,10 +242,27 @@ if ($showUsers) { } } } - $row_count = ceil(count($user_list)/3); + $row_count = ceil(count($user_list_active)/3); $form->addInput(array('type'=>'checkboxgroup', - 'name'=>'users', - 'data'=>$user_list, + 'name'=>'users_active', + 'data'=>$user_list_active, + 'layout'=>'V', + 'groupin'=>$row_count, + 'style'=>'width: 100%;')); + + foreach ($inactive_users as $single_user) { + $user_list_inactive[$single_user['id']] = $single_user['name']; + $projects = ttProjectHelper::getAssignedProjects($single_user['id']); + if ($projects) { + foreach ($projects as $single_project) { + $assigned_projects[$single_user['id']][] = $single_project['id']; + } + } + } + $row_count = ceil(count($user_list_inactive)/3); + $form->addInput(array('type'=>'checkboxgroup', + 'name'=>'users_inactive', + 'data'=>$user_list_inactive, 'layout'=>'V', 'groupin'=>$row_count, 'style'=>'width: 100%;')); @@ -332,7 +357,7 @@ $bean = new ActionForm('reportBean', $form, $request); if ($request->isGet() && !$bean->isSaved()) { // No previous form data were found in session. Use the following default values. - $form->setValueByElement('users', array_keys($user_list)); + $form->setValueByElement('users_active', array_keys($user_list_active)); $period = new Period(INTERVAL_THIS_MONTH, new DateAndTime($user->getDateFormat())); $form->setValueByElement('start_date', $period->getStartDate()); $form->setValueByElement('end_date', $period->getEndDate()); @@ -374,8 +399,10 @@ if ($request->isPost()) { ttFavReportHelper::loadReport($bean); // If user selected no favorite report - mark all user checkboxes (most probable scenario). - if ($bean->getAttribute('favorite_report') == -1) - $form->setValueByElement('users', array_keys($user_list)); + if ($bean->getAttribute('favorite_report') == -1) { + $form->setValueByElement('users_active', array_keys($user_list_active)); + $form->setValueByElement('users_inactive', false); + } // Save form data in session for future use. $bean->saveBean(); @@ -457,7 +484,8 @@ $smarty->assign('show_invoice_checkbox', $showInvoiceCheckbox); $smarty->assign('show_paid_status', $showPaidStatus); $smarty->assign('show_timesheet_dropdown', $showTimesheetDropdown); $smarty->assign('show_timesheet_checkbox', $showTimesheetCheckbox); -$smarty->assign('show_users', $showUsers); +$smarty->assign('show_active_users', $showUsers && $active_users); +$smarty->assign('show_inactive_users', $showUsers && $inactive_users); $smarty->assign('show_start', $showStart); $smarty->assign('show_finish', $showFinish); $smarty->assign('show_work_units', $showWorkUnits);