A few bugs fixed related to role revamp.
[timetracker.git] / WEB-INF / lib / ttRoleHelper.class.php
index 6a4f33b..4a666cb 100644 (file)
@@ -83,35 +83,8 @@ class ttRoleHelper {
     return false;
   }
 
-  // The getLegacyRole obtains a legacy role value for a role_id.
-  // This is a temporary function to allow usage of both old and new roles
-  // while new role code is being written and deployed.
-  static function getLegacyRole($role_id) {
-    global $user;
-    $mdb2 = getConnection();
-
-    $sql = "select rank from tt_roles where team_id = $user->team_id and id = $role_id";
-    $res = $mdb2->query($sql);
-
-    if (!is_a($res, 'PEAR_Error')) {
-      $val = $res->fetchRow();
-      if ($val['rank']) {
-        $rank = $val['rank'];
-        if ($rank >= ROLE_MANAGER)
-          return ROLE_MANAGER;
-        else if ($rank >= ROLE_COMANAGER)
-          return ROLE_COMANAGER;
-        else if ($rank >= ROLE_CLIENT)
-          return ROLE_CLIENT;
-        else
-          return ROLE_USER;
-      }
-    }
-    return false;
-  }
-
   // isClientRole determines if the role is a "client" role.
-  // This simply means the role has no "data_entry" right.
+  // This simply means the role has no "track_own_time" right.
   static function isClientRole($role_id) {
     global $user;
     $mdb2 = getConnection();
@@ -122,26 +95,26 @@ class ttRoleHelper {
     if (!is_a($res, 'PEAR_Error')) {
       $val = $res->fetchRow();
       if ($val['rights']) {
-        return !in_array('data_entry', explode(',', $val['rights']));
+        return !in_array('track_own_time', explode(',', $val['rights']));
       }
     }
     return false;
   }
 
   // getRoleByRank looks up a role by its rank.
-  static function getRoleByRank($rank) {
+  static function getRoleByRank($rank, $team_id) {
     global $user;
     $mdb2 = getConnection();
 
     $rank = (int) $rank; // Cast to int just in case for better security.
 
-    $sql = "select id from tt_roles where team_id = $user->team_id and rank = $rank and (status = 1 or status = 0)";
+    $sql = "select id from tt_roles where team_id = $team_id and rank = $rank and (status = 1 or status = 0)";
     $res = $mdb2->query($sql);
 
     if (!is_a($res, 'PEAR_Error')) {
       $val = $res->fetchRow();
       if ($val['id'])
-        return $val;
+        return $val['id'];
     }
     return false;
   }
@@ -195,22 +168,6 @@ class ttRoleHelper {
     return true;
   }
 
-  // rolesExist - checks whether roles for team already exist.
-  static function rolesExist()
-  {
-    $mdb2 = getConnection();
-    global $user;
-
-    $sql = "select count(*) as count from tt_roles where team_id = $user->team_id";
-    $res = $mdb2->query($sql);
-    if (!is_a($res, 'PEAR_Error')) {
-      $val = $res->fetchRow();
-      if ($val['count'] > 0)
-        return true; // Roles for team exist.
-    }
-    return false;
-  }
-
   // createPredefinedRoles - creates a set of predefined roles for the team to use.
   static function createPredefinedRoles($team_id, $lang)
   {
@@ -221,9 +178,9 @@ class ttRoleHelper {
 
     $mdb2 = getConnection();
 
-    $rights_client = 'view_own_data,manage_own_settings';
-    $rights_user = 'data_entry,view_own_data,manage_own_settings,view_users';
-    $rights_supervisor = $rights_user.',on_behalf_data_entry,view_data,override_punch_mode,swap_roles,approve_timesheets';
+    $rights_client = 'view_own_reports,view_own_charts,view_own_invoices,manage_own_settings';
+    $rights_user = 'track_own_time,track_own_expenses,view_own_reports,view_own_charts,manage_own_settings,view_users';
+    $rights_supervisor = $rights_user.',track_time,track_expenses,view_reports,view_charts,override_punch_mode,override_date_lock,swap_roles,approve_timesheets';
     $rights_comanager = $rights_supervisor.',manage_users,manage_projects,manage_tasks,manage_custom_fields,manage_clients,manage_invoices';
     $rights_manager = $rights_comanager.',manage_features,manage_basic_settings,manage_advanced_settings,manage_roles,export_data,manage_subgroups';
 
@@ -279,9 +236,9 @@ class ttRoleHelper {
     global $i18n;
     global $user;
 
-    $rights_client = 'view_own_data,manage_own_settings';
-    $rights_user = 'data_entry,view_own_data,manage_own_settings,view_users';
-    $rights_supervisor = $rights_user.',on_behalf_data_entry,view_data,override_punch_mode,swap_roles,approve_timesheets';
+    $rights_client = 'view_own_reports,view_own_charts,view_own_invoices,manage_own_settings';
+    $rights_user = 'track_own_time,track_own_expenses,view_own_reports,view_own_charts,manage_own_settings,view_users';
+    $rights_supervisor = $rights_user.',track_time,track_expenses,view_reports,view_charts,override_punch_mode,override_date_lock,swap_roles,approve_timesheets';
     $rights_comanager = $rights_supervisor.',manage_users,manage_projects,manage_tasks,manage_custom_fields,manage_clients,manage_invoices';
     $rights_manager = $rights_comanager.',manage_features,manage_basic_settings,manage_advanced_settings,manage_roles,export_data,manage_subgroups';