Some cleanup and refactoring of role_id update.
[timetracker.git] / charts.php
index a7d0887..9df70d5 100644 (file)
@@ -38,7 +38,7 @@ import('ttUserHelper');
 import('ttTeamHelper');
 
 // Access check.
-if (!ttAccessCheck(right_view_charts)) {
+if (!ttAccessAllowed('view_own_charts') || !$user->isPluginEnabled('ch')) {
   header('Location: access_denied.php');
   exit();
 }
@@ -67,13 +67,13 @@ if (!$cl_type) {
   $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;
   }
@@ -84,7 +84,7 @@ $_SESSION['chart_type'] = $cl_type;
 // 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) {
@@ -117,7 +117,7 @@ if ($request->getMethod( )== 'POST') {
       exit();
     }
   }
-}
+} // isPost
 
 // Elements of chartForm.
 $chart_form = new Form('chartForm');
@@ -139,10 +139,10 @@ if ($user->canManageTeam()) {
 
 // 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_THIS_DAY] = $i18n->getKey('dropdown.selected_day');
+$intervals[INTERVAL_THIS_WEEK] = $i18n->getKey('dropdown.selected_week');
+$intervals[INTERVAL_THIS_MONTH] = $i18n->getKey('dropdown.selected_month');
+$intervals[INTERVAL_THIS_YEAR] = $i18n->getKey('dropdown.selected_year');
 $intervals[INTERVAL_ALL_TIME] = $i18n->getKey('dropdown.all_time');
 
 // Chart interval dropdown.
@@ -154,15 +154,14 @@ $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');
   if (MODE_PROJECTS_AND_TASKS == $user->tracking_mode)
     $types[CHART_TASKS] = $i18n->getKey('dropdown.tasks');
-  if (in_array('cl', explode(',', $user->plugins)))
+  if ($user->isPluginEnabled('cl'))
     $types[CHART_CLIENTS] = $i18n->getKey('dropdown.clients');
 
   // Add chart type dropdown.