import('ttUserHelper');
import('ttTeamHelper');
-// Access check.
-if (!ttAccessCheck(right_view_charts)) {
+// Access checks.
+if (!(ttAccessAllowed('view_own_charts') || ttAccessAllowed('view_charts'))) {
header('Location: access_denied.php');
exit();
}
+if (!$user->isPluginEnabled('ch')) {
+ header('Location: feature_disabled.php');
+ exit();
+}
+if ($user->behalf_id && (!$user->can('view_charts') || !$user->checkBehalfId())) {
+ header('Location: access_denied.php'); // Trying on behalf, but no right or wrong user.
+ exit();
+}
+if (!$user->behalf_id && !$user->can('view_own_charts') && !$user->adjustBehalfId()) {
+ header('Location: access_denied.php'); // Trying as self, but no right for self, and noone to view on behalf.
+ exit();
+}
// Initialize and store date in session.
$cl_date = $request->getParameter('date', @$_SESSION['date']);
$cl_type = $sc->getValue(SYSC_CHART_TYPE);
}
if (MODE_TIME == $user->tracking_mode) {
- if (in_array('cl', explode(',', $user->plugins)))
+ if ($user->isPluginEnabled('cl'))
$cl_type = CHART_CLIENTS;
} else {
if ($cl_type == CHART_CLIENTS) {
- if (!in_array('cl', explode(',', $user->plugins)))
+ if (!$user->isPluginEnabled('cl'))
$cl_type = CHART_PROJECTS;
- } else if ($cl_type == CHART_TASKS) {
+ } elseif ($cl_type == CHART_TASKS) {
if (MODE_PROJECTS_AND_TASKS != $user->tracking_mode)
$cl_type = CHART_PROJECTS;
}
// Who do we draw charts for?
$on_behalf_id = $request->getParameter('onBehalfUser', (isset($_SESSION['behalf_id'])? $_SESSION['behalf_id'] : $user->id));
-if ($request->getMethod( )== 'POST') {
+if ($request->isPost()) {
// If chart interval changed - save it.
$cl_interval = $request->getParameter('interval');
if ($cl_interval) {
}
// If user has changed - set behalf_id accordingly in the session.
if ($request->getParameter('onBehalfUser')) {
- if($user->canManageTeam()) {
+ if($user->can('view_charts')) {
unset($_SESSION['behalf_id']);
unset($_SESSION['behalf_name']);
exit();
}
}
-}
+} // isPost
// Elements of chartForm.
$chart_form = new Form('chartForm');
// User dropdown. Changes the user "on behalf" of whom we are working.
-if ($user->canManageTeam()) {
- $user_list = ttTeamHelper::getActiveUsers(array('putSelfFirst'=>true));
- if (count($user_list) > 1) {
+if ($user->can('view_charts')) {
+ if ($user->can('view_own_charts'))
+ $options = array('status'=>ACTIVE,'max_rank'=>$user->rank-1,'include_self'=>true,'self_first'=>true);
+ else
+ $options = array('status'=>ACTIVE,'max_rank'=>$user->rank-1);
+ $user_list = $user->getUsers($options);
+ if (count($user_list) >= 1) {
$chart_form->addInput(array('type'=>'combobox',
'onchange'=>'this.form.submit();',
'name'=>'onBehalfUser',
// Chart interval options.
$intervals = array();
-$intervals[INTERVAL_THIS_DAY] = $i18n->getKey('dropdown.this_day');
-$intervals[INTERVAL_THIS_WEEK] = $i18n->getKey('dropdown.this_week');
-$intervals[INTERVAL_THIS_MONTH] = $i18n->getKey('dropdown.this_month');
-$intervals[INTERVAL_THIS_YEAR] = $i18n->getKey('dropdown.this_year');
-$intervals[INTERVAL_ALL_TIME] = $i18n->getKey('dropdown.all_time');
+$intervals[INTERVAL_THIS_DAY] = $i18n->get('dropdown.selected_day');
+$intervals[INTERVAL_THIS_WEEK] = $i18n->get('dropdown.selected_week');
+$intervals[INTERVAL_THIS_MONTH] = $i18n->get('dropdown.selected_month');
+$intervals[INTERVAL_THIS_YEAR] = $i18n->get('dropdown.selected_year');
+$intervals[INTERVAL_ALL_TIME] = $i18n->get('dropdown.all_time');
// Chart interval dropdown.
$chart_form->addInput(array('type' => 'combobox',
));
// Chart type options.
-$chart_selector = (MODE_PROJECTS_AND_TASKS == $user->tracking_mode
- || in_array('cl', explode(',', $user->plugins)));
+$chart_selector = (MODE_PROJECTS_AND_TASKS == $user->tracking_mode || $user->isPluginEnabled('cl'));
if ($chart_selector) {
$types = array();
if (MODE_PROJECTS == $user->tracking_mode || MODE_PROJECTS_AND_TASKS == $user->tracking_mode)
- $types[CHART_PROJECTS] = $i18n->getKey('dropdown.projects');
+ $types[CHART_PROJECTS] = $i18n->get('dropdown.projects');
if (MODE_PROJECTS_AND_TASKS == $user->tracking_mode)
- $types[CHART_TASKS] = $i18n->getKey('dropdown.tasks');
- if (in_array('cl', explode(',', $user->plugins)))
- $types[CHART_CLIENTS] = $i18n->getKey('dropdown.clients');
+ $types[CHART_TASKS] = $i18n->get('dropdown.tasks');
+ if ($user->isPluginEnabled('cl'))
+ $types[CHART_CLIENTS] = $i18n->get('dropdown.clients');
// Add chart type dropdown.
$chart_form->addInput(array('type' => 'combobox',
$smarty->assign('img_file_name', $img_ref);
$smarty->assign('chart_selector', $chart_selector);
$smarty->assign('forms', array($chart_form->getName() => $chart_form->toArray()));
-$smarty->assign('title', $i18n->getKey('title.charts'));
+$smarty->assign('title', $i18n->get('title.charts'));
$smarty->assign('content_page_name', 'charts.tpl');
$smarty->display('index.tpl');