A few fixes to export-import.
[timetracker.git] / WEB-INF / lib / ttRoleHelper.class.php
index 329e0a8..1839670 100644 (file)
@@ -83,33 +83,6 @@ 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 "track_own_time" right.
   static function isClientRole($role_id) {
@@ -153,10 +126,11 @@ class ttRoleHelper {
 
     $id = (int)$fields['id'];
     if (isset($fields['name'])) $name_part = 'name = '.$mdb2->quote($fields['name']);
+    if (isset($fields['rank'])) $rank_part = ', rank = '.(int)$fields['rank'];
     if (isset($fields['description'])) $descr_part = ', description = '.$mdb2->quote($fields['description']);
     if (isset($fields['status'])) $status_part = ', status = '.(int)$fields['status'];
     if (isset($fields['rights'])) $rights_part = ', rights = '.$mdb2->quote($fields['rights']);
-    $parts = trim($name_part.$descr_part.$status_part.$rights_part, ',');
+    $parts = trim($name_part.$rank_part.$descr_part.$status_part.$rights_part, ',');
     $sql = "update tt_roles set $parts where id = $id and team_id = $user->team_id";
     $affected = $mdb2->exec($sql);
     return (!is_a($affected, 'PEAR_Error'));
@@ -192,7 +166,11 @@ class ttRoleHelper {
     if (is_a($affected, 'PEAR_Error'))
       return false;
 
-    return true;
+    $sql = "SELECT LAST_INSERT_ID() AS last_id";
+    $res = $mdb2->query($sql);
+    $val = $res->fetchRow();
+    $last_id = $val['last_id'];
+    return $last_id;
   }
 
   // createPredefinedRoles - creates a set of predefined roles for the team to use.
@@ -207,7 +185,7 @@ class ttRoleHelper {
 
     $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_supervisor = $rights_user.',track_time,track_expenses,view_reports,view_charts,override_punch_mode,override_date_lock,override_own_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';
 
@@ -265,7 +243,7 @@ class ttRoleHelper {
 
     $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_supervisor = $rights_user.',track_time,track_expenses,view_reports,view_charts,override_punch_mode,override_date_lock,override_own_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';